-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Fix DebugParser
.
#127273
Fix DebugParser
.
#127273
Conversation
hmm, I'm quite certain I did test the same code I committed, but it was inside a macro expansion, so it might have been an unusual case... (and lately the specific tokenization of macros may be subtly changing in a way only visible to this, judging by recent commits). |
I'm not aware of any cases where |
@workingjubilee I'm using
With the new code, I get this:
A big difference in usefulness! |
I was using it on code generated from |
If I recall correctly, what lead to the somewhat awkward formation here is that there were multiple Eof tokens in a row, which I did not understand but also did not try to understand. Insofar as an "objection", I would prefer to conduct a modest amount of investigation into why the current state of affairs is, er, the current state of affairs, and then r+ this, because "basic" is relative and I wouldn't want to make this useless on what I was doing. But it requires retracing my steps, and from about Thursday to now I was completely exhausted and overheated so I did not get much serious thought done. If you can find out why, based on the scant description, I made the mistake I did (if it was a mistake?), then I am happy to accept something plausible, otherwise I will try to get to it shortly. |
You can get multiple Eofs if you look past the end of the tokenstream. Something weird would have to be happening. |
I see. I suppose we are filing "macro expansion" under "something weird"? |
I don't know how you were using it. I do know that the existing code doesn't work for my simple use case, and the new code does. If I wrote a test or two would that help? |
Yes, please. I really should have committed some, but I didn't expect this to be this complicated, and it seemed contra the "debug use only" thing... 😅 |
Using `#[track_caller]` works if the assertion is moved outside of the closure.
That method is currently badly broken, and the test output reflects this. The obtained tokens list is always empty, except in the case where we go two `bump`s past the final token, whereupon it will produce as many `Eof` tokens as asked for.
It currently doesn't work at all. This commit changes it to a simpler imperative style that produces a valid `tokens` vec. (An aside: I find `Iterator::scan` to be a pretty wretched function, that produces code which is very hard to understand. Probably why this is just one of two uses of it in the entire compiler.)
402c7c2
to
aa0e8e1
Compare
New code is up, with tests showing before and after behaviour. |
Thanks! I think I got direly confused at some point by hitting some of the "quirks" in the special case of before, and that plus inexperience with the parser (or indeed reasoning about tokenstreams) resulted in the current state of things. @bors r+ |
@bors rollup |
…iaskrgr Rollup of 5 pull requests Successful merges: - rust-lang#127273 (Fix `DebugParser`.) - rust-lang#127587 (Report usage of lib features in ast validation) - rust-lang#127592 (doc: Suggest `str::repeat` over `iter::repeat().take().collect()`) - rust-lang#127630 (Remove lang feature for type ascription (since it's a lib feature now)) - rust-lang#127711 (Add regression test for a gce + effects ICE) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#127273 - nnethercote:fix-DebugParser, r=workingjubilee Fix `DebugParser`. I tried using this and it didn't work at all. `prev_token` is never eof, so the accumulator is always false, which means the `then_some` always returns `None`, which means `scan` always returns `None`, and `tokens` always ends up an empty vec. I'm not sure how this code was supposed to work. (An aside: I find `Iterator::scan` to be a pretty wretched function, that produces code which is very hard to understand. Probably why this is just one of two uses of it in the entire compiler.) This commit changes it to a simpler imperative style that produces a valid `tokens` vec. r? `@workingjubilee`
I tried using this and it didn't work at all.
prev_token
is never eof, so the accumulator is always false, which means thethen_some
always returnsNone
, which meansscan
always returnsNone
, andtokens
always ends up an empty vec. I'm not sure how this code was supposed to work.(An aside: I find
Iterator::scan
to be a pretty wretched function, that produces code which is very hard to understand. Probably why this is just one of two uses of it in the entire compiler.)This commit changes it to a simpler imperative style that produces a valid
tokens
vec.r? @workingjubilee