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

Propagate spans and attributes from proc macro definitions #63761

Merged
merged 4 commits into from
Aug 27, 2019

Conversation

petrochenkov
Copy link
Contributor

Thanks to #63269 we now have spans and attributes from proc macro definitions available in metadata.

However, that PR didn't actually put them into use! This PR finishes that work.

Attributes rustc_macro_transparency, allow_internal_unstable, allow_internal_unsafe, local_inner_macros, rustc_builtin_macro, stable, unstable, rustc_deprecated, deprecated now have effect when applied to proc macro definition functions.
From those attributes only deprecated is both stable and supposed to be used in new code.
(#![staged_api] still cannot be used in proc macro crates for unrelated reasons though.)

Span::def_site from the proc macro API now returns the correct location of the proc macro definition.

Also, I made a mistake in #63269 (comment), loaded proc macros didn't actually use the resolver cache.
This PR fixes the caching issue, now proc macros go through the Resolver::macro_map cache as well.

(Also, the first commit turns proc_macro::quote into a regular built-in macro to reduce the number of places where SyntaxExtensions need to be manually created.)

@rust-highfive
Copy link
Collaborator

r? @eddyb

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

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 20, 2019
@petrochenkov
Copy link
Contributor Author

cc @Aaron1011

let edition = if sess.opts.debugging_opts.dual_proc_macros {
self.host_lib.as_ref().unwrap().metadata.get_root().edition
} else {
self.root.edition
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure whether this dance is necessary.
Can these two "roots" have different editions?
I don't really understand how "dual proc macros" work.
cc @Zoxc

@rust-highfive

This comment has been minimized.

macro_rules! quote { () => {} }
#[allow_internal_unstable(proc_macro_def_site)]
#[cfg_attr(not(bootstrap), rustc_builtin_macro)]
pub macro quote ($($t:tt)*) { /* compiler built-in */ }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohhh right, this works now, without the risk of this quote ending up defined anywhere other than the proc_macro crate!

Copy link
Member

@eddyb eddyb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me but maybe @alexcrichton or @dtolnay want to take a look as well

@alexcrichton
Copy link
Member

I won't pretend to fully understand what's happening here but what I do understand all seems quite reasonable!

@petrochenkov
Copy link
Contributor Author

@bors r=eddyb

@bors
Copy link
Contributor

bors commented Aug 24, 2019

📌 Commit 5c4e04e036ee8b4565ac9c8e24d4ca73abade656 has been approved by eddyb

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 24, 2019
@bors
Copy link
Contributor

bors commented Aug 24, 2019

⌛ Testing commit 5c4e04e036ee8b4565ac9c8e24d4ca73abade656 with merge 8848c10c117204140db4f06c59687e44655dea92...

@bors
Copy link
Contributor

bors commented Aug 24, 2019

💥 Test timed out

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Aug 24, 2019
@bors
Copy link
Contributor

bors commented Aug 24, 2019

☔ The latest upstream changes (presumably #63823) made this pull request unmergeable. Please resolve the merge conflicts.

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 24, 2019
Previously in was implemented using a special hack in the metadata loader
Fix caching of loaded proc macros
…location

Which is no longer dummy and is available from metadata now.
@petrochenkov
Copy link
Contributor Author

@bors r=eddyb

@bors
Copy link
Contributor

bors commented Aug 26, 2019

📌 Commit c476b55 has been approved by eddyb

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 26, 2019
Centril added a commit to Centril/rust that referenced this pull request Aug 27, 2019
Propagate spans and attributes from proc macro definitions

Thanks to rust-lang#63269 we now have spans and attributes from proc macro definitions available in metadata.

However, that PR didn't actually put them into use! This PR finishes that work.

Attributes `rustc_macro_transparency`, `allow_internal_unstable`, `allow_internal_unsafe`, `local_inner_macros`, `rustc_builtin_macro`, `stable`, `unstable`, `rustc_deprecated`, `deprecated` now have effect when applied to proc macro definition functions.
From those attributes only `deprecated` is both stable and supposed to be used in new code.
(`#![staged_api]` still cannot be used in proc macro crates for unrelated reasons though.)

`Span::def_site` from the proc macro API now returns the correct location of the proc macro definition.

Also, I made a mistake in rust-lang#63269 (comment), loaded proc macros didn't actually use the resolver cache.
This PR fixes the caching issue, now proc macros go through the `Resolver::macro_map` cache as well.

(Also, the first commit turns `proc_macro::quote` into a regular built-in macro to reduce the number of places where `SyntaxExtension`s need to be manually created.)
Centril added a commit to Centril/rust that referenced this pull request Aug 27, 2019
Propagate spans and attributes from proc macro definitions

Thanks to rust-lang#63269 we now have spans and attributes from proc macro definitions available in metadata.

However, that PR didn't actually put them into use! This PR finishes that work.

Attributes `rustc_macro_transparency`, `allow_internal_unstable`, `allow_internal_unsafe`, `local_inner_macros`, `rustc_builtin_macro`, `stable`, `unstable`, `rustc_deprecated`, `deprecated` now have effect when applied to proc macro definition functions.
From those attributes only `deprecated` is both stable and supposed to be used in new code.
(`#![staged_api]` still cannot be used in proc macro crates for unrelated reasons though.)

`Span::def_site` from the proc macro API now returns the correct location of the proc macro definition.

Also, I made a mistake in rust-lang#63269 (comment), loaded proc macros didn't actually use the resolver cache.
This PR fixes the caching issue, now proc macros go through the `Resolver::macro_map` cache as well.

(Also, the first commit turns `proc_macro::quote` into a regular built-in macro to reduce the number of places where `SyntaxExtension`s need to be manually created.)
bors added a commit that referenced this pull request Aug 27, 2019
Rollup of 4 pull requests

Successful merges:

 - #62600 (libtest: add --show-output flag to print stdout of successful tests)
 - #63698 (Fixed floating point issue with asinh function)
 - #63761 (Propagate spans and attributes from proc macro definitions)
 - #63917 (Error when generator trait is not found)

Failed merges:

r? @ghost
@bors bors merged commit c476b55 into rust-lang:master Aug 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants