Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collect lang items in the AST #3289

Merged
merged 3 commits into from
Dec 4, 2024

Conversation

CohenArthur
Copy link
Member

In order to have lang items paths, we need to be able to resolve these lang items to their definition point which is impossible in the current system, as lang items are only saved in the mappings during lowering (and thus after name resolution). This small visitor collects lang items and stores their NodeIds in the mappings for an easy resolution.

gcc/rust/ChangeLog:

	* util/rust-hir-map.h: Keep a NodeId mappings for lang items.
	* util/rust-hir-map.cc (Mappings::insert_lang_item_node): New function.
	(Mappings::lookup_lang_item_node): Likewise.
gcc/rust/ChangeLog:

	* Make-lang.in: Add new object file.
	* rust-session-manager.cc (Session::compile_crate): Call CollectLangItems.
	* ast/rust-collect-lang-items.cc: New file.
	* ast/rust-collect-lang-items.h: New file.
@CohenArthur CohenArthur force-pushed the collect-lang-items-ast branch from 514c1f4 to 89425cf Compare December 4, 2024 13:56
gcc/rust/ChangeLog:

	* util/rust-attributes.h (class Attributes): New.
	* util/rust-attributes.cc: Implement Attributes::is_known().
	* ast/rust-collect-lang-items.cc (is_known_attribute): Remove.
	(get_lang_item_attr): Call Attributes::is_known() instead.
	* hir/rust-ast-lower-base.cc (ASTLoweringBase::handle_outer_attributes): Likewise.
	(ASTLoweringBase::is_known_attribute): Remove.
Comment on lines +1244 to +1246
// FIXME: Before merging: Should we remove the `locus` parameter here? since
// lang items are looked up mostly for code generation, it doesn't make sense to
// error out on the locus of the node trying to access an inexistant lang item
Copy link
Member Author

Choose a reason for hiding this comment

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

This would require changes in a lot of code which fetches lang items, such as the typechecker and codegen. It would be done in a later PR

@CohenArthur CohenArthur added this to the Lang items path fixes milestone Dec 4, 2024
Copy link
Member

@P-E-P P-E-P left a comment

Choose a reason for hiding this comment

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

It looks good, I only put a small comment but it could be merged as is.

continue;
}

bool is_lang_item = str_path == Values::Attributes::LANG
Copy link
Member

Choose a reason for hiding this comment

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

We should introduce some helper function here instead, I'm sure it would be reused elsewhere and it would ease this function a bit.

Probably within rust-attributes.cc since we already have some similar functions there ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I think it'd be good but in a different PR. it would be a good good-first-pr issue too

@CohenArthur CohenArthur added this pull request to the merge queue Dec 4, 2024
Merged via the queue into Rust-GCC:master with commit 7208108 Dec 4, 2024
13 checks passed
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