-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
hygiene: Eliminate expansion hierarchy in favor of call-site hierarchy #51457
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
Hmm, we need someone interested in hygiene and not on PTO, parental leave or perpetual absence. Hard choice. cc @nrc @jseyfried |
} | ||
} | ||
|
||
macro use_field($define_field: item) { |
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.
Can you also add a test for macro_rules, as they go through different code?
} | ||
|
||
use_field!(define_field!{}); | ||
|
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.
if define_field took an identifier as an argument, and the user passed "field" as the identifier, would that have compiled before, but would fail now? Or are there other ways this is a breaking change (other than diagnostics)?
I have a feeling there could be very subtle breakage
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.
Yes, this is a subtle breakage for users of declarative macros 2.0 and their def-site hygiene.
A had hard time coming up even with one behavior-changing test though (but it turned out to fix things, rather than break).
I'll add a test for field
passed as an identifier and macro_rules! use_field
, but I'm pretty sure the second one is not affected by the change (it doesn't go through the "who is the parent" logic).
26b08a0
to
643391f
Compare
Updated. |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
643391f
to
ef001ae
Compare
@@ -347,7 +347,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { | |||
let derives = derives.entry(invoc.expansion_data.mark).or_insert_with(Vec::new); | |||
|
|||
for path in &traits { | |||
let mark = Mark::fresh(self.cx.current_expansion.mark); |
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 was more worried about this causing breaking changes to macro_rules
than breaking the unstable macros 2.0. But I also cannot come up with an example that would break due to this change. Maybe we should do a crater run?
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.
Yeah, that would be interesting since unstable crates are on crates.io too.
Check-only crater run requested! |
@bors try |
⌛ Trying commit ef001ae with merge fbbd1bb74974ed8dd0d394e4dfcd2383462475f6... |
💔 Test failed - status-travis |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
hygiene: Eliminate expansion hierarchy in favor of call-site hierarchy "Expansion hierarchy" and "call-site hierarchy" are two slightly different ways to nest macro invocations and answer the question "who is the parent" for a given invocation. For example, here both hierarchies coincide ```rust macro inner() { ... } macro outer() { inner!() } outer!(); // expansions: root -> outer -> inner // call-sites: root -> outer -> inner ``` but here they are different ```rust macro inner() { ... } macro outer($stuff: stuff) { $stuff } // expansions: root -> outer -> inner (`inner` is expanded as a part of `outer`'s output) // call-sites: root -> outer; root -> inner outer!(inner!()) ``` All our talk about hygiene was in terms of "def-site" and "call-site" name resolution so far and the "expansion hierarchy" is an internal detail, but it was actually used in few places in the way affecting resolution results. For example, in the attached test case the structure `S` itself was previously resolved succesfully, but resolution of its field `field` failed due to use of "expansion hierarchy". This PR eliminates expansion hierarchy from hygiene algorithm and uses call-site hierarchy instead. This is also a nice simplification of the model. Instead of growing in *three* dimensions in similar but subtly different ways (def-site, call-site, expansion) hygiene hierarchies now grow in *two* dimensions in similar but subtly different ways (def-site, call-site).
☀️ Test successful - status-travis |
If crater isn't started yet, then I'll close this. Apparently |
|
"Expansion hierarchy" and "call-site hierarchy" are two slightly different ways to nest macro invocations and answer the question "who is the parent" for a given invocation.
For example, here both hierarchies coincide
but here they are different
All our talk about hygiene was in terms of "def-site" and "call-site" name resolution so far and the "expansion hierarchy" is an internal detail, but it was actually used in few places in the way affecting resolution results. For example, in the attached test case the structure
S
itself was previously resolved succesfully, but resolution of its fieldfield
failed due to use of "expansion hierarchy".This PR eliminates expansion hierarchy from hygiene algorithm and uses call-site hierarchy instead.
This is also a nice simplification of the model.
Instead of growing in three dimensions in similar but subtly different ways (def-site, call-site, expansion) hygiene hierarchies now grow in two dimensions in similar but subtly different ways (def-site, call-site).