Skip to content

Cleanup creation of lang items#2880

Merged
CohenArthur merged 2 commits into
Rust-GCC:masterfrom
CohenArthur:cleanup-lang-items
Feb 29, 2024
Merged

Cleanup creation of lang items#2880
CohenArthur merged 2 commits into
Rust-GCC:masterfrom
CohenArthur:cleanup-lang-items

Conversation

@CohenArthur

@CohenArthur CohenArthur commented Feb 27, 2024

Copy link
Copy Markdown
Member
  • lang-items: Cleanup parsing and lookups of lang items.
  • lang-items: Make lang items enum stronger, rename class, cleanup ns.

This cleans up the handling and creation of lang items. The second commit is more of a nitpick, which renames the class and enum to make it easier to use - but we can definitely drop it if it's too many changes at once.

  • Need an implementation of std::less/std::hash for LangItem::Kind for the C++almost11 standard

@CohenArthur

Copy link
Copy Markdown
Member Author

we could also rename the methods in LangItem to be lowercase instead, like the rest of the compiler? or instead rename the rest of our static methods to use this case as well since I do think it makes sense, even though I'm not a huge fan

gcc/rust/ChangeLog:

	* Make-lang.in: Compile new rust-lang-item.o.
	* util/rust-lang-item.h: Split into header and source.
	* util/rust-lang-item.cc: Cleanup parsing of lang items by using a hashmap
	and returning optional values, cleanup handling of exhaustive lang item
	lookups.
	* hir/rust-ast-lower-base.cc (ASTLoweringBase::handle_lang_item_attribute): Use
	new optional API.
gcc/rust/ChangeLog:

	* util/rust-lang-item.h (class RustLangItem): Renamed to...
	(class LangItem): ...this. Rename ItemType enum to Kind
	* util/rust-lang-item.cc: Rename methods to use new class name.
	* backend/rust-compile-expr.cc (CompileExpr::visit): Use new lang-item API.
	(CompileExpr::resolve_operator_overload): Likewise.
	* backend/rust-compile-expr.h: Likewise.
	* hir/rust-ast-lower-base.cc (ASTLoweringBase::handle_lang_item_attribute): Likewise.
	* typecheck/rust-autoderef.cc (Adjuster::try_deref_type): Likewise.
	(AutoderefCycle::cycle): Likewise.
	* typecheck/rust-autoderef.h: Likewise.
	* typecheck/rust-hir-type-bounds.h: Likewise.
	* typecheck/rust-hir-type-check-base.cc (TypeCheckBase::get_marker_predicate): Likewise.
	* typecheck/rust-hir-type-check-base.h: Likewise.
	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise.
	* typecheck/rust-hir-type-check-expr.h: Likewise.
	* typecheck/rust-hir-type-check-type.cc (TypeResolveGenericParam::visit): Likewise.
	* typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::assemble_sized_builtin): Likewise.
	(TypeBoundsProbe::assemble_builtin_candidate): Likewise.
	(TypeCheckBase::get_predicate_from_bound): Likewise.
	* typecheck/rust-tyty.cc (ClosureType::setup_fn_once_output): Likewise.
	* util/rust-hir-map.cc (Mappings::get_lang_item): Likewise.
	(Mappings::lookup_trait_item_lang_item): Likewise.
	* util/rust-hir-map.h: Likewise.
@P-E-P

P-E-P commented Feb 28, 2024

Copy link
Copy Markdown
Member

we could also rename the methods in LangItem to be lowercase instead, like the rest of the compiler? or instead rename the rest of our static methods to use this case as well since I do think it makes sense, even though I'm not a huge fan

We should probably keep those lowercase for now

item.get_mappings ().get_defid ());
auto lang_item_type = LangItem::Parse (lang_item_type_str);

if (lang_item_type)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer we keep the condition explicit instead of relying on the underlying value.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you mean using if (lang_item_type.has_value()) instead?

@P-E-P P-E-P Feb 29, 2024

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No sorry, I read too fast and thought we kept the Unknown item kind. Given it is an optional we can keep this.

@CohenArthur CohenArthur added this pull request to the merge queue Feb 29, 2024
Merged via the queue into Rust-GCC:master with commit 6895e0b Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants