-
Notifications
You must be signed in to change notification settings - Fork 173
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
Fix modules with same name as builtins causing ICE (#3315) #3437
base: master
Are you sure you want to change the base?
Conversation
44e6e4e
to
98f7902
Compare
// we're at the root :) hopefully! Globbed declaration allows | ||
// user-defined items in the `types` namespace | ||
// to shadow builtins. Probably unwise, but allowed by rustc! | ||
auto ok = ctx.types.insert_globbed (builtin.name, builtin.node_id); |
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.
Since it's in a separate rib, insert
, insert_shadowable
, or insert_globbed
would all work fine here
@@ -107,6 +107,11 @@ NameResolutionContext::scoped (Rib::Kind rib_kind, NodeId id, | |||
std::function<void (void)> lambda, | |||
tl::optional<Identifier> path) | |||
{ | |||
// Prelude doesn't have an access path | |||
// TODO: Assert current cursor is at the root |
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.
This should already hit an assertion, so you could remove the comment or add another assertion
// Prelude doesn't have an access path | ||
// TODO: Assert current cursor is at the root | ||
if (rib_kind == Rib::Kind::Prelude) | ||
rust_assert (!path); |
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.
This could be moved to push_inner
or copied there, but an assertion like this should probably be in push_inner
It's alright, it looks good |
c9a02b2
to
20e456a
Compare
@powerboat9 Thank you for the reviews, and sorry about the TODO: comments -- I forgot about those. I think I fixed all of the issues you pointed out. |
933eba4
to
05aaeb8
Compare
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.
Looks like a regression for:
Running /home/runner/work/gccrs/gccrs/gcc/testsuite/rust/borrowck/borrowck.exp ...
Running /home/runner/work/gccrs/gccrs/gcc/testsuite/rust/compile/compile.exp ...
Running /home/runner/work/gccrs/gccrs/gcc/testsuite/rust/compile/macros/builtin/builtin_macro.exp ...
Running /home/runner/work/gccrs/gccrs/gcc/testsuite/rust/compile/macros/mbe/mbe_macro.exp ...
Running /home/runner/work/gccrs/gccrs/gcc/testsuite/rust/compile/macros/proc/proc_macro.exp ...
Running /home/runner/work/gccrs/gccrs/gcc/testsuite/rust/compile/nr2/compile.exp ...
FAIL: /home/runner/work/gccrs/gccrs/gcc/testsuite/rust/compile/macros/mbe/macro54.rs: nr2 failure: FAIL: rust/compile/macros/mbe/macro54.rs -frust-name-resolution-2.0 (test for excess errors)
For some reason after rebasing these fail now. I'll take a look at these |
I think the strategy I chose to implement this doesn't work, since the test involves resolving something like u32::VALUE. I'll try to re-implement |
a865b40
to
dbc0b7d
Compare
@powerboat9 @philberty I added some code to get_segments to handle the prelude rib as a special case. I think my PR should work now |
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.
Otherwise, looks great
{ | ||
// If you push_inner into the prelude from outside the root, you will pop | ||
// back into the | ||
// root, which could screw up a traversal. |
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.
Should probably adjust the formatting on this comment
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.
fixed
@@ -487,6 +519,7 @@ ForeverStack<N>::resolve_segments ( | |||
* |
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.
Should probably add an entry to the numbered list in the above comment, mentioning changing searched_prelude
from false
to true
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.
I added a comment for this, let me know if it needs modification.
* It has the root node as a parent, and acts as a "special case" for name | ||
* resolution | ||
*/ | ||
Node 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.
I probably should have noticed and commented on this earlier, but this should really be called something like language_prelude
, given that we'll have to deal with multiple preludes
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.
I considered that as well, I figured that we would also dump the std::prelude and core::prelude in here as well
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.
I figured we'd keep some sort of reference to the standard library prelude -- since that should already be a module with its own Node
, we shouldn't need to try to copy entries into another Node
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.
I think the comment there clarifies that it's currently only used for the language prelude (language builtins). If it needs to be beefed up with a better explanation I can do that.
@@ -107,6 +107,7 @@ NameResolutionContext::scoped (Rib::Kind rib_kind, NodeId id, | |||
std::function<void (void)> lambda, | |||
tl::optional<Identifier> path) | |||
{ | |||
// NOTE: You should be at the root node when calling this function. |
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 be at the root node, if pushing a Prelude
rib kind
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.
🤦
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.
I'll update to clarify that we only need to be at the root for the prelude rib pushes
It looks like rustc has some backtracking capability. We may have to implement something like that later, for full parity, but that's probably outside the scope of this PR |
gcc/rust/ChangeLog: * resolve/rust-forever-stack.h: Add a dedicated prelude node for the Language prelude * resolve/rust-forever-stack.hxx: Add support code for the prelude node * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Move language prelude builtins to the prelude context * resolve/rust-name-resolution-context.cc: Add code for handling the prelude corner case * resolve/rust-rib.h: Add a special Prelude rib type gcc/testsuite/ChangeLog: * rust/compile/issue-3315-1.rs: Add test for module with same name as builtin * rust/compile/issue-3315-2.rs: Test with utilization of i32 type * rust/compile/nr2/exclude: issue-3315-2.rs Does not work with NR2.0 Signed-off-by: Liam Naddell <liamnprg@gmail.com>
@powerboat9 I can update to move the language prelude to rust-forever-stack.hxx if you still want the change
Thank you for making Rust GCC better!
If your PR fixes an issue, you can add "Fixes #issue_number" into this
PR description and the git commit message. This way the issue will be
automatically closed when your PR is merged. If your change addresses
an issue but does not fully fix it please mark it as "Addresses #issue_number"
in the git commit message.
Here is a checklist to help you with your PR.
make check-rust
passes locallyclang-format
gcc/testsuite/rust/
Note that you can skip the above if you are just opening a WIP PR in
order to get feedback.
*Please write a comment explaining your change. This is the message
that will be part of the merge commit.