Skip to content
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

rustc: Stabilize the `proc_macro` feature #52081

Merged
merged 1 commit into from Jul 16, 2018

Conversation

@alexcrichton
Copy link
Member

alexcrichton commented Jul 5, 2018

This commit stabilizes some of the proc_macro language feature as well as a
number of APIs in the proc_macro crate as previously discussed. This
means that on stable Rust you can now define custom procedural macros which
operate as attributes attached to items or macro_rules!-like bang-style
invocations. This extends the suite of currently stable procedural macros,
custom derives, with custom attributes and custom bang macros.

Note though that despite the stabilization in this commit procedural macros are
still not usable on stable Rust. To stabilize that we'll need to stabilize at
least part of the use_extern_macros feature. Currently you can define a
procedural macro attribute but you can't import it to call it!

A summary of the changes made in this PR (as well as the various consequences)
is:

  • The proc_macro language and library features are now stable.
  • Other APIs not stabilized in the proc_macro crate are now named under a
    different feature, such as proc_macro_diagnostic or proc_macro_span.
  • A few checks in resolution for proc_macro being enabled have switched over
    to use_extern_macros being enabled. This means that code using
    #![feature(proc_macro)] today will likely need to move to
    #![feature(use_extern_macros)].

It's intended that this PR, once landed, will be followed up with an attempt to
stabilize a small slice of use_extern_macros just for procedural macros to
make this feature 100% usable on stable.

@rust-highfive

This comment has been minimized.

Copy link
Collaborator

rust-highfive commented Jul 5, 2018

r? @aturon

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive

This comment has been minimized.

Copy link
Collaborator

rust-highfive commented Jul 5, 2018

warning Warning warning

  • These commits modify submodules.
@alexcrichton

This comment has been minimized.

Copy link
Member Author

alexcrichton commented Jul 5, 2018

@rust-highfive rust-highfive assigned nikomatsakis and unassigned aturon Jul 5, 2018

@alexcrichton alexcrichton referenced this pull request Jul 5, 2018

Closed

Tracking issue for RFC 1566: Procedural macros #38356

24 of 31 tasks complete

@petrochenkov petrochenkov self-assigned this Jul 5, 2018

@@ -13,7 +13,7 @@ use Span;
use rustc_errors as rustc;

/// An enum representing a diagnostic level.
#[unstable(feature = "proc_macro", issue = "38356")]
#[unstable(feature = "proc_macro_diagnostic", issue = "38356")]

This comment has been minimized.

@petrochenkov

petrochenkov Jul 5, 2018

Contributor

What's the point in renaming unstable library features?
This is only breaking all the code using them.

This comment has been minimized.

@alexcrichton

alexcrichton Jul 5, 2018

Author Member

The proc_macro feature at this point has been used-and-abused I think a bit too much. This PR is, afaik, the main thrust of proc_macro for stabilization. The renamings here aren't intended to purely break everyone else's code, but rather clearly singify different groupings of features instead of leaving them all in a perpetual singular proc_macro bucket

@@ -93,13 +93,13 @@ impl !Sync for LexError {}

impl TokenStream {
/// Returns an empty `TokenStream` containing no token trees.
#[unstable(feature = "proc_macro", issue = "38356")]
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]

This comment has been minimized.

@petrochenkov

petrochenkov Jul 5, 2018

Contributor

