Simplify TokenTree and fix macro_rules! bugs#39419
Conversation
src/libsyntax/ext/tt/quoted.rs
Outdated
There was a problem hiding this comment.
Can't this be done on the fly? (i.e in parsing not lexing)
There was a problem hiding this comment.
Neither parsing nor lexing knows about sequences and matchers at all. We lex directly into a Vec<TokenTree> and consume the token trees in the parser directly (e.g. parsing a token tree is constant time). Sequences and matchers are parsed by ext::tt::quoted::parse.
ca90c32 to
04b8382
Compare
nrc
left a comment
There was a problem hiding this comment.
I only got halfway through reviewing this PR before the (long) weekend, and then my browser crashed and lost my comments. There wasn't anything major. Anyway, here is a single comment and I'll finish the review on Tuesday. Sorry for the delay.
src/libsyntax/ext/tt/transcribe.rs
Outdated
src/libsyntax/ext/tt/transcribe.rs
Outdated
There was a problem hiding this comment.
I would factor this out into a ctor function
src/libsyntax/ext/tt/transcribe.rs
Outdated
src/libsyntax/ext/tt/quoted.rs
Outdated
There was a problem hiding this comment.
Why make this module here? I'd have thought TTs were much more general than just quasi quoting
There was a problem hiding this comment.
We still have tokenstream::{TokenStream, TokenTree, ...}.
quoted::TokenTree is more general than tokenstream::TokenTree since it also supports "$-quoted tokens" from the macro_rules! syntax -- $e, $e:expr, and $(...)*. In other words, quoted::TokenTree is the parse tree for macro_rules! syntax.
|
Oh, GH didn't lose my earlier comments. Good. |
nrc
left a comment
There was a problem hiding this comment.
Just one more comment, and that can be done later
src/libsyntax/ext/tt/quoted.rs
Outdated
There was a problem hiding this comment.
I think Match is a pretty bad name - it is not actually a match of a pattern to text (or anything to do with a match expression). Maybe PatternVariable or MacroVariable is better? Doesn't have to be done in this PR though.
There was a problem hiding this comment.
With a bit more refactoring I could also move Nonterminal::SubstNt here -- I think MacroVariable would be a better fit for that. MacroVariableDeclaration is too long though (imo); how about MetaVarDecl?
|
☔ The latest upstream changes (presumably #39712) made this pull request unmergeable. Please resolve the merge conflicts. |
a4e7704 to
ea1f84c
Compare
|
☔ The latest upstream changes (presumably #39572) made this pull request unmergeable. Please resolve the merge conflicts. |
67be452 to
88716e7
Compare
|
@eddyb would you mind Cratering this? |
|
☔ The latest upstream changes (presumably #39752) made this pull request unmergeable. Please resolve the merge conflicts. |
|
@jseyfried Can you ping me after a rebase? |
88716e7 to
f46907c
Compare
|
@eddyb rebased. |
|
The crater report shows 4 main regressions:
These all look like macro-defining macros, and they seem like they should work, but something is perhaps doing too-eager parsing? I've never liked |
|
It looks like all these errors are due to fixing #39404. That is, they are legitimate errors in the macro definition that didn't show up before because the erroneous pattern never ended up getting used to match anything. I'll start a warning cycle.
Agreed, that's one of the reasons for this PR. After this PR, |
|
EDIT: No, you're right 😞 |
|
Okay, this might not be that bad. |
b6e60f9 to
839398a
Compare
|
@bors r=nrc |
|
📌 Commit 839398a has been approved by |
|
⌛ Testing commit 839398a with merge d35bcfa... |
|
💔 Test failed - status-appveyor |
|
@bors: retry
* network error
…On Tue, Feb 28, 2017 at 4:21 PM, bors ***@***.***> wrote:
💔 Test failed - status-appveyor
<https://ci.appveyor.com/project/rust-lang/rust/build/1.0.2168>
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#39419 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAD95GB7SjuZ5IPQajxpJNAzk0PKgfWqks5rhJ3sgaJpZM4LySVU>
.
|
Simplify `TokenTree` and fix `macro_rules!` bugs This PR - fixes rust-lang#39390, fixes rust-lang#39403, and fixes rust-lang#39404 (each is a [breaking-change], see issues for examples), - fixes rust-lang#39889, - simplifies and optimizes macro invocation parsing, - cleans up `ext::tt::transcribe`, - removes `tokenstream::TokenTree::Sequence` and `Token::MatchNt`, - instead, adds a new type `ext::tt::quoted::TokenTree` for use by `macro_rules!` (`ext::tt`) - removes `parser.quote_depth` and `parser.parsing_token_tree`, and - removes `quote_matcher!`. - Instead, use `quote_tokens!` and `ext::tt::quoted::parse` the result with `expect_matchers=true`. - I found no outside uses of `quote_matcher!` when searching Rust code on Github. r? @nrc
Simplify `TokenTree` and fix `macro_rules!` bugs This PR - fixes #39390, fixes #39403, and fixes #39404 (each is a [breaking-change], see issues for examples), - fixes #39889, - simplifies and optimizes macro invocation parsing, - cleans up `ext::tt::transcribe`, - removes `tokenstream::TokenTree::Sequence` and `Token::MatchNt`, - instead, adds a new type `ext::tt::quoted::TokenTree` for use by `macro_rules!` (`ext::tt`) - removes `parser.quote_depth` and `parser.parsing_token_tree`, and - removes `quote_matcher!`. - Instead, use `quote_tokens!` and `ext::tt::quoted::parse` the result with `expect_matchers=true`. - I found no outside uses of `quote_matcher!` when searching Rust code on Github. r? @nrc
|
☀️ Test successful - status-appveyor, status-travis |
Updated AST as per <rust-lang/rust#39419>, thereby closing #19. Since those changes involved removing MathcNt and SubstNt, I've removed the unsafe parts of Quote that relied on that. Quote is now a safe module (where '$x' and '$x:ty' don't work), enabled by default. Difference tests now work on 'ast.rs' as well as 'parser.rs'. Additional work was done on cleaning up tests around macros and tokens. Closes #16.
This PR
ttfragments treat$(foo)*likefoo#39390, fixes macros: simplifyttmatchers #39403, and fixes macros: syntax errors in matches should fail on definition, not use #39404 (each is a [breaking-change], see issues for examples),ext::tt::transcribe,tokenstream::TokenTree::SequenceandToken::MatchNt,ext::tt::quoted::TokenTreefor use bymacro_rules!(ext::tt)parser.quote_depthandparser.parsing_token_tree, andquote_matcher!.quote_tokens!andext::tt::quoted::parsethe result withexpect_matchers=true.quote_matcher!when searching Rust code on Github.r? @nrc