Skip to content

Extern prelude handling - #4758

Open
P-E-P wants to merge 9 commits into
Rust-GCC:masterfrom
P-E-P:extern_prelude_2
Open

P-E-P wants to merge 9 commits into
Rust-GCC:masterfrom
P-E-P:extern_prelude_2

Conversation

@P-E-P

@P-E-P P-E-P commented Aug 4, 2026

Copy link
Copy Markdown
Member

No description provided.

@P-E-P
P-E-P force-pushed the extern_prelude_2 branch from 458859f to 047b08a Compare August 4, 2026 10:31
@P-E-P
P-E-P force-pushed the extern_prelude_2 branch 3 times, most recently from b8dd134 to 64c7d0b Compare August 24, 2026 00:31
@P-E-P
P-E-P force-pushed the extern_prelude_2 branch 2 times, most recently from 4a55587 to 5fe50cf Compare September 28, 2026 17:59
P-E-P and others added 9 commits September 29, 2026 14:04
We usually test components independently, this means we did not test for
lang item declaration within external crate. This commit introduces a new
test directory to test external crate boundary.

gcc/testsuite/ChangeLog:

	* rust/minicore/extern_lang_items.rs: New test.
	* rust/minicore/extern_lang_items_core/lib.rs: New test.
	* rust/minicore/minicore.exp: New test.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Macros are already emitted by the AST dump within metadata files, we no
longer require a separate export pass from within the metadata exporter.

gcc/rust/ChangeLog:

	* metadata/rust-export-metadata.cc (PublicInterface::gather_export_data):
	Do not emit macros separately anymore.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Return the injected crate's node id.

gcc/rust/ChangeLog:

	* ast/rust-ast.cc (Crate::inject_extern_crate): Return the injected
	crate's node id.
	* ast/rust-ast.h: Update the function's prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Kernel and core related tests as well as their core crate needs to be
compiled with a matching rust edition. In order to enforce that we
control the edition from the testsuite instead of relying on a per crate
edition change. Moreover, the kernel and core 1.49 is meant to be
compiled with rust edition 2018, using this edition will make things
easier for us.

gcc/testsuite/ChangeLog:

	* rust/minicore/minicore.exp: Enforce crate edition at test top level.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Node streaming started from the root and did not walk through the
different preludes within the forever stack. This enables a more complete
representation of the forever stack.

gcc/rust/ChangeLog:

	* resolve/rust-forever-stack.hxx: Stream extern and lang prelude nodes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
This data structure is complex, when using the debug dump within a
debugger we often need to know what is the current state and where new
nodes will be pushed within the forever stack.

gcc/rust/ChangeLog:

	* resolve/rust-forever-stack.hxx: Debug the forever stack cursor
	position.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
We did not assign any node id to neither extern and lang prelude nodes
and this was confusing and could lead to unexpected behaviors (duplicate
ids).

gcc/rust/ChangeLog:

	* resolve/rust-forever-stack.h: Assign a node id to extern and lang
	nodes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Extern crates were not inserted within the extern prelude.

gcc/rust/ChangeLog:

	* ast/rust-ast.cc (Crate::inject_extern_crate): Inject extern crates
	at the beginning of the crate instead of the end.
	* resolve/rust-forever-stack.h: Add function prototype to insert a
	crate within the extern prelude.
	* resolve/rust-forever-stack.hxx: Add function to insert extern crate
	within extern prelude.
	* resolve/rust-name-resolution-context.cc (NameResolutionContext::insert_crate_in_prelude):
	Insert extern crate within all extern prelude namespaces.
	* resolve/rust-name-resolution-context.h: Add function prototype.
	* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Inject
	extern crate within extern prelude during top level nr.

Signed-off-by: Pierre-Emmanuel Patry <pierre.emmanuel.patry@opensrcsec.com>
Top level module should collide with extern crate names and the error
should be reported on the module, not the extern crate because the latter
may not have a source location given it may have been injected.

gcc/testsuite/ChangeLog:

	* rust/minicore/top_core_modules.rs: New test.
	* rust/minicore/top_core_modules_core/lib.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry <pierre.emmanuel.patry@opensrcsec.com>
@P-E-P
P-E-P marked this pull request as ready for review September 29, 2026 12:05
@P-E-P
P-E-P requested a review from CohenArthur September 29, 2026 12:07

This branch has not been deployed

No deployments
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.

1 participant