Are you going to use proc_macro_lib3/4/5/... for the next portions of stabilized APIs? :)
I used proc_macro_12 in my PR (#50473 (comment)), because it's Macros 1.2.
(OK, it doesn't matter anyway.)

This comment has been minimized.

@alexcrichton

alexcrichton Jul 5, 2018

Author Member

As I'm sure you know, the stable feature name doesn't actually matter. I initially changed these while the other unstable features were still proc_macro and then ended up later changing the other proc_macro features to different names. As a result this stuck. It's an arbitrary name.

@petrochenkov

This comment has been minimized.

Copy link
Contributor

petrochenkov commented Jul 5, 2018

The custom_attribute feature no longer works as unknown attibutes are looked up as macros.

Oh man, this is going to be painful.

@petrochenkov

This comment has been minimized.

Copy link
Contributor

petrochenkov commented Jul 5, 2018

I don't see much use in landing this PR before stabilizing use_extern_macros and completing #51952, but it's good to have a PR open for some publicity.

I plan to fix tool attributes in the next few weeks, so poor users of #[rustfmt_skip] could migrate to #[rustfmt::skip] if custom attributes are not fixed either.

I think custom attributes could be restored in some form as well, e.g. if some attribute is "definitely unresolved" as a macro, then it can be kept in the source as a custom attribute (still under a feature gate) instead of producing a dummy expansion, like it's done now.

@alexcrichton

This comment has been minimized.

Copy link
Member Author

alexcrichton commented Jul 5, 2018

While true that this PR isn't too useful landing by itself it does need to land eventually for proc-macro stabilization, and this was larger and more thorny than I thought it would be so I wanted to put it up for review and get it in soon to iron out all the CI issues.

@SimonSapin

This comment has been minimized.

Copy link
Contributor

SimonSapin commented Jul 6, 2018

The custom_attribute feature no longer works as unknown attibutes are looked up as macros.

Oh man, this is going to be painful.

Does this also break rustc_plugin::Registry::register_attribute in #[plugin_registrar]? Servo still has a lint plugin with (unfortunately) no clear upgrade path.

@eddyb

This comment has been minimized.

Copy link
Member

eddyb commented Jul 6, 2018

FWIW, I have mentioned before that if the unrooted_must_root_lint analysis is "close enough" to being sound, it should naturally be replaceable with a trait-based system that's partially implemented inside the compiler itself, with most of the logic being in impls/derives in Servo crates.

@SimonSapin

This comment has been minimized.

Copy link
Contributor

SimonSapin commented Jul 6, 2018

@eddyb Yes, it might be "just" a matter of someone familiar enough with what the lint does and the soundness of GC rooting to come up with a new design and implementing it. In the meantime, a lint is what we have.

@alexcrichton

This comment has been minimized.

Copy link
Member Author

alexcrichton commented Jul 6, 2018

@SimonSapin yes it'd break that because those attributes aren't hooked into the normal resolver. You can rename them with a rustc_ prefix, though, and it should continue working. All attributes with a rustc_ prefix are gated and skip the resolver.

@alexcrichton

This comment has been minimized.

Copy link
Member Author

alexcrichton commented Jul 9, 2018

I think @nikomatsakis is out this week, so...

r? @nrc

@rust-highfive rust-highfive assigned nrc and unassigned nikomatsakis and petrochenkov Jul 9, 2018

@alercah

This comment has been minimized.

Copy link
Contributor

alercah commented Jul 10, 2018

I have a major reservation about stabilizing that I brought up in the tracking issue.

@petrochenkov

This comment has been minimized.

Copy link
Contributor

petrochenkov commented Jul 10, 2018

@alexcrichton
The attribute resolution changes (tool attributes, custom attributes) are really a part of the macro modularization feature (#35896), gating them on proc_macro was a mistake.

I think we can land the proc macro library API part right now (it adds nothing fundamentally new compared to TokenStream::parse) and the part of language proc_macro feature that allows to define #[proc_macro] and #[proc_macro_attribute] items, but not use them.
Everything else should be effectively moved under the use_extern_macros gate and has some blocker issues to fix before stabilization.

Could you leave this stabilization work to me?
I have more time now than in the previous ~year and have a plan with regards to what needs to be done and in what order.

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Jul 16, 2018

⌛️ Testing commit 65f3007 with merge 2750fc6...

@bors bors referenced this pull request Jul 16, 2018

Merged

Rollup of 9 pull requests #52433

@kennytm

This comment has been minimized.

Copy link
Member

kennytm commented Jul 16, 2018

@bors retry

GitHub outage causing the CIs not seeing the auto branch got updated.

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Jul 16, 2018

⌛️ Testing commit 65f3007 with merge 1ecf692...

bors added a commit that referenced this pull request Jul 16, 2018

Auto merge of #52081 - alexcrichton:proc-macro-stable, r=petrochenkov
rustc: Stabilize the `proc_macro` feature

This commit stabilizes some of the `proc_macro` language feature as well as a
number of APIs in the `proc_macro` crate as [previously discussed][1]. This
means that on stable Rust you can now define custom procedural macros which
operate as attributes attached to items or `macro_rules!`-like bang-style
invocations. This extends the suite of currently stable procedural macros,
custom derives, with custom attributes and custom bang macros.

Note though that despite the stabilization in this commit procedural macros are
still not usable on stable Rust. To stabilize that we'll need to stabilize at
least part of the `use_extern_macros` feature. Currently you can define a
procedural macro attribute but you can't import it to call it!

A summary of the changes made in this PR (as well as the various consequences)
is:

* The `proc_macro` language and library features are now stable.
* Other APIs not stabilized in the `proc_macro` crate are now named under a
  different feature, such as `proc_macro_diagnostic` or `proc_macro_span`.
* A few checks in resolution for `proc_macro` being enabled have switched over
  to `use_extern_macros` being enabled. This means that code using
  `#![feature(proc_macro)]` today will likely need to move to
  `#![feature(use_extern_macros)]`.

It's intended that this PR, once landed, will be followed up with an attempt to
stabilize a small slice of `use_extern_macros` just for procedural macros to
make this feature 100% usable on stable.

[1]: https://internals.rust-lang.org/t/help-stabilize-a-subset-of-macros-2-0/7252
@bors

This comment has been minimized.

Copy link
Contributor

bors commented Jul 16, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: petrochenkov
Pushing 1ecf692 to master...

@bors bors merged commit 65f3007 into rust-lang:master Jul 16, 2018

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
@rust-highfive

This comment has been minimized.

Copy link
Collaborator

rust-highfive commented Jul 16, 2018

📣 Toolstate changed by #52081!

Tested on commit 1ecf692.
Direct link to PR: #52081

💔 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).

rust-highfive added a commit to rust-lang-nursery/rust-toolstate that referenced this pull request Jul 16, 2018

📣 Toolstate changed by rust-lang/rust#52081!
Tested on commit rust-lang/rust@1ecf692.
Direct link to PR: <rust-lang/rust#52081>

💔 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).

Manishearth added a commit to rust-lang/rust-clippy that referenced this pull request Jul 16, 2018

Update mini-macro post proc macro stabilization
rust-lang/rust#52081 stabilized proc macros, but
quote is still unstable, so you need to explicitly enable that feature.

Manishearth added a commit to Manishearth/rust that referenced this pull request Jul 16, 2018

Update clippy
Fixes test failures caused by rust-lang#52081

@Manishearth Manishearth referenced this pull request Jul 16, 2018

Merged

Update clippy #52448

bors added a commit that referenced this pull request Jul 17, 2018

Auto merge of #52448 - Manishearth:clippyup, r=Mark-Simulacrum
Update clippy

Fixes test failures caused by #52081

LukasKalbertodt added a commit to LukasKalbertodt/auto_impl that referenced this pull request Jul 17, 2018

Update after proc_macro stabilization
The feature `proc_macro` was recently stabilized [1]. This has two effects:
- The `proc_macro` feature gate is replaced by finer grained feature gates
- Using this crate now doesn't need `#![feature(proc_macro)]` but
  `#![feature(use_extern_macros)]`

[1]: rust-lang/rust#52081

@alexcrichton alexcrichton added this to the Rust 2018 Preview 2 milestone Jul 17, 2018

Arnavion added a commit to Arnavion/fac-rs that referenced this pull request Jul 17, 2018

Fixed build on latest nightly.
rust-lang/rust#52081 updated the name of the main
feature required for proc-macro-related sub features.

@alexcrichton alexcrichton deleted the alexcrichton:proc-macro-stable branch Jul 18, 2018

@pitdicker pitdicker referenced this pull request Jul 18, 2018

Merged

Fix wasm-bindgen feature #559

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.