Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign up[WIP] Macro rules backtracking #33840
Conversation
rust-highfive
assigned
sfackler
May 24, 2016
This comment has been minimized.
This comment has been minimized.
|
r? @sfackler (rust_highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
|
r? @nrc |
rust-highfive
assigned
nrc
and unassigned
sfackler
May 24, 2016
LeoTestard
force-pushed the
LeoTestard:macro-rules-backtracking
branch
from
07a1b18
to
dde0e88
May 24, 2016
This comment has been minimized.
This comment has been minimized.
|
Potential |
This comment has been minimized.
This comment has been minimized.
|
No. The parsing algorithm is the same. There is actually no « backtracking » as you may understand it. The parsing algorithm works on a single arm and, on failure, will try the next arms with the same tokens. This PR only make sure all errors encountered during the parsing for an arm are not fatal but properly reported. There's no change in complexity here. In fact, the parsing algorithm could already be called on every arm if no non-terminal parsing errors occured. |
LeoTestard
force-pushed the
LeoTestard:macro-rules-backtracking
branch
from
dde0e88
to
ce31cb7
May 25, 2016
LeoTestard
added some commits
May 24, 2016
LeoTestard
force-pushed the
LeoTestard:macro-rules-backtracking
branch
2 times, most recently
from
b9eb282
to
0d8dae4
May 31, 2016
LeoTestard
referenced this pull request
Jun 1, 2016
Closed
[wip] reference: rework Macros section #31990
nrc
reviewed
Jun 2, 2016
| match name { | ||
| "tt" => { | ||
| p.quote_depth += 1; //but in theory, non-quoted tts might be useful | ||
| let res: ::parse::PResult<'a, _> = p.parse_token_tree(); | ||
| let res = token::NtTT(P(panictry!(res))); | ||
| let res = token::NtTT(P(try!(res))); |
This comment has been minimized.
This comment has been minimized.
nrc
reviewed
Jun 2, 2016
| pub fn span(&self) -> &MultiSpan { | ||
| &self.span | ||
| } | ||
|
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
LeoTestard
Jun 2, 2016
•
Author
Contributor
Because it's private I guess. We still can make it pub...
I chosed to add a method for consistency with message below.
This comment has been minimized.
This comment has been minimized.
nrc
Jun 7, 2016
Member
I think a pub field would be nicer (more idiomatic Rust), could change message too I guess
LeoTestard
force-pushed the
LeoTestard:macro-rules-backtracking
branch
from
0d8dae4
to
be53b20
Jun 2, 2016
LeoTestard
referenced this pull request
Jun 2, 2016
Merged
Add a `literal` fragment specifier to `macro_rules!`. #1576
This comment has been minimized.
This comment has been minimized.
LeoTestard
force-pushed the
LeoTestard:macro-rules-backtracking
branch
from
67c1790
to
13a8c8d
Jun 8, 2016
This comment has been minimized.
This comment has been minimized.
|
lgtm with a cursory read over the code, but r? @pnkfelix for a detailed review |
rust-highfive
assigned
pnkfelix
and unassigned
nrc
Jun 8, 2016
LeoTestard
reviewed
Jun 9, 2016
| let nt = match parse_nt(&mut rust_parser, span, | ||
| &ident.name.as_str()) { | ||
| Ok(nt) => Rc::new(MatchedNonterminal(nt)), | ||
| Err(diag) => return Failure(diag) |
This comment has been minimized.
This comment has been minimized.
LeoTestard
Jun 9, 2016
Author
Contributor
Note to myself: we must not fail here, but rather just remove the current parsing item from the stack.
This comment has been minimized.
This comment has been minimized.
|
Note for myself and for others: Allright we have a problem here. As I noted in the comment above, we currently only backtrack from an arm, not from a parsing item. That means that if you have a macro like this: macro_rules! foo(
( $( $e:expr ),* some_other_tokens ) => ...
)If we provide it input that doesn't match This sounds easy to fix: just remove the current parsing item from the stack. macro_rules! foo(
( $( $e:expr , )* $( $i:ident : $t:ty , )* ) => ...
)Before type ascription syntax, This was not a problem before because failure to match a NT (such as This problem is in fact the very same as the one with multiple-arm macros: macro_rules! foo(
$( $e:expr ) => ... ;
$( $i:ident : $t:ty ) => ...
)So I believe that my analysis for multiple-arm macros could be applied to fix the issue with the current future-proofing analysis for single-arm macros. But until we sorted that out, we have two solutions for this PR:
(By fixing this issue, I mean: making sure the parser backtracks out of a sequence repetition.) |
LeoTestard
force-pushed the
LeoTestard:macro-rules-backtracking
branch
from
13a8c8d
to
24b9e39
Jun 9, 2016
This comment has been minimized.
This comment has been minimized.
|
@LeoTestard as we said in person, this is indeed a drag, though I guess it just ups the priority of investigating the other future-proofing problem. :( |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
ping, @LeoTestard looks like this needs a rebase? |
This comment has been minimized.
This comment has been minimized.
|
@alexcrichton Yes indeed, but it's blocked anyway until we have a fix for the future-proofing issue. I don't know what we should do with this PR. Maybe we can just close it and reopen it later? |
This comment has been minimized.
This comment has been minimized.
|
Ah either way is fine by me, this is now active in the last 5 hours rather than 21 days, so I'm happy at least :) |
durka
referenced this pull request
Aug 13, 2016
Closed
Fragment specifiers in macro are not taken into account #35650
alexcrichton
referenced this pull request
Oct 31, 2016
Closed
[WIP] Check future proofing of macros with multiple arms using FIRST sets. #34140
This comment has been minimized.
This comment has been minimized.
|
This is quite stalled. @pnkfelix @LeoTestard is there any chance of this PR landing? Should we close? |
LeoTestard
referenced this pull request
Dec 21, 2016
Closed
Check future-proofing of `macro_rules!` using FIRST sets. #1746
This comment has been minimized.
This comment has been minimized.
|
@brson Yes, there is still a chance. I thought again about this problem after I found the problem I mentioned above, and I no longer think it's a problem. It turns out that I did not understood how the parser handled ambiguity at the time. I should be able to sum up the situation in more detail. |
This comment has been minimized.
This comment has been minimized.
Any chance of this happening? I am tempted to just close this PR until you or someone else is ready to move forward here; this is going to be extremely out of date, right? |
This comment has been minimized.
This comment has been minimized.
|
Seems reasonable to close the PR in the meantime, though @LeoTestard I'd like to hear more about what you have in mind. |
pnkfelix
closed this
Jan 4, 2017
pnkfelix
added
A-macros
T-compiler
labels
Jan 4, 2017
This comment has been minimized.
This comment has been minimized.
|
@steveklabnik The code is probably quite out of date indeed, I agree that the PR can be closed in the meantime. @nikomatsakis Sure. I promise I'll take the time to write about it at some point, but I'm quite busy these days. |
LeoTestard commentedMay 24, 2016
This fixes
macro_rules!to implement the wanted backtracking semantics: if an arm fails to match, the next arm is tried, and so on.This was previously not the case because of hard errors emitted during parsing of non-terminals. Now that the parser code has been fixed not to panic but to return a
DiagnosticBuilderin case of error, it's easy to catch those errors and signal that the arm failed to match.This PR probably contains a bit of hackery, so it's flagged as WIP so that people can review it.