Skip to content

Adjust external crate lowering and type checking#3830

Merged
philberty merged 1 commit into
Rust-GCC:masterfrom
powerboat9:adjust-link-m
Jun 18, 2025
Merged

Adjust external crate lowering and type checking#3830
philberty merged 1 commit into
Rust-GCC:masterfrom
powerboat9:adjust-link-m

Conversation

@powerboat9

Copy link
Copy Markdown
Collaborator

Name resolution 2.0 doesn't like crates being typechecked before the initialization of ImmutableNameResolutionContext

@powerboat9 powerboat9 requested a review from P-E-P June 17, 2025 03:49
@powerboat9

powerboat9 commented Jun 17, 2025

Copy link
Copy Markdown
Collaborator Author

I thought about initializing ImmutableNameResolutionContext sooner, but I didn't think it would make sense to do so before the name resolution context is expected to become immutable.

@philberty

Copy link
Copy Markdown
Member

I think i need an example of the issue you were seeing that you needed this try to add a little more info into your commit messages its super important later on.

The 2.0 name resolver is provided through
ImmutableNameResolutionContext after it is done being mutated. The
typechecker attempts to use ImmutableNameResolutionContext, so it needs
to be run after ImmutableNameResolutionContext has been initialized
(after all name resolution has been completed). Additionally, although I
haven't seen any issues with lowering AST to HIR before name resolution
2.0 is complete, it makes sense to perform all lowering in lockstep as
well.

gcc/rust/ChangeLog:

	* hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Add
	visitor for ExternCrate.
	* hir/rust-ast-lower-item.h (ASTLoweringItem::visit): Likewise.
	* rust-session-manager.cc (Session::load_extern_crate): Avoid
	lowering or type resolving external crates here.
	* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit):
	Add visitor for ExternCrate.
	* typecheck/rust-hir-type-check-item.h (TypeCheckItem::visit):
	Replace empty definition with a declaration.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
@powerboat9

Copy link
Copy Markdown
Collaborator Author

I think i need an example of the issue you were seeing that you needed this try to add a little more info into your commit messages its super important later on.

Fixed?

@philberty philberty 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.

Ah ok i see what you mean now this looks kind of neat actually. LGTM

@philberty philberty added this pull request to the merge queue Jun 18, 2025
Merged via the queue into Rust-GCC:master with commit 3b4d11c Jun 18, 2025
12 checks passed
@powerboat9 powerboat9 deleted the adjust-link-m branch June 18, 2025 12:13
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