-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Merge proc_macro_
expansion feature gates as proc_macro_hygiene
#52121
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Hm I'd personally prefer to leave these as smaller feature gates in the sense that we started as one large |
@alexcrichton Continuing down this path makes both developing and using crates with proc-macros (with their full abilities) very painful. For instance, once Rocket migrates to using proc-macros universally, users will need to enable at least four of these features to use Rocket at all. This is, in fact, the impetus for this PR. Accepting this PR has no implications on whether everything has to be stabilized at once or not. All of the existing features will continue to exist, and you can continue to subset features into different gates. Crates asking users to enable 'macros_2' can stop doing so as soon as the subset of features the crate requires are stable. I see no downsides to this PR, aside from needing to maintain the feature flag, but I do a see a strong win in terms of usability for both end-users and developers. |
@SergioBenitez I agree from an author's point of view that it's much easier to just write In any case though @nikomatsakis is listed for review here, and mine isn't the only opinion! |
My concern with making the granularity of opt-in "by unit of stabilization" is that those units keep changing. For example, last time I tried it locally, #52081 broke |
@jebrosen that breakage (and recent breakage) has been from splitting up the |
☔ The latest upstream changes (presumably #52081) made this pull request unmergeable. Please resolve the merge conflicts. |
Heh, not any more! 😛 |
Writing By the way, can someone explain what all of those features do? None of them have explanations in the unstable book, and all six of the proc_macro ones point to the same tracking issue. |
Yes I'm not saying that this PR is equivalent to I think one of the problems is actually pointed out by @mikeyhew in that naively we should have a feature per "user facing feature" but these are all very different user facing features:
My point is that almost all of these are entirely separate APIs and actually entirely separate user-facing features. A small handful can be merged but I don't think it's useful to lump these all into one feature. It's basically an impossibility for these to all be stabilized at once. |
I looked more closely at the individual gates and have some more thoughts on this. It ended up being a bit of a brain dump instead of any particular argument, so bear with me. For a macro crate author: For someone using a proc_macro crate, things are a lot muddier. According to my understanding of the errors defined in libsyntax/ext/expand.rs and what activates them:
Whether these gates are necessary or not is always (usually?) determined by the macro, but the consumer has to enable the features that support the macros they happen to use. For example, if Rocket's macros were all reimplemented today to perform exactly as the current plugin-based ones, I believe most application crates would need Side note: if |
I think that all makes sense to me @jebrosen! One possibility that may imply to me is that we could have fine-grained gates for definitions of procedural macros but not for the invocation of procedural macros. That should help improve the user experience I believe? |
I think I have to take back what I said about macros implying the gates they need, at least in general. On the other hand, Rocket's current collection of macros are all targeted at specific use cases: expanding to a From a "wants" perspective, it might be nice for macro authors to be able to opt-in to allow |
That sounds great to me. |
@jebrosen it's true yeah that a macro's definition doesn't always imply where it's going to be expanded, but as you've found I think it's safe to assume that most macros have a specific context they're expected to expand to, so I think a lot of macros could benefit from the strategy of "the macro is tagged with features it can expand to" |
@alexcrichton Do I understand correctly that you would be amenable to merging a PR that:
|
@SergioBenitez correct yeah! Something like that I think would reasonably inform users about the dangers of using all these features while hopefully not being too cumbersome as well |
I'm trying another formulation of this:
Note that this proposal does not even touch on "tagging" macros with whitelisted expansion types, which I think is a better ideal solution but is also unreasonably complex to implement in the compiler. Under this proposal, Rocket application crates would need to enable @SergioBenitez how do you feel about leaving decl_macro out for these reasons? |
After #53459 lands, it'll probably no longer worth it introducing an umbrella feature on the consumer side. |
As far as I can tell, #53459 doesn't address any of the features imposed on consumer crates by the macro author, which is what this feature request has become. Only |
src/libsyntax/feature_gate.rs
Outdated
(active, proc_macro_expr, "1.27.0", Some(38356), None), | ||
(active, proc_macro_non_items, "1.27.0", Some(38356), None), | ||
(active, proc_macro_gen, "1.27.0", Some(38356), None), | ||
(active, proc_macro_hygiene, "1.27.0", Some(38356), None), |
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.
Could you move the features into the "removed" list instead of just removing, and also add "subsumed by proc_macro_hygiene
" as the removal reason?
💔 Test failed - status-travis |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
proc_macro_
expansion feature gates as proc_macro_hygiene
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
@petrochenkov Looks like we're good. |
☔ The latest upstream changes (presumably #54767) made this pull request unmergeable. Please resolve the merge conflicts. |
…acro_hygiene` gate.
@bors r+ |
📌 Commit d3c902f has been approved by |
Merge `proc_macro_` expansion feature gates as `proc_macro_hygiene` Merges `proc_macro_mod`, `proc_macro_expr`, `proc_macro_non_items`, and `proc_macro_gen` into a single feature: `proc_macro_hygiene`. These features are not all blocked on implementing macro hygiene *per se*, but rather on interactions with hygiene that have not been entirely resolved.
☀️ Test successful - status-appveyor, status-travis |
📣 Toolstate changed by #52121! Tested on commit 766e21c. 💔 clippy-driver on windows: test-pass → test-fail (cc @Manishearth @llogiq @mcarton @oli-obk, @rust-lang/infra). |
Tested on commit rust-lang/rust@766e21c. Direct link to PR: <rust-lang/rust#52121> 💔 clippy-driver on windows: test-pass → test-fail (cc @Manishearth @llogiq @mcarton @oli-obk, @rust-lang/infra). 💔 clippy-driver on linux: test-pass → test-fail (cc @Manishearth @llogiq @mcarton @oli-obk, @rust-lang/infra).
Merges
proc_macro_mod
,proc_macro_expr
,proc_macro_non_items
, andproc_macro_gen
into a single feature:proc_macro_hygiene
. These features are not all blocked on implementing macro hygiene per se, but rather on interactions with hygiene that have not been entirely resolved.