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

macros: improve reexports #37463

Merged
merged 9 commits into from
Nov 10, 2016
Merged

Conversation

jseyfried
Copy link
Contributor

@jseyfried jseyfried commented Oct 29, 2016

This PR

  • fixes $crate in #[macro_reexport]ed macros,
    • [breaking-change] for #[feature(macro_reexport)] (technically)
  • stability checks #[no_link] extern crates,
    • [breaking-chage]: #[no_link] #[macro_use] extern crate syntax; is allowed on stable today
  • allows selective macro importing (i.e. #[macro_use(foo, bar)]) from custom derive crates,
  • avoids building multiple module graphs for a crate that is referenced by multiple extern crate items,
  • registers #[no_link] extern crates to avoid loading the same crate metadata twice, and
  • refactors the crate metadata to support re-exported macros in arbitrary modules (not yet needed).

r? @nrc

@jseyfried
Copy link
Contributor Author

jseyfried commented Oct 29, 2016

cc @eddyb @alexcrichton
cc #35896

name: macro_def.name,
attrs: macro_def.attrs.to_vec(),
span: macro_def.span,
body: ::syntax::print::pprust::tts_to_string(&macro_def.body)
Copy link
Member

Choose a reason for hiding this comment

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

We should just encode the raw tokens - which would get us proper spans from the original source.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, but I'd rather change that in a separate PR.

@jseyfried jseyfried force-pushed the refactor_macro_reexports branch 4 times, most recently from 9399bd2 to ea80c32 Compare October 30, 2016 09:08
@bors
Copy link
Contributor

bors commented Oct 30, 2016

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

if let Def::Macro(..) = exp.def {
} else if macros_only {
continue
}
Copy link
Member

Choose a reason for hiding this comment

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

This would be clearer using else if !macros_only { callback(exp) } and/or using a match rather than if let

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'll use a match.

@@ -533,6 +533,7 @@ impl PatternSource {
pub enum Namespace {
TypeNS,
ValueNS,
MacroNS,
Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer to use a qualified name rather than have this NS suffix on each variant, but not essential to landing

@@ -226,4 +226,8 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> {
fn visit_lifetime(&mut self, lifetime: &'ast Lifetime) {
self.insert(lifetime.id, NodeLifetime(lifetime));
}

fn visit_macro_def(&mut self, macro_def: &'ast MacroDef) {
self.insert_entry(macro_def.id, NotPresent);
Copy link
Member

Choose a reason for hiding this comment

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

Why do we record macros in the HIR and start with HIR to make the metadata? I'd have thought the HIR should be totally ignorant of macros and we could generate metadata from the AST.

Copy link
Contributor Author

@jseyfried jseyfried Nov 7, 2016

Choose a reason for hiding this comment

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

The AST is no longer around when we generate metadata.

If we don't want to include exported macros in the HIR, I think the best alternative would be to move the AST's exported macros into a local in driver::compile_input and pass them directly to the metadata encoder.

Copy link
Member

Choose a reason for hiding this comment

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

Don't see any improvement from that. OTOH, HIR is nicer for incremental recompilation.

@bors
Copy link
Contributor

bors commented Nov 7, 2016

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

@jseyfried jseyfried force-pushed the refactor_macro_reexports branch 3 times, most recently from ed42dfc to 57d781d Compare November 7, 2016 22:38
@jseyfried
Copy link
Contributor Author

@bors r=nrc

@bors
Copy link
Contributor

bors commented Nov 7, 2016

📌 Commit 57d781d has been approved by nrc

@bors
Copy link
Contributor

bors commented Nov 7, 2016

⌛ Testing commit 57d781d with merge 8840d92...

@bors
Copy link
Contributor

bors commented Nov 7, 2016

💔 Test failed - auto-linux-cross-opt

@jseyfried
Copy link
Contributor Author

@bors r=nrc

@bors
Copy link
Contributor

bors commented Nov 8, 2016

📌 Commit f967566 has been approved by nrc

bors added a commit that referenced this pull request Nov 9, 2016
Rollup of 15 pull requests

- Successful merges: #36868, #37134, #37229, #37250, #37370, #37428, #37432, #37472, #37524, #37614, #37622, #37627, #37636, #37644, #37654
- Failed merges: #37463, #37542, #37645
@jseyfried
Copy link
Contributor Author

@bors r=nrc

@bors
Copy link
Contributor

bors commented Nov 10, 2016

📌 Commit b2fa1b6 has been approved by nrc

@bors
Copy link
Contributor

bors commented Nov 10, 2016

⌛ Testing commit b2fa1b6 with merge 8510b2e...

@bors
Copy link
Contributor

bors commented Nov 10, 2016

💔 Test failed - auto-win-gnu-32-opt-rustbuild

@jseyfried
Copy link
Contributor Author

@bors r=nrc

@bors
Copy link
Contributor

bors commented Nov 10, 2016

📌 Commit a0a9f8c has been approved by nrc

@bors
Copy link
Contributor

bors commented Nov 10, 2016

⌛ Testing commit a0a9f8c with merge ab03f85...

bors added a commit that referenced this pull request Nov 10, 2016
macros: improve reexports

This PR
- avoids building multiple module graphs for a crate that is referenced by multiple `extern crate` items,
- registers `#[no_link] extern crate`s to avoid loading the same crate metadata twice,
- stability checks `#[no_link] extern crate`s,
  - [breaking-chage]: `#[no_link] #[macro_use] extern crate syntax;` is allowed on stable today
- fixes `$crate` in `#[macro_reexport]`ed macros,
  - [breaking-change] for `#[feature(macro_reexport)]` (technically)
- allows selective macro importing (i.e. `#[macro_use(foo, bar)]`) from custom derive crates, and
- refactors the crate metadata to support re-exported macros in arbitrary modules (not yet needed).

r? @nrc
@bors bors merged commit a0a9f8c into rust-lang:master Nov 10, 2016
@jseyfried jseyfried deleted the refactor_macro_reexports branch November 11, 2016 02:53
bors added a commit that referenced this pull request Nov 23, 2016
rustc_metadata: don't break the version check when CrateRoot changes.

In #36551 I made `rustc_version` a field of `CrateRoot`, but despite it being the first field, one could still break the version check by changing `CrateRoot` so older compilers couldn't fully decode it (e.g. #37463).

This PR fixes #37803 by moving the version string back at the beginning of metadata, right after the 32-bit big-endian absolute position of `CrateRoot`, and by incrementing `METADATA_VERSION`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants