Skip to content

nr2.0: Adjust resolution of modules#3826

Merged
P-E-P merged 1 commit into
Rust-GCC:masterfrom
powerboat9:fix-mod
Jun 30, 2025
Merged

nr2.0: Adjust resolution of modules#3826
P-E-P merged 1 commit into
Rust-GCC:masterfrom
powerboat9:fix-mod

Conversation

@powerboat9

Copy link
Copy Markdown
Collaborator

This prioritizes resolution in the language prelude over resolution as a module.

void
TopLevel::visit (AST::Module &module)
{
insert_or_error_out (module.get_name (), module, Namespace::Types);

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.

Can't wrap my mind around this line, why is it required to removed the module name from type namespace ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

To change the resolution order to non-modules -> lang items -> modules

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 feel we're doing something wrong somewhere, rustc resolves modules first during top level and from what I heard struggles with their implementation. I'll need some time to think about that.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I'm seeing

            // In `a(::assoc_item)*` `a` cannot be a module. If `a` does resolve to a module we
            // don't report an error right away, but try to fallback to a primitive type.
            // So, we are still able to successfully resolve something like
            //
            // use std::u8; // bring module u8 in scope
            // fn f() -> u8 { // OK, resolves to primitive u8, not to std::u8
            //     u8::max_value() // OK, resolves to associated function <u8>::max_value,
            //                     // not to non-existent std::u8::max_value
            // }
            //
            // Such behavior is required for backward compatibility.
            // The same fallback is used when `a` resolves to nothing.

in the rustc source code (rustc_resolve/src/late.rs, 1.49)

@P-E-P P-E-P 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.

Took me a bit longer than expected. Thank you! If you could rebase this PR, I'll be happy to merge it.

This prioritizes resolution in the language prelude over resolution as a
module.

gcc/rust/ChangeLog:

	* resolve/rust-forever-stack.hxx (ForeverStack::resolve_path):
	Resolve final segments which point to modules.
	* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit):
	Avoid inserting module names into ribs in the type namespace.

gcc/testsuite/ChangeLog:

	* rust/compile/nr2/exclude: Remove issue-3315-2.rs.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
@P-E-P P-E-P added this pull request to the merge queue Jun 30, 2025
Merged via the queue into Rust-GCC:master with commit eed2723 Jun 30, 2025
13 checks passed
@powerboat9 powerboat9 deleted the fix-mod branch June 30, 2025 21:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants