-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Tracking issue for "Macros 1.1" (RFC #1681) #35900
Comments
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 |
Ok, I'm going to look into this today and see how far I get. |
cc #35957, an implementation |
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 |
@nrc: Okay, my immediate thoughts on naming:
|
@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 |
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. |
@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? |
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". |
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. |
Perhaps 'Syntax transformers' or 'programmatic macros' would work well as names? I don't have a problem with procedural macros however. |
"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. |
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 |
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.) |
@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 |
I have a cargo PR rust-lang/cargo#3064 which should check all the "cargo integration" boxes in the checklist. |
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.
|
Yes https://github.com/serde-rs/serde/releases/tag/v0.8.6 (except for container attributes in some cases #36211) |
Awesome, thanks for the updates @dtolnay! |
Are there docs on these macros? I suppose, the only example of using them is in serde, am I right? |
This commit stabilizes the `proc_macro` and `proc_macro_lib` features in the compiler to stabilize the "Macros 1.1" feature of the language. Many more details can be found on the tracking issue, rust-lang#35900. Closes rust-lang#35900
These are some bare-bones documentation for custom derive, needed to stabilize "macros 1.1", rust-lang#35900 The book chapter is based off of a blog post by @cbreeden, https://cbreeden.github.io/Macros11/ Normally, we have a policy of not mentioning external crates in documentation. However, given that syn/quote are basically neccesary for properly using macros 1.1, I feel that not including them here would make the documentation very bad. So the rules should be bent in this instance.
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. |
You can go |
You would also need to tell the compiler to add a dependency to |
The proc macro can use |
I think it's not very intuitive to have to put the path relative to the Cargo.toml. |
Yeah I know it can be done, it just can't be done with the current procedural macros API. The parameter is an |
Are these APIs (in particular |
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 |
I just got this error in a crate of mine. What's going on?
|
@alexreg If you're using |
@alexreg
|
@jseyfried I think we should change the tracking issue on |
Thanks guys. That makes sense. |
@abonander Yeah, |
`empty_line_after_outer_attribute` produced a false positive warning when deriving `Copy` and/or `Clone` for an item. It looks like the second point in [this comment][that_comment] is related, as the attribute that causes the false positive has a path of `rustc_copy_clone_marker`. Fixes rust-lang#2475 [that_comment]: rust-lang/rust#35900 (comment)
Tracking issue for rust-lang/rfcs#1681.
cc @alexcrichton
Stabilization TODO
Litmus tests:
Features:
proc_macro
proc-macro
#[proc_macro_derive(Foo)]
attributeproc-macro
crates with-L
and#[macro_use]
to load themproc-macro = true
Known bugs:
mod foo
fail - Custom derives: TokenStream::from_str fails if the string contains 'mod foo;' #36691proc_macro
- Publish docs forproc_macro
crate #38749#[derive]
s after other attribute macros and improve intra-#[derive]
ordering #37067)Implementation TODO
rustc_macro
cratelibrustc_macro
link tolibsyntax
. Depend onlibrustc_macro
inlibrustc_driver
rustc_macro
as unstable with our standard header.rustc_macro
with#![crate_type = "rlib"]
, do not produce a dylib.rustc_macro
usinglibsyntax
'sTokenStream
internallyrustc_macro
with aTokenStream
lang item so the compiler knows about it.rustc_macro_derive
attributefoo(bar)
, no other arguments/formatsTokenStream
lang item added aboverustc_macro_derive
into metadata along with the derive mode they're used for.rustc-macro
crate type for other cratesrustc-macro
crates cannot be linked as dylibs#[rustc_macro_derive]
cfg(rustc_macro)
as an unstablecfg
directive, set it for therustc-macro
crate typerustc-macro
crates link dynamically to libsytnax#[macro_use]
support forrustc-macro
cratesrustc-macro
crates separately from dylib/rlib tracked today when loding cratesrustc-macro
crates to learn about symbol/derive mode pairingsdlopen
the dylibrustc-macro
similar toplugin = true
--crate-type=rustc-macro
when depending on it#[derive]
traitThe text was updated successfully, but these errors were encountered: