-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Stabilize count
, ignore
, index
, and len
(macro_metavar_expr
)
#122808
base: master
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
count
, index
, ignore
and length
in Rust 1.80count
, ignore
, index
, and length
in Rust 1.80
93b1119
to
1536974
Compare
@c410-f3r Has this been documented in the Reference already? The box is not ticked over at the tracking issue. If not, stabilization is blocked on adding sufficient documentation. |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
Team member @joshtriplett has proposed to merge this. The next step is review by the rest of the tagged team members: Concerns:
Once a majority of reviewers approve (and at most 2 approvals are outstanding), 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! cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns. |
AFAIK it is currently equivalent to count($x, 0), which does align with my intuition once I re-familiarized myself with how nested capture groups work. I don't know what infinite depth would even mean.
|
I'm not sure what count(x, 0) would mean, based on this from the RFC:
Reading this over again though, I no longer think it makes sense to limit to 1 by default. I still think specifying a max depth level is non-obvious and of dubious value, since you could always rewrite the excerpt above as something like the following; are there cases where you can't do this?
|
I have linked this already above, see here. That's what I reverse engineered based on my experiments, anyway. The default is definitely 0, according to that PR. Maybe the semantics changed since the RFC was accepted? Would be good to get an up=to-date description of the proposed semantics confirmed by the people involved in the implementation -- Cc @c410-f3r , not sure who else?
I think the issue is around matchers like |
I will try to address all questions this weekend in my free time. |
Thank you.
It is more complex but not impossible IMO. One way is to attach a corresponding matcher depth to each named repetition and then evaluate which ones can be associated based on the current transcriber position. Syntax-wise, the distinction between numbers and strings can create appropriated implementation branches.
Before #117050 rust-lang/reference#1485 (comment) will probably provide a better overview.
Unfortunately it is not possible to count without a metavariable. AFAICT, But yeah, the specification of a depth is non-obvious as it depends on the number of nested matcher repetitions as well as the positioning.
|
I see, I was confused by reading the RFC for more detail, but that is now outdated. @c410-f3r Can you please include a list of differences from the RFC in the stabilization report (with rationale; feel free to summarize and link to more context)? |
Sure. The report has been updated. |
@c410-f3r |
Well, I can rebase but I don't think it will make much of a difference. The actual issue lies within the decision around the use of indices in This PR has been waiting for more than 2 months for a response from the responsible team. AFAICT, all questions posted here as well as in rust-lang/reference#1485 have already been answered to the best of my ability. |
count
, ignore
, index
, and length
(macro_metavar_expr
)count
, ignore
, index
, and len
(macro_metavar_expr
)
close #13 ref: rust-lang/rust#122808
close #13 ref: rust-lang/rust#122808 2508e7c
What's the context? Why was this closed? |
Since the person who closed it is the author, who in September had already been waiting for "more than 2 months", and it's been many months since, and it's even been a month since it was Lang nominated with no update from T-lang, I have to assume the author lost interest in going any further with this. |
I really hope this does not get abandoned. I was tracking this for a while and it would be a great addition. In any case, thank you to the author for all their hard work and patience |
I will take this over (whether as this PR or a new one) if the author is no longer interested. |
Stabilization proposal
This PR proposes the stabilization of a subset of
#![feature(macro_metavar_expr)]
or more specifically, the stabilization ofcount
,ignore
,index
andlen
.Tracking issue: #83527
Version: 1.80 (June 13 2024 => beta, July 25 2024 => stable).
What is stabilized
Count
The number of times a meta variable repeats in total.
The output of
count
depends on where it is placed as well the provided index. If no index is provided, then it will always start at the innermost level.Ignore
Binds a meta variable for repetition, but expands to nothing.
Index
The current index of the inner-most repetition.
index
is a counter that starts from 0 until the end of the repetition.len
The current index starting from the inner-most repetition.
len
indicates the sum of meta variable elements, aka length, of the current repetition.Motivation
Meta variable expressions not only facilitate the use of macros but also allow things that can't be done today like in the
$index
example.An initial effort to stabilize this feature was made in #111908 but ultimately reverted because of possible obstacles related to syntax and expansion.
Nevertheless, #83527 (comment) tried to address some questions and fortunately the lang team accept #117050 the unblocking suggestions.
Here we are today after ~4 months so everything should be mature enough for wider use.
After RFC changes
In order to unblock progress, some changes were applied in #118958. These changes did not trigger any opposition debates and were quickly integrated.
count
changed fromoutermost-to-innermost
toinnermost-to-outermost
.count(some_metavariable)
but now they must be preceded by$
. For example,count($some_metavariable)
.What isn't stabilized
$$
is not being stabilized due to unresolved concerns.History
count
Tests
This list is a subset of https://github.com/rust-lang/rust/tree/master/tests/ui/macros/rfc-3086-metavar-expr.
Ensures that nested macros have correct behavior
Compares produced tokens to assert expected outputs
Checks the declarations of the features
Verifies all possible errors that can occur due to incorrect user input
Possible future work
With enough consensus, other nightly expressions can be added for experimentation and possibly stabilized in the future. For example, #118958.
Thanks @markbt for creating the RFC and thanks to @petrochenkov and @mark-i-m for reviewing the implementations.