Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upTracking issue for "Macros 1.1" (RFC #1681) #35900
Comments
nikomatsakis
added
B-RFC-approved
T-lang
T-tools
B-unstable
labels
Aug 22, 2016
This comment has been minimized.
This comment has been minimized.
|
I've updated the issue description with a checklist of what needs to be done. It's likely not exhaustive but it should get us 90% of the way there hopefully |
This comment has been minimized.
This comment has been minimized.
|
Ok, I'm going to look into this today and see how far I get. |
alexcrichton
self-assigned this
Aug 22, 2016
SimonSapin
referenced this issue
Aug 23, 2016
Open
Tracking issue for plugin stabilization (`plugin`, `plugin_registrar` features) #29597
This comment has been minimized.
This comment has been minimized.
|
cc #35957, an implementation |
This comment has been minimized.
This comment has been minimized.
|
From #35957: we should bikeshed the name of the librustc_macro crate some more. In particular, this is intended to be a long-lived crate which will have essentials for all macro authors in it, so limiting to rustc_macro (which in my mind, at least) is just about the 1.1 idea seems bad. I'd previously wanted libmacro for this, but since |
This comment has been minimized.
This comment has been minimized.
|
@nrc: Okay, my immediate thoughts on naming:
|
This comment has been minimized.
This comment has been minimized.
|
@nrc It seems like an important aspect of this question is the naming of our various macro styles over all -- in particular, if we go with To be clear, are you thinking that today's |
This comment has been minimized.
This comment has been minimized.
|
My thinking here is that all macros are "macros", and when we need to make a distinction based on the implementation (the usage should be exactly the same for all kinds) we use "procedural macros" vs "macros by example". I would like to banish "syntax extension" and "compiler plugin" entirely (and one day re-use the latter for actual plugins). But, yes, I strongly want to get behind the "procedural macro" terminology. |
This comment has been minimized.
This comment has been minimized.
|
@nrc Makes good sense to me! While "macros by example" is a bit unwieldy, it's also a very evocative/intuitive term. My one worry about "procedural macro" is that "procedure" is not a thing in Rust. I wonder if there's a way of making the connection more direct. "Function macro" isn't quite right, but maybe gives you a sense of what I mean? |
This comment has been minimized.
This comment has been minimized.
|
Yeah, it's not quite perfect, but given that it is a well-known/used term outside of Rust I think it is better than coining our own term. "Programmatic macro" is possible, but I prefer "procedural". |
This comment has been minimized.
This comment has been minimized.
|
Perl's term for the closest equivalent it has to "procedural macros" is "source filters", which (especially with the shift from AST to tokens) is a pretty fitting description. |
This comment has been minimized.
This comment has been minimized.
|
Perhaps 'Syntax transformers' or 'programmatic macros' would work well as names? I don't have a problem with procedural macros however. |
This comment has been minimized.
This comment has been minimized.
|
"Procedural" is already what people call this, and I think it's clearly understood what it means, especially in contrast to "macros by example." I wouldn't worry about trying to find a different name. |
This comment has been minimized.
This comment has been minimized.
|
I like the term "procedural macro" for regular use (or maybe "custom macro"). I particularly like using the word macro so that it's clear that they can (eventually...) be used in the same way as "regular macros". For this reason, I don't like "source filters" (I also expect a filter to just drop data, not transform it, though I know the term is used for both). I am fine with either |
This comment has been minimized.
This comment has been minimized.
|
One question: do we ever expect to have "support routines" that could be used from non-procedural macros? I know of no such plans, but if we did, and we wanted them in the same crate, then (I am thinking a bit about e.g., @dherman's comment from the eager-expansion RFC.) |
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis: A related but subtly different question is a use case I brought up in rust-lang/rfcs#1561 (comment) - will we want procedural macros' implementation functions to be able to call other procedural macros' implementation functions? I can easily see wanting to allow one custom derive to call another, and that would essentially make procedural macro definitions themselves capable of being used as such "support routines" But yes, I think @dherman's |
This comment has been minimized.
This comment has been minimized.
|
I have a cargo PR rust-lang/cargo#3064 which should check all the "cargo integration" boxes in the checklist. |
This comment has been minimized.
This comment has been minimized.
|
I left a comment on the cargo PR, but I think we want a different type of dependency, not just a different type of package. Firstly, I think this just is just better aestheticly and ergnomicly, but that's just my opinion. But I have two concrete reasons too.
|
This comment has been minimized.
This comment has been minimized.
Yes https://github.com/serde-rs/serde/releases/tag/v0.8.6 (except for container attributes in some cases #36211) |
This comment has been minimized.
This comment has been minimized.
|
Awesome, thanks for the updates @dtolnay! |
This comment has been minimized.
This comment has been minimized.
|
Are there docs on these macros? I suppose, the only example of using them is in serde, am I right? |
bors
added a commit
that referenced
this issue
Jan 5, 2017
nikomatsakis
added a commit
to nikomatsakis/rust
that referenced
this issue
Jan 6, 2017
nikomatsakis
added a commit
to nikomatsakis/rust
that referenced
this issue
Jan 6, 2017
nikomatsakis
added a commit
to nikomatsakis/rust
that referenced
this issue
Jan 6, 2017
nikomatsakis
added a commit
to nikomatsakis/rust
that referenced
this issue
Jan 6, 2017
nikomatsakis
added a commit
to nikomatsakis/rust
that referenced
this issue
Jan 6, 2017
nikomatsakis
added a commit
to nikomatsakis/rust
that referenced
this issue
Jan 6, 2017
This comment has been minimized.
This comment has been minimized.
|
If the user writes This is by-design and thus wouldn't be easy to fix, and I guess it's too late to fix this anyway. |
This comment has been minimized.
This comment has been minimized.
|
You can go |
This comment has been minimized.
This comment has been minimized.
|
You would also need to tell the compiler to add a dependency to |
This comment has been minimized.
This comment has been minimized.
|
The proc macro can use |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I think it's not very intuitive to have to put the path relative to the Cargo.toml. |
This comment has been minimized.
This comment has been minimized.
Yeah I know it can be done, it just can't be done with the current procedural macros API. The parameter is an |
This comment has been minimized.
This comment has been minimized.
Are these APIs (in particular |
This comment has been minimized.
This comment has been minimized.
|
They don't have to be, in fact I wouldn't want to stabilize any of the internals. We can, instead, stabilize APIs that extract information about a |
This comment has been minimized.
This comment has been minimized.
|
I just got this error in a crate of mine. What's going on?
|
This comment has been minimized.
This comment has been minimized.
|
@alexreg If you're using |
This comment has been minimized.
This comment has been minimized.
|
@alexreg
|
This comment has been minimized.
This comment has been minimized.
|
@jseyfried I think we should change the tracking issue on |
This comment has been minimized.
This comment has been minimized.
|
Thanks guys. That makes sense. |
This comment has been minimized.
This comment has been minimized.
|
@abonander Yeah, |
nikomatsakis commentedAug 22, 2016
•
edited by alexcrichton
Tracking issue for rust-lang/rfcs#1681.
cc @alexcrichton
Stabilization TODO
Litmus tests:
Features:
proc_macroproc-macro#[proc_macro_derive(Foo)]attributeproc-macrocrates with-Land#[macro_use]to load themproc-macro = trueKnown bugs:
mod foofail - #36691proc_macro- #38749Implementation TODO
rustc_macrocratelibrustc_macrolink tolibsyntax. Depend onlibrustc_macroinlibrustc_driverrustc_macroas unstable with our standard header.rustc_macrowith#![crate_type = "rlib"], do not produce a dylib.rustc_macrousinglibsyntax'sTokenStreaminternallyrustc_macrowith aTokenStreamlang item so the compiler knows about it.rustc_macro_deriveattributefoo(bar), no other arguments/formatsTokenStreamlang item added aboverustc_macro_deriveinto metadata along with the derive mode they're used for.rustc-macrocrate type for other cratesrustc-macrocrates cannot be linked as dylibs#[rustc_macro_derive]cfg(rustc_macro)as an unstablecfgdirective, set it for therustc-macrocrate typerustc-macrocrates link dynamically to libsytnax#[macro_use]support forrustc-macrocratesrustc-macrocrates separately from dylib/rlib tracked today when loding cratesrustc-macrocrates to learn about symbol/derive mode pairingsdlopenthe dylibrustc-macrosimilar toplugin = true--crate-type=rustc-macrowhen depending on it#[derive]trait