Skip to content

macros: improve reexports - #37463

Merged
bors merged 9 commits into
rust-lang:masterfrom
jseyfried:refactor_macro_reexports
Nov 10, 2016
Merged

macros: improve reexports#37463
bors merged 9 commits into
rust-lang:masterfrom
jseyfried:refactor_macro_reexports

Conversation

@jseyfried

@jseyfriedjseyfried commented Oct 29, 2016

Copy link
Copy Markdown
Contributor

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

jseyfried commented Oct 29, 2016

Copy link
Copy Markdown
ContributorAuthor

cc @eddyb@alexcrichton
cc #35896

@jseyfried
jseyfriedforce-pushed the refactor_macro_reexports branch from 6a83458 to 70eca75CompareOctober 29, 2016 07:40
Comment threadsrc/librustc_metadata/encoder.rs Outdated

Copy link
Copy Markdown
Contributor

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
Copy Markdown
ContributorAuthor

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
jseyfriedforce-pushed the refactor_macro_reexports branch 4 times, most recently from 9399bd2 to ea80c32CompareOctober 30, 2016 09:08
@bors

bors commented Oct 30, 2016

Copy link
Copy Markdown
Collaborator

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

@jseyfried
jseyfriedforce-pushed the refactor_macro_reexports branch from ea80c32 to b0babc8CompareOctober 30, 2016 21:55
@jseyfried
jseyfriedforce-pushed the refactor_macro_reexports branch 2 times, most recently from b3bb0a7 to bac13dcCompareNovember 5, 2016 20:11
nrc
nrc approved these changes Nov 7, 2016
Comment threadsrc/librustc_metadata/decoder.rs Outdated

Copy link
Copy Markdown
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
Copy Markdown
ContributorAuthor

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.

Comment threadsrc/librustc_resolve/lib.rs Outdated

Copy link
Copy Markdown
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

Comment threadsrc/librustc/hir/map/collector.rs Outdated

Copy link
Copy Markdown
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.

@jseyfriedjseyfriedNov 7, 2016

Copy link
Copy Markdown
ContributorAuthor

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
Copy Markdown
Contributor

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

bors commented Nov 7, 2016

Copy link
Copy Markdown
Collaborator

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

@jseyfried
jseyfriedforce-pushed the refactor_macro_reexports branch 3 times, most recently from ed42dfc to 57d781dCompareNovember 7, 2016 22:38
@jseyfried

Copy link
Copy Markdown
ContributorAuthor

@bors r=nrc

@bors

bors commented Nov 7, 2016

Copy link
Copy Markdown
Collaborator

📌 Commit 57d781d has been approved by nrc

@bors

bors commented Nov 7, 2016

Copy link
Copy Markdown
Collaborator

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

@bors

bors commented Nov 7, 2016

Copy link
Copy Markdown
Collaborator

💔 Test failed - auto-linux-cross-opt

@jseyfried
jseyfriedforce-pushed the refactor_macro_reexports branch from 57d781d to f967566CompareNovember 8, 2016 05:16
@jseyfried

Copy link
Copy Markdown
ContributorAuthor

@bors r=nrc

@bors

bors commented Nov 8, 2016

Copy link
Copy Markdown
Collaborator

📌 Commit f967566 has been approved by nrc

@eddybeddyb mentioned this pull request Nov 9, 2016
bors added a commit that referenced this pull request Nov 9, 2016
@jseyfried
jseyfriedforce-pushed the refactor_macro_reexports branch from f967566 to 3d760d7CompareNovember 10, 2016 06:07
@jseyfried
jseyfriedforce-pushed the refactor_macro_reexports branch from 3d760d7 to b2fa1b6CompareNovember 10, 2016 09:23
@jseyfried

Copy link
Copy Markdown
ContributorAuthor

@bors r=nrc

@bors

bors commented Nov 10, 2016

Copy link
Copy Markdown
Collaborator

📌 Commit b2fa1b6 has been approved by nrc

@bors

bors commented Nov 10, 2016

Copy link
Copy Markdown
Collaborator

⌛ Testing commit b2fa1b6 with merge 8510b2e...

@bors

bors commented Nov 10, 2016

Copy link
Copy Markdown
Collaborator

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

@jseyfried
jseyfriedforce-pushed the refactor_macro_reexports branch from b2fa1b6 to a0a9f8cCompareNovember 10, 2016 10:05
@jseyfried

Copy link
Copy Markdown
ContributorAuthor

@bors r=nrc

@bors

bors commented Nov 10, 2016

Copy link
Copy Markdown
Collaborator

📌 Commit a0a9f8c has been approved by nrc

@bors

bors commented Nov 10, 2016

Copy link
Copy Markdown
Collaborator

⌛ 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:masterNov 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 freeto 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

@jseyfried@bors@eddyb@nrc