-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
syntax_pos::symbol::Symbol::gensym() is incompatible with stable hashing. #49300
Comments
I generally consider |
We should investigate implementing gensyms via |
Blocked on removing emulation of hygiene with gensyms (can't emulate gensyms with hygiene if we are doing exactly the opposite thing right now!) (https://github.com/petrochenkov/rust/tree/spident2, in progress), which in its turn is waiting for #49154 and #49718. |
Could gensym generate a name with a stable prefix (proc macro crate name + version), a stable ID (proc macro invocation local) and some character that is illegal in names, so noone can name it? Maybe even throw in the stable hash of the code it is invoked upon? |
Categorizing as P-high so that this keeps annoying us, even though we don't have anyone assigned to it or actively working on it. |
We've been coming back to this issue in the @rust-lang/compiler meeting without progress for a few weeks in a row now. It would be great if we could come up with some action items. @petrochenkov , the two blocking PRs you mentioned above have be merged in the meantime. What would be the next steps? Or broader question: Do we know what to do and just need to implement it or are there still open questions about how this can be solved? |
With regards to the first part (removing emulation of hygiene with gensyms) we know what to do and just need to implement it. The good news is that I have a few free days before I leave on vacation on May 31, and I was going to spend them on Macro 1.2 stuff, but there's a good chance I'll have time left on With regards to the second part, I didn't yet think about how exactly gensyms should be encoded in |
That sounds like good news, thanks @petrochenkov! Regarding stability: The main requirement is that a gensymed symbol hashes the same way in two different compilation sessions regardless of what other HIR items have been added before or after it. If something in the item that contains the symbol has changed, then the hash can also change. An example what we need for stable hashing are |
visiting for triage. assigning to @michaelwoerister to ensure that it gets addressed (potentially via further delegation). |
Some status update: 94ef9f5 was merged, so all macros (including legacy builtin ones) can now easily generate identifiers with def-site hygiene. |
Thanks for the awesome work so far, @petrochenkov! The current situation is that we don't use I haven't had time to think about the various solution strategies yet. |
visiting for triage. No progress yet. Should consider either reassigning or lowering priority if we are still stalled next week. |
The problem remains, but at least we have some kind of assertion that should catch problems related to it. Going to downgrade to P-medium for now. |
In particular, this one: rust/src/librustc/ty/query/plumbing.rs Lines 526 to 535 in fbb6275
|
I haven't seen this written out explicitly, but expansion/hygiene data can be stored in metadata/incremental-data in a stable way using the same The basic thing to encode here is mod m {
fn foo() { // def-path: m::foo
// Here's how the closures' `NodeId`s get a stable representation.
let closure1 = || {}; // m::foo(1)
let closure2 = || {}; // m::foo(2)
// Same idea, but for macro invocations and their `ExpnId`s instead of `NodeId`s
mac1!(); // m::foo!(1)
mac2!(); // m::foo!(2)
}
} If we can encode #63919 should be one of few last steps in the removal of gensyms, after that we'll only have hygiene, which should be encodable as described above, if I'm not missing anything. |
Hm, making macro invocations a regular |
@michaelwoerister Yeah, that's also roughly my vision for moving incremental further back, I think I discussed it with @nikomatsakis before. I was supposed to write about this months ago but other things came up. In short, there'd be "Def" layer that parsing, expansion and cross-crate metadata would all interact with, with AST/HIR remaining mainly for the intra-definition syntactic categories and miscellaneous syntax. A first step could be splitting HIR into "HIR Def" and "everything else", but moving def paths by themselves further back would also make sense. |
Def paths are currently created during expansion, when a freshly expanded AST fragment is integrated into the partially built AST. |
Remove last uses of gensyms Bindings are now indexed in resolve with an additional disambiguator that's used for underscore bindings. This is the last use of gensyms in the compiler. I'm not completely happy with this approach, so suggestions are welcome. Moving undescore bindings into their own map didn't turn out any better: master...matthewjasper:remove-underscore-gensyms. closes #49300 cc #60869 r? @petrochenkov
🎉 🎉 🎉 🎉 🎉 |
The current scheme for "gensym"ing names via
Symbol::gensym()
is rather clever and elegant but unfortunately it defies being hashed in a stable way as is needed for incremental compilation. So far, incr. comp. has erroneously treated differingSymbols
with equal string contents as being the same. Now situations are starting to arise where this leads to problems (#48923, #49065).I consider this a somewhat urgent issue.
cc @rust-lang/compiler, esp. @petrochenkov & @jseyfried
The text was updated successfully, but these errors were encountered: