Skip to content

gccrs: Search lang_prelude when reaching module boundary during name resolution#4580

Merged
CohenArthur merged 1 commit into
Rust-GCC:masterfrom
Polygonalr:lang_prelude_name_res
Jun 15, 2026
Merged

gccrs: Search lang_prelude when reaching module boundary during name resolution#4580
CohenArthur merged 1 commit into
Rust-GCC:masterfrom
Polygonalr:lang_prelude_name_res

Conversation

@Polygonalr

Copy link
Copy Markdown
Contributor

Name resolution does not resolve language preludes properly within a module. This PR fixes that.

@powerboat9 powerboat9 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm pretty sure there's some better way we should be doing this, but I'm not quite sure what, so LGTM

Comment on lines +386 to +389
if ((current_node->is_root ()
|| (is_start (iterator, segments)
&& current_node->rib.kind == Rib::Kind::Module))
&& !searched_prelude)

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 would suggest doing something like this which would be cleaner and easier to modify later:

Suggested change
if ((current_node->is_root ()
|| (is_start (iterator, segments)
&& current_node->rib.kind == Rib::Kind::Module))
&& !searched_prelude)
if (should_search_prelude())

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.

You'll need to do something like should_search_prelude(current_node, searched_prelude) if we want to keep it as a simple static void function helper and not a full-on class function

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh there's some template jank involved around here, see whether my current abstraction works out :v

Comment thread gcc/testsuite/rust/compile/name_resolution28.rs Outdated
@Polygonalr Polygonalr force-pushed the lang_prelude_name_res branch 2 times, most recently from 6128f0e to f88754e Compare June 9, 2026 14:34

@CohenArthur CohenArthur left a comment

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.

Once the style comment is fixed I think this is good to go 👍 well done

Comment thread gcc/rust/resolve/rust-name-resolution-context.hxx Outdated
…resolution

gcc/rust/ChangeLog:

	* resolve/rust-name-resolution-context.h (NameResolutionContext): Add new function
	definition for `should_search_prelude`.
	* resolve/rust-name-resolution-context.hxx (NameResolutionContext::should_search_prelude):
	Add implementation.
	(NameResolutionContext::resolve_segments): Update the check to trigger lang_prelude search
	during name resolution in modules.

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
@Polygonalr Polygonalr force-pushed the lang_prelude_name_res branch from f88754e to 0154f5c Compare June 10, 2026 14:25
@CohenArthur CohenArthur added the core Issue related to the compilation of the `core` crate label Jun 11, 2026

@CohenArthur CohenArthur left a comment

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.

LGTM

@CohenArthur CohenArthur added this pull request to the merge queue Jun 15, 2026
Merged via the queue into Rust-GCC:master with commit 035002f Jun 15, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Issue related to the compilation of the `core` crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants