-
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
macros: expand items before their #[derive]
s
#41029
Conversation
cc #38356 |
536d411
to
370a837
Compare
370a837
to
3b6b779
Compare
cc @alexcrichton @rust-lang/lang |
Other than bringing Could we Crater this? |
@nrc Also, derives usually want expanded code, e.g.
|
Seems fine to me! |
Seems like we could detect some breakage here via a crater run, for sure. |
To be clear, this change would mean that |
@sgrif my understanding of this change is that cfg attributes will not change at all. Its that other macros inside a struct will be expanded in the same way that cfg is. |
@withoutboats exactly. |
Ah. Big 👍 from me then. XD |
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.
r=me with the tests fixed and a comment on PartialExpansion
. I think that in general the expansion code is getting pretty complex, if you get a chance it would be great if you could add some docs giving an overview of the process and data structures, and some detailed comments around the place to explain what is going on (in another PR, doesn't need to block this one).
@@ -156,16 +156,20 @@ impl<'a> base::Resolver for Resolver<'a> { | |||
self.whitelisted_legacy_custom_derives.contains(&name) | |||
} | |||
|
|||
fn visit_expansion(&mut self, mark: Mark, expansion: &Expansion, derives: &[Mark]) { | |||
fn visit_expansion(&mut self, mark: Mark, expansion: &Expansion, derives: &[(Mark, Path)]) { |
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.
I would think about making this new tuple into a struct - it's OK for now, but I think it is a bit opaque to identify a derive by a (Mark, Path)
.
monotonic: bool, // c.f. `cx.monotonic_expander()` | ||
} | ||
|
||
struct PartialExpansion { |
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 add a comment here please - it would be good to explain how partial expansions come about - are they just intermediate state or are they stored like this, in what circumstances is a macro partially rather than fully expanded, and are there invariants that can be assumed about partial expansions.
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.
Will do. Partial expansion are macro expansions that have unexpanded macro invocations in them. That is, the macro itself has resolved and been expanded, but it created more macro invocations that have yet to be expanded. This is in contrast to "fully expanded" AST, which has no macro invocations left.
Friendly ping to keep this PR on your radar @jseyfried! ❤️ |
Looks like there's some minor tweaks requested, @jseyfried — do you think you will be able to address those soon? |
@carols10cents @shepmaster Yeah, this is still on my radar -- I plan on fixing the tweaks and |
I'm going to close this out of inactivity for now, but @jseyfried you're of course welcome to resubmit at any time! (just trying to help clear out the queue) |
@jseyfried are you going to revive this PR? |
…henkov Expand items before their derives continuation of rust-lang#41029 At this point all I've done is naively rebased on top of `master` and fixed the code enough to compile. I'm not even sure if it works because my local build stopped here: ``` C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Microsoft.CppBuild.targets(317,5): error MSB3491: Could not write lines to file "emscripten -optimizer.dir\Release\emscript.63209ED8.tlog\emscripten-optimizer.lastbuildstate". The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters. [C:\Users\cyber\Rust\rust\build\x86_64-pc-windows-msvc\stage0-rustc\x86_64-pc-windows-msvc\release\bui ld\rustc_binaryen-aaf5e3b308543526\out\build\src\emscripten-optimizer\emscripten-optimizer.vcxproj] ``` So I'm going to be relying on Travis to run tests unless I can fix this error.
For example, after this PR the following are equivalent:
Note that today,
#[cfg]
s in an item are processed before expanding#[derive]
s. For example,After this PR, we can consider
#[cfg]
to be a normal attribute macro (assuming attribute macros were allowed everywhere#[cfg]
is allowed).Since type macros and
#[proc_macro_derive]
are stable, this is a [breaking-change].r? @nrc