-
Notifications
You must be signed in to change notification settings - Fork 13.4k
yarte_lexer 0.0.1 compilation regression #96305
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Oh, I can probably guess what caused the metadata change: |
Aha! I have worked it out. The 7th commit in #95159 unintentionally changed the behaviour of (For anyone wondering how I worked this out: I took the 7th commit from #95159 and combined it with the diff from #95797 using I'm still unsure why the single-file test case above doesn't work, and whether it should. |
PR rust-lang#95159 unintentionally changed the behaviour of declarative macro matching for `NoDelim` delimited sequences. - Before rust-lang#95159, delimiters were implicit in `mbe::Delimited`. When doing macro matching, normal delimiters were generated out of thin air as necessary, but `NoDelim` delimiters were not. This was done within `TokenTree::{get_tt,len}`. - After rust-lang#95159, the delimiters were explicit. There was an unintentional change whereby `NoDelim` delimiters were represented explicitly just like normal delimeters. - rust-lang#95555 introduced a new matcher representation (`MatcherLoc`) and the `NoDelim` delimiters were made explicit within it, just like `mbe::Delimited`. - rust-lang#95797 then changed `mbe::Delimited` back to having implicit delimiters, but because matching is now being done on `MatcherLoc`, the behavioural change persisted. The fix is simple: remove the explicit `NoDelim` delimiters in the `MatcherLoc` representation. This gives back the original behaviour. As for why this took so long to be found: it seems that `NoDelim` sequences are unusual. It took a macro that generates another macro (from the `yarte_lexer` crate, found via a crater run) to uncover this. Fixes rust-lang#96305.
Assigning priority as discussed in the Zulip thread of the Prioritization Working Group. @rustbot label -I-prioritize +P-medium |
Likely because in the single-file case The cross-crate case is "normative" because it's pure token stream. |
@petrochenkov said the following in #96307:
|
After some thought, perhaps we should indeed land #96307 to keep the old behavior at call site, until the definition site diagnostics (#96307 (comment)) are actually implemented and turned into errors. |
This needs an open issue though, so it doesn't get lost. |
Uh oh!
There was an error while loading. Please reload this page.
@lqd pointed out a failure from a recent crater run.
Bisection identifies the 7th commit of #95159 as the problem: "Eliminate TokenTreeOrTokenTreeSlice". Interestingly, #95797 reverted many of the changes from that 7th commit, but the problem persists.
UPDATE: See this comment for the explanation.
I have a reduced test case. It doesn't fit in a single file, instead requiring two crates.
Two-crate test case
Crate
y
,Cargo.toml
:Crate
y
,src/lib.rs
:Crate
z
(which sits next to cratey
in the filesystem),Cargo.toml
:Crate
z
,src/main.rs
:Note: The original code defines
ascii
andascii_builder
within theyarte_lexer
crate and then usesascii
within a unit test. For my reduced test case I used two separate crates because it made it easier to use tools likecargo expand
, and to avoid any issues specific to unit tests.Output
If I compile with
cargo check
using a version prior to #95159, compilation succeeds with this output:If I do the same with a version after #95159, compilation fails with this output:
The obvious difference is the compile error. Interestingly, the expansion of
ascii_builder
in cratey
is the same in both cases. So it's not at all clear why the failure occurs. There's a rule matching'a'
in both cases.Single file attempt
I tried and failed to reproduce this in a single file. Here's what I had:
I just get the same compile error from above, no matter which version of the compiler I use:
I honestly don't know why this single-file version fails but the two-crate version works, and whether that is valid or a bug. It feels like it should compile.
Metadata difference
The only other clue I have is that the metadata has changed slightly. The older (pre-regression) compiler produces this:
The newer (post-regression) compiler produces this:
I don't know of an easy way to compare metadata files, so I don't know what accounts for the slight size difference.
Conclusion
This is a weird one, involving a macro that generates another macro that is then used in another crate. This explains why the change in behaviour took a while to be noticed.
I have looked through the commit responsible, but I can't see any changes related to all of the above.
@petrochenkov, any ideas?
The text was updated successfully, but these errors were encountered: