Uh oh!
There was an error while loading. Please reload this page.
macros: Remove matching on "complex" nonterminals requiring AST comparisons - #49326
Conversation
rust-highfive
commented
Mar 24, 2018
(rust_highfive has picked a reviewer for you, use r? to override) |
petrochenkov
commented
Mar 24, 2018
cc #49154 (comment) |
There's one pattern I know of that this could break, though it's fine if macro_rules! eq {($a:tt $b:tt) => {
macro_rules! __eq {($a $a) => {/* equal */};($a $b) => {/* not equal */}}
__eq!($a $b);}}Arcane, yes, but useful. This trick is the basis of my crate |
sdleffler
commented
Mar 25, 2018
@durka notably, iirc, this trick no longer works if you call that macro more than once: last time I tried it, I got a "macro shadows another macro" error :( |
@sdleffler |
Mark-Simulacrum
commented
Mar 26, 2018
We'll want crater artifacts eventually presumably. @bors try |
bors
commented
Mar 26, 2018
⌛ Trying commit 8eb9aa4acebd6a6c62328e728e1525e89f279196 with merge 0b4b23eb7eedcac71ed7287e39e46f44946babf1... |
eddyb
commented
Mar 26, 2018
We should probably compare the underlying tokens the fragment was parsed from, eventually. Another weird thing happening with nonterminals is we expand macros in them (#47358 (comment)). |
bors
commented
Mar 26, 2018
☀️ Test successful - status-travis |
aidanhs
commented
Mar 31, 2018
Crater run started. |
aidanhs
commented
Apr 8, 2018
(apologies for the delay, I fell ill last week) Hi @petrochenkov (crater requester), @eddyb (PR reviewer)! Crater results are at: http://cargobomb-reports.s3.amazonaws.com/pr-49326/index.html. 'Blacklisted' crates (spurious failures etc) can be found here. If you see any spurious failures not on the list, please make a PR against that file. (interested observers: Crater is a tool for testing the impact of changes on the crates.io ecosystem. You can find out more at the repo if you're curious) |
petrochenkov
commented
Apr 8, 2018
All the regressions are spurious. |
nikomatsakis
commented
Apr 12, 2018
Discussed in the @rust-lang/lang meeting and we agreed to go forward with this change. It seems like this was never intentional and we can't really be exposing the details of how |
eddyb
commented
Apr 12, 2018
@bors r+ |
bors
commented
Apr 12, 2018
📌 Commit 8eb9aa4 has been approved by |
bors
commented
Apr 13, 2018
⌛ Testing commit 8eb9aa4acebd6a6c62328e728e1525e89f279196 with merge e6410f50dc146fecc530e42971e4012ad15247f7... |
bors
commented
Apr 13, 2018
💔 Test failed - status-appveyor |
rust-highfive
commented
Apr 13, 2018
Your PR failed on Travis (raw log). 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 |
petrochenkov
commented
Apr 13, 2018
Needs rebase. |
petrochenkov
commented
Apr 13, 2018
@bors r=eddyb |
bors
commented
Apr 13, 2018
📌 Commit 5bbfd67 has been approved by |
petrochenkov
commented
Apr 13, 2018
@bors r=eddyb |
bors
commented
Apr 13, 2018
📌 Commit 7e1f73b has been approved by |
rust-highfive
commented
Apr 13, 2018
Your PR failed on Travis (raw log). 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 |
bors
commented
Apr 14, 2018
macros: Remove matching on "complex" nonterminals requiring AST comparisons
So, you can actually use nonterminals from outer macros in left hand side of nested macros and invocations of nested macros will try to match passed arguments to them.
```rust
macro outer($nt_item: item) {
macro inner($nt_item) {
struct S;
}
inner!($nt_item); // OK, `$nt_item` matches `$nt_item`
}
```
Why this is bad:
- We can't do this matching correctly. When two nonterminals are compared, the original tokens are lost and we have to compare AST fragments instead. Right now the comparison is done by `PartialEq` impls derived on AST structures.
- On one hand, AST loses information compared to original tokens (e.g. trailing separators and other simplifications done during parsing to AST), so we can produce matches that are not actually correct.
- On another hand derived `PartialEq` impls for AST structures don't make much sense in general and compare various auxiliary garbage like spans. For the argument nonterminal to match we should use literally the same token (possibly cloned) as was used in the macro LHS (as in the example above). So we can reject matches that are actually correct.
- Support for nonterminal matching is the only thing that forces us to derive `PartialEq` for all (!) AST structures. As I mentioned these impls are also mostly nonsensical.
This PR removes support for matching on all nonterminals except for "simple" ones like `ident`, `lifetime` and `tt` for which we have original tokens that can be compared.
After this is done I'll submit another PR removing huge number of `PartialEq` impls from AST and HIR structures.
This is an arcane feature and I don't personally know why would anyone use it, but the change should ideally go through crater.
We'll be able to support this feature again in the future when all nonterminals have original token streams attached to them in addition to (or instead of) AST fragments.bors
commented
Apr 14, 2018
☀️ Test successful - status-appveyor, status-travis |
Remove most of `PartialEq` and `Hash` impls from AST and HIR structures Continuation of #49326, prerequisite for removing `PartialEq` for `Ident`.
So, you can actually use nonterminals from outer macros in left hand side of nested macros and invocations of nested macros will try to match passed arguments to them.
Why this is bad:
PartialEqimpls derived on AST structures.PartialEqimpls for AST structures don't make much sense in general and compare various auxiliary garbage like spans. For the argument nonterminal to match we should use literally the same token (possibly cloned) as was used in the macro LHS (as in the example above). So we can reject matches that are actually correct.PartialEqfor all (!) AST structures. As I mentioned these impls are also mostly nonsensical.This PR removes support for matching on all nonterminals except for "simple" ones like
ident,lifetimeandttfor which we have original tokens that can be compared.After this is done I'll submit another PR removing huge number of
PartialEqimpls from AST and HIR structures.This is an arcane feature and I don't personally know why would anyone use it, but the change should ideally go through crater.
We'll be able to support this feature again in the future when all nonterminals have original token streams attached to them in addition to (or instead of) AST fragments.