-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Change behavior of ?
as a macro separator and Kleene op in 2018 edition
#51934
Comments
Nice work, @mark-i-m. I think we finally have a fully appropriate solution in all cases, at least as I understand it. LTGM! |
I think this is too much hassle over nothing. The one symbol lookup checking for another Kleene op and reducing the breakage from zero to absolute zero also doesn't look like too much complexity or special casing to me. Also, the separator should be allowed on both left-hand and right-hand sides of a macro (this is the first thing I tried to use when trying |
I don't really see a point in making breaking changes like this in the current edition, especially now that we have editions and the next one is right around the corner. |
What would happen for macro definitions across editions? // edition (4033 - A)
macro_rules! define_macro {
($($t:tt)*) => {
macro_rules! use_macro {
($($t)*) => {}
}
}
}
// edition A
define_macro!($(a)?*);
use_macro!(a?a?a); // ???
use_macro!(a*); // ??? |
@kennytm In the current design, if you use |
@mark-i-m but can a 2018 crate use a macro defined in a 2015 crate that uses (going even further down the rabbit hole, there is the possibility of a 2015 crate with a macro that generates a |
Also, it is unclear to me from the summary, but:
Is this describing the new proposed behavior in 2018, or the behavior of an alternative design? It seems desirable to me. |
Sorry, perhaps I misunderstanding. What is the distinction from @kennytm's point? Yes, in 2018 (according to the current plan) if you were to use
Yes, this describes the proposed behavior (implemented in #51587). |
None that I know of, it just sounded to me like you and I interpreted his question differently, especially due to the quote
which is not something a 2018 consumer of a 2015 macro crate can do. |
Yes, that's true. However, I believe the fact that the fix is easy mitigates this a bit, since you can often make a PR to fix the problem, and a PR with this fix ought to be easy to review. Again, I agree that this is not a super great situation, but I expect it to be rare. |
Ignoring the state of the current implementation: I believe the expected behavior for the cross-crate case would be that a macro defined in the 2015 Edition crate would not treat |
Regarding regressions, I'm curious: @petrochenkov asserted that a crater run found zero regressions, but I believe that @mark-i-m cited some regressions to me. Which is correct? |
@rfcbot fcp merge I'm going to propose that we accept this proposal. I feel like using an edition here for backwards compatibility is the right thing to do and it's an easy enough for us to do. The one thing that gives me pause here is that we are effectively losing expressiveness: there is no (convenient, at least) way in Rust 2018 to get the equivalent of At worst, I suppose, you could isolate the macro to Rust 2015 crate that you use as a dependency. =) |
Team member @nikomatsakis has proposed to merge this. The next step is review by the rest of the tagged teams: No concerns currently listed. Once a majority of reviewers approve (and none object), 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. |
Escaping could be the way forwards, if we decide we really need this... |
There's no way to express |
Both. Crater found no regressions, but we still broke clippy. |
So IIUC, the current implementation would not change, but a different edition would be passed to the macros parser? So the macro parser would think it was in edition 2015 even though we are in a 2018 crate? |
@mark-i-m I think the right way to think of it is that one can ask what Edition a given span is in. |
There wouldn't really be a notion of "current edition" for the most part |
As you can see in #51587 the edition-specific logic is much worse than previously implemented fallback. I don't understand what kind of priorities you need to have to end up preferring such edition split and removal of a useful feature to introducing one-symbol lookup logic. |
I was surprised to read this comment. I find this implementation significantly cleaner than what was rolled back. The 2015 logic is similar to what on nightly today, and the 2018 logic very small without the feature gate. This clean 2018 logic is what well be updating in the future, which I consider a benefit.
Not removing; delaying until the edition in a couple of months... |
Mostly a tangent, but I would absolutely love to have a solution to $(...)++ (Which presumably covers this case as well), its pretty commonly needed for me. |
Using |
Hmm... Perhaps we should explore escaping tokens as separators? Will open a thread on internals. |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
I think the current proposal is forward compatible with separator escaping, right? |
@mark-i-m I don't think so, no. Because any future escape char chosen would be recognised as a separator char under the current behaviour (or if |
Hmm... It looks like currently |
Ah, that's better than I thought. |
@mark-i-m BTW, could you kindly expand the bit in the book about lints with the knowledge you picked up from writing this PR? :-) |
Funny you should ask :) |
The final comment period, with a disposition to merge, as per the review above, is now complete. |
@mark-i-m Great. Maybe |
The corresponding PR has been merged, closing this issue. |
@mark-i-m: isn't using the operator in 2015 as a separator supposed to trigger a migration lint? It doesn't seem to at the moment. |
@varkor You're not using it as a separator. You are using it as a Kleene op. And it does actually give the correct error:
If you want the migration lint, you will need to add
|
This is a request for FCP on PR #51587, according to #51587 (comment).
Tracking issue: #48075 (
?
macro repetition)Current behavior:
?
is a macro separator, not a Kleene op.Proposed new behavior (implemented in #51587):
?
is a macro separator, not a kleene op, but using it as a separator triggers a migration lint.?
is not a valid separator.?
is a valid Kleene op.EDIT: To clarify: Under this proposal,
$(a)?+
matches+
anda+
unambiguously.Why we chose this behavior:
Alternatives: The main problem to address is ambiguity. Currently,
?
is a valid separator, so there are a lot of ambiguous possibilities like$(a)?+
. Is the?
a separator for 1 or more iterations OR is it a zero-or-one kleene op followed by a+
token? The solutions fall into 2 categories: make breaking changes or add fallbacks.Fallbacks
macro_at_most_once_rep
):?
kleene op is allowed to take a separator which can never be used (we don't allow trailing separators and?
allows at most one repetition).?
is followed by+
,*
, or?
, we treat the?
as a separator and the second token as a kleene op.?
to take a separator, so the rules would be that?
followed by+
or*
is a separator, but?
followed by?
or any other token would be a?
kleene op followed by the other token.Breaking changes
?
repetition disambiguation. #49719, accidentally merged without FCP, and rolled back).?
as a separator in 2015 edition.?
kleene op from taking a separator.$(a)?+
matches+
anda+
unambiguously. However, it is a breaking change. This was deemed not worthy of a breaking change in the 2015 edition.?
Kleene operator #51587 and is the subject of this FCP.?
as a separator. Currently, you would just get a compile error.?
repetition disambiguation. #49719 (comment)). However, we did found out later that there was apparently some breakage elsewhere (Update?
repetition disambiguation. #49719 (comment)).cc @nikomatsakis
cc @petrochenkov Reviewed the second attempt
cc @durka @alexreg @clarcharr @Centril @kennytm @ExpHP Who participated extensively in the original design discussions (EDIT: apologies if I missed anyone; there were a lot of people who came in at various points)
cc @oli-obk Who brought up clippy breakage
cc @sgrif @pietroalbini Who wanted to see an FCP
Whew... that's a lot of people :)
The text was updated successfully, but these errors were encountered: