-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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 2.0: Avoid comparing fields by name #49718
Conversation
r? @pnkfelix (rust_highfive has picked a reviewer for you, use r? to override) |
r? @eddyb |
Your PR failed on Travis. Through arcane magic we have determined that the following fragments from the build log may contain information about the problem. 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 latest upstream changes (presumably #49154) made this pull request unmergeable. Please resolve the merge conflicts. |
Updated with some tests. |
@bors r+ |
📌 Commit 8b2fcb0 has been approved by |
☔ The latest upstream changes (presumably #49875) made this pull request unmergeable. Please resolve the merge conflicts. |
Resolve them into field indices once and then use those resolutions + Fix rebase
@bors r=eddyb |
📌 Commit fcf4852 has been approved by |
@bors p=1 Looks relatively conflict prone and is blocking other work. |
Hygiene 2.0: Avoid comparing fields by name There are two separate commits here (not counting tests): - The first one unifies named (`obj.name`) and numeric (`obj.0`) field access expressions in AST and HIR. Before field references in these expressions are resolved it doesn't matter whether the field is named or numeric (it's just a symbol) and 99% of code is common. After field references are resolved we work with them by index for all fields (see the second commit), so it's again not important whether the field was named or numeric (this includes MIR where all fields were already by index). (This refactoring actually fixed some bugs in HIR-based borrow checker where borrows through names (`S { 0: ref x }`) and indices (`&s.0`) weren't considered overlapping.) - The second commit removes all by-name field comparison and instead resolves field references to their indices once, and then uses those resolutions. (There are still a few name comparisons in save-analysis, because save-analysis is weird, but they are made correctly hygienic). Thus we are fixing a bunch of "secondary" field hygiene bugs (in borrow checker, lints). Fixes #46314
☀️ Test successful - status-appveyor, status-travis |
Tested on commit rust-lang/rust@defcfe7. Direct link to PR: <rust-lang/rust#49718> 💔 clippy-driver on windows: test-pass → build-fail (cc @Manishearth @llogiq @mcarton @oli-obk). 💔 clippy-driver on linux: test-pass → build-fail (cc @Manishearth @llogiq @mcarton @oli-obk).
Whoops, I missed this until just now - it breaks Rustfmt as well as Clippy. But I wanted to comment on the strategy here, it seems that this is the kind of thing that should be done on the HIR, but not on the AST - it is useful for tools to be able to tell the two operations apart syntactically and the rest of the compiler could still unify code because it operates on the HIR. The lowering step could easily unify the two kinds of field access. |
This is especially annoying for Rustfmt because formatting changes - we can output |
For the compiler itself it's more convenient to keep all fields as identifiers even in AST, there are no places where they would be treated differently + parsing logic and hygiene-keeping is simplified, so I optimized for that. |
This update includes removal of ExprKind::TupField(rust-lang/rust#49718). With this change, I changed the logic of method completion for tuple struct and added a related test.
By rust-lang/rust#49718, ExprKind::TupField was removed. This commit includes a temorary fix and a tests for this removal.
There are two separate commits here (not counting tests):
obj.name
) and numeric (obj.0
) field access expressions in AST and HIR. Before field references in these expressions are resolved it doesn't matter whether the field is named or numeric (it's just a symbol) and 99% of code is common. After field references are resolved we work withthem by index for all fields (see the second commit), so it's again not important whether the field was named or numeric (this includes MIR where all fields were already by index).
(This refactoring actually fixed some bugs in HIR-based borrow checker where borrows through names (
S { 0: ref x }
) and indices (&s.0
) weren't considered overlapping.)Thus we are fixing a bunch of "secondary" field hygiene bugs (in borrow checker, lints).
Fixes #46314