-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Check future-proofing of macro_rules!
using FIRST sets.
#1746
Conversation
* `NOW(m)` is the set of inputs that are now accepted by a matcher m | ||
* `MAYBE(m)` is defined by: `forall sentence s, matcher m: s ∈ MAYBE(m) <=> s ∉ NOW(m) ⋀ s ∉ NEVER(m)` | ||
|
||
Of course, the problem of deciding wether some input sequence may match some matcher in the future (that is, if, for a given matcher m, wether it belongs to NOW(m), MAYBE(m) or NEVER(m)) is virtually impossible. Instead, we use the concept of *FIRST sets* as an approximation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whether
Thanks for writing all this up and working through the very tricky reasoning! My concerns are:
|
errors will probably be hard to understand and to fix, we will first land it as a warning. We could then periodically use Crater to gather breakage statistics to see how fast people are adapting and decide when to turn it into an error (if we ever do, the other option being to wait for `macro_rules!` to be replaced by | ||
something else). | ||
|
||
An opt-out attribute, `#[unsafe_macro]` will also be added to ignore the future-proofing analysis on a specific macro. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unsafe
sounds wrong for this. How about #[ambiguous_macro]
?
Of course it is. But the only way to make the algorithm cleverer in a signficant way is the thing with FOLLOW sets I describe in the unresolved questions. This requires careful thinking and possibly tweaking the way the macro parser works. If feel that we can't do this right now, but @nikomatsakis is the person to ask about this. What sounds like a good plan to me is landing this as an opt-in lint and add maybe this trick later. This way there won't be any unnecessary breakage. The FIRST sets cannot be adjusted a lot, and it will have very little impact on the number of regressions (and none on the proportion of false positives).
No, it wouldn't. The problem is not that the number is too high, it's that we can't know it for every possible input. Plus, I feel like those would be pretty much niche cases.
Of course, it's the goal of this RFCs. We're not supposed to add anything to the FIRST sets after they are accepted. :) |
What did you mean by "If feel"? "I feel"? :) Presuming you meant "I feel", can you say a bit more about why you feel that way (not saying I disagree). |
ping @LeoTestard @nikomatsakis Status? |
I'm not sure, that's why I said ‶feel″. :D In fact, it was mostly based on the fact that I did not understand 100% how the macro parser works and that it was the end of my internship and I did not have the time to think about all the corner cases that might happen (in particular, I was thinking about sequence-repetitions, for example there might be problems related to rust-lang/rust#33840). I'm sorry about that. Maybe I can now try to find the time on my spare time to think about it in more details, or at least try to sum up the current state of things so that someone else can continue. |
@LeoTestard @pnkfelix What's the status of this RFC? |
So one thing that seems worth mentioning here -- I have been talking to @jseyfried and @nrc in the context of macros 2.0. In that setting, I definitely want to change the meaning of I would like to do the same for existing macro-rules, but I'm not sure of the impact. |
Aha, would that solve the problem I just answered here[1], where if you
match something as :expr and then pass it onto another macro, it can't be
reparsed?
[1]:
https://www.reddit.com/r/rust/comments/5rg5eu/help_on_a_rust_macro/dd7dpta/
…On Wed, Feb 1, 2017 at 4:55 PM, Niko Matsakis ***@***.***> wrote:
So one thing that seems worth mentioning here -- I have been talking to
@jseyfried <https://github.com/jseyfried> and @nrc
<https://github.com/nrc> in the context of macros 2.0. In that setting, I
*definitely* want to change the meaning of $t:expr to just meant "scoop
up all tokens until an expr separator is found" -- it would just let you
copy those tokens somewhere else (anywhere else, really). If you happen to
paste them into a Rust expression context, it will be parsed as an
expression *then*. The macro parser will never run the parser itself, in
other words.
I *would like* to do the same for existing macro-rules, but I'm not sure
of the impact.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#1746 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAC3n1sdwVqBSa-lSk11fXXJhv9w7GJiks5rYP9KgaJpZM4J50dE>
.
|
Yeah, we're planning on fixing this (i.e. allowing reparsing) in macros 2.0, at least in certain contexts. More specifically, we don't want to treat c.f. rust-lang/rust#26361
We'll be able to Crater and find out soon once I land some more proc-macros groundwork :) |
Do we need to specify something like |
I have wondered the same thing. I still think it's useful to have |
@nikomatsakis What about allowing macros to further match on an expression's tokens? Right now you can't "peer into" a Should we always wrap such matches in FWIW I'm fine with having
|
In an expression context, types can only show up after Even |
I don't understand what you're proposing here. Can you elaborate an example? On first glance, it makes me quite nervous. I'm not sure how we would decide, given some stream of tokens like |
Oh, nevermind, fragments are too greedy for |
@aturon @nikomatsakis the status of this RFC, my take (all my opinion, and I'm open to being convinced otherwise): I don't think we're going to be able to reasonably change the semantics of existing if we deploy the checks defined here as an opt-in lint, then it won't pay for the implementation and support effort (because I expect relatively few developers to actually opt into using the lint). what I would primarily aim to do is ensure that the design of macros 2.0 does not fall into the same pitfalls that we hit in From the comments above, it seems like @jseyfried and @nrc are planning to ensure they are future proof by using the approach described by @nikomatsakis , which, if I understand correctly, effectively decouples the meaning of Presumably we should ensure that all fragment specifiers are similarly decoupled from the grammar of the language? |
I think so, with the exception that In any case I believe I agree with your overall conclusions. |
@nikomatsakis I think types in expressions have a similar problem, sadly. |
@rfcbot fcp close Given @pnkfelix's comment, my feeling is that we ought to close this RFC, and instead just try to avoid these mistakes in Macros 2.0. We have already adopted the position (e.g. when we adopted the |
Team member @nikomatsakis has proposed to close this. The next step is review by the rest of the tagged teams: No concerns currently listed. Once these reviewers reach consensus, this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
@eddyb hmm, that's an interesting point. I hadn't considered that. =( I'm not sure if affects the idea that we ought to close this RFC, but it's certainly a thorny complication. |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
The final comment period is now complete. |
The FCP has elapsed with no further commentary. I'm going to go ahead and close. Thanks @LeoTestard for your work here; hopefully we'll be in a better position with macros 2.0. |
No description provided.