-
Notifications
You must be signed in to change notification settings - Fork 187
name-resolution: Add std/core prelude resolution #4149
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
base: master
Are you sure you want to change the base?
Conversation
gcc/rust/ChangeLog: * resolve/rust-early-name-resolver-2.0.cc (Early::finalize_glob_import): Save prelude if we find one. * resolve/rust-name-resolution-context.h: Add field. * resolve/rust-toplevel-name-resolver-2.0.cc (has_prelude_import): New function. (TopLevel::visit): Create a prelude glob import if necessary. * resolve/rust-toplevel-name-resolver-2.0.h: Allow glob imports to be prelude imports.
gcc/rust/ChangeLog: * resolve/rust-forever-stack.h: Add new resolve_path function. * resolve/rust-forever-stack.hxx: Implement it.
88a2da9
to
8811544
Compare
gcc/rust/ChangeLog: * resolve/rust-forever-stack.h: New function. * resolve/rust-forever-stack.hxx: Implement it. * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Call it if the prelude exists and we have an unresolved Identifier Call it if the prelude exists and we have an unresolved Identifier.
{ | ||
rust_assert (!segments.empty ()); | ||
|
||
std::reference_wrapper<Node> starting_point = cursor (); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should probably just add a new variant to ResolutionMode
, instead of adding a user-provided starting_point
in addition to mode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ForeverStack
could probably fetch the node id associated with the language prelude from NameResolutionContext
-- might be kind of tricky to get that working, though. You could also just have each ForeverStack
keep a std::reference_wrapper
to the currently set prelude Node
.
case Namespace::Macros: | ||
return macros.resolve_path (segments, mode, | ||
insert_segment_resolution, | ||
collect_errors, *prelude); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should probably use a temporary vector instead of collect_errors
for the prelude resolution -- if prelude resolution does emit errors and fail, only the errors produced during the normal resolution attempt should be collected.
This PR adds name resolution within the prelude marked with
#[prelude_import]
. This is important for compiling core, and for compiling crates in general - as the compiler is supposed to inject the#[prelude_import]
use-declaration if it is not user defined.The current implementation attempts to resolve within the prelude if regular resolution has failed.
The prelude is collected and stored in the name-resolution context.