-
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
Amend RFC 550 with (expanded) abstract specification rather than algorithm #1384
Amend RFC 550 with (expanded) abstract specification rather than algorithm #1384
Conversation
As noted in the Edit History addition: * replaced detailed design with a specification-oriented presentation rather than an implementation-oriented algorithm. * fixed some oversights in the specification (that led to matchers like `break { stuff }` being accepted), * expanded the follows sets for `ty` to include `OpenDelim(Brace), Ident(where), Or` (since Rust's grammar already requires all of `|foo:TY| {}`, `fn foo() -> TY {}` and `fn foo() -> TY where {}` to work). * expanded the follow set for `pat` to include `Or` (since Rust's grammar already requires `match (true,false) { PAT | PAT => {} }` and `|PAT| {}` to work). See also [RFC issue 1336][]. Not noted in Edit History addition: * expanded/revised terminology section to fit new detailed design * added "examples of valid and invalid matchers" subsection, that uses the specification from detailed design to explain why each is valid/invalid. * rewrote the algorithm to actually implement the (new) specification, and moved the discussion of the algorithm to a non-binding appendix.
I forgot to mention it in amendment as currently written, but: This change is strongly motivated by rust-lang/rust#25658 (that is, this change, along with an implementation I am prototyping, is meant to fix that issue). One thing I have not addressed at all here is whether the change described here would go through warning cycle. I am not sure whether I can easily do that (though in principle I guess I could just run both analyses, and set the new one to warn for the initial release cycle). |
cc @cmr @rust-lang/lang |
One thing that we may want, in order to land this in practice, is a fragment specifier for the subclass of expressions that corresponds to expressions that can be used as a test in an The reason that we may want such a fragment specifier is because a crater run with my prototype signaled that some crates in the wild are relying on the ability to put Adding a new fragment specifier that those crates could use instead of
|
This is excellent work @pnkfelix. |
I found a typo, but I can't find it again... |
``` | ||
|
||
Examples of FOLLOW (expressed as equality relations between sets, to avoid | ||
incoporating details of FOLLOW(NT) in these examples): |
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.
Here it is! s/inco/incor/
So hopefully I'll have a chance soon to incorporate this properly into the RFC, but two new things:
|
Did a new crater run (the previous one was bad because I was comparing against an old baseline, and so the set of crates had changed in the meantime). Very promising results. Summary:
As a fun aside, the prototype does fix one crate (though I suspect its not a terribly vital one): https://github.com/arthurtw/echo-rs/blob/master/src/lib.rs#L37 |
|
||
The current legal fragment specifiers are: `item`, `block`, `stmt`, `pat`, | ||
`expr`, `ty`, `ident`, `path`, `meta`, and `tt`. | ||
|
||
- `FOLLOW(pat)` = `{FatArrow, Comma, Eq}` | ||
- `FOLLOW(pat)` = `{FatArrow, Comma, Eq, Or, Ident(if), Ident(in)}` |
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.
It's not obvious to me if we want to add |
here, #1336 (comment) .
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.
so how would that work in the presence of closures, i.e. let f = |VariantA(x, _)|VariantB(_, x)| { ... };
? Seems hard to parse to me.
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.
(though I guess we would just not allow the generalized pattern form in that context?)
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.
((which is guess is basically what you said in the comment you linked...))
Hear ye, hear ye! This RFC amendment is now entering final comment period. |
For those like me coming from the subteams report and lacking context: RFC 550 is Macro future-proofing. |
@nikomatsakis @huonw so, what do you two think: Should I take My personal inclination is to add |
@pnkfelix I say add it |
lang team discussed, and decided RFC amendment is good as-is (i.e., it is okay that it is adding |
Amend RFC 550 with (expanded) abstract specification rather than algorithm
and also durka42 on irc asked about the |
…s validity. See RFC amendment 1384 and tracking issue 30450: rust-lang/rfcs#1384 rust-lang#30450 Moved old check_matcher code into check_matcher_old combined the two checks to enable a warning cycle (where we will continue to error if the two checks agree to reject, accept if the new check says accept, and warn if the old check accepts but the new check rejects).
See RFC amendment 1384: rust-lang/rfcs#1384
This is making invalid a macro that I’ve been using for about a year, and I don’t know how to fix it. I’d appreciate some help: https://users.rust-lang.org/t/macro-rules-used-like-a-match-expression/4328 |
I replied in the Discourse thread. It's not pretty :) On Mon, Jan 18, 2016 at 12:50 PM, Simon Sapin [email protected]
|
Change the usage syntax to require a comma on the last non-fallback arm, which is a [breaking-change]. The old definition has started to emit a warning in recent nightlies and is likely to be an error in future versions: rust-lang/rfcs#1384 The new definition is recursive to resolve ambiguities. Unfortunately this makes error reporting terrible: rust-lang/rust#31022
Make match_ignore_ascii_case! future-proof. Change the usage syntax to require a comma on the last non-fallback arm, which is a [breaking-change]. The old definition has started to emit a warning in recent nightlies and is likely to be an error in future versions: rust-lang/rfcs#1384 The new definition is recursive to resolve ambiguities. Unfortunately this makes error reporting terrible: rust-lang/rust#31022 <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/rust-cssparser/91) <!-- Reviewable:end -->
(tracking issue: rust-lang/rust#30450)
Massive redo of Detailed Design of RFC #550; expanded parts of spec in passing.
As noted in the Edit History addition:
$e:expr { stuff }
being accepted (which match fragments likebreak { stuff }
, significantly limiting future language extensions),ty
to includeOpenDelim(Brace), Ident(where), Or
(since Rust's grammar already requires all of|foo:TY| {}
,fn foo() -> TY {}
andfn foo() -> TY where {}
to work).pat
to includeOr
(since Rust's grammar already requiresmatch (true,false) { PAT | PAT => {} }
and|PAT| {}
to work). See also RFC issue Allowpat
macro matcher be followed by|
#1336.Not noted in Edit History addition:
specification from detailed design to explain why each is valid/invalid.
moved the discussion of the algorithm to a non-binding appendix.
diff of amendment (split view)