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

Load proc macro metadata in the correct order. #64528

Merged
merged 1 commit into from
Sep 18, 2019

Conversation

Aaron1011
Copy link
Member

Serialized proc macro metadata is assumed to have a one-to-one
correspondence with the entries in static array generated by proc_macro_harness.
However, we were previously serializing proc macro metadata in a
different order than proc macros were laied out in the static array.
This lead to us associating the wrong data with a proc macro when
generating documentation, causing Rustdoc to generate incorrect docs for
proc macros.

This commit keeps track of the order in which we insert proc macros into
the generated static array. We use this same order when serializing proc
macro metadata, ensuring that we can later associate the metadata for a
proc macro with its entry in the static array.

Fixes #64251

@rust-highfive
Copy link
Collaborator

r? @alexcrichton

(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 Sep 16, 2019
@Centril
Copy link
Contributor

Centril commented Sep 16, 2019

cc @petrochenkov @eddyb

@petrochenkov petrochenkov self-assigned this Sep 16, 2019
@alexcrichton
Copy link
Member

I'm not super familiar with this but from my perspective it seems like a sort of odd field to add to the AST, it seems like a better solution might be to ensure that the raw proc macro harnesses are in the same order as the AST, or ensuring that they're encoded in the same order that the harnesses show up (which appears to basically be sorted by type)

@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 Sep 17, 2019
@Aaron1011
Copy link
Member Author

it seems like a better solution might be to ensure that the raw proc macro harnesses are in the same order as the AST

How is this different from your second suggestion?

or ensuring that they're encoded in the same order that the harnesses show up (which appears to basically be sorted by type)

I considered that - however, it seems very fragile to me. The harness code runs very early on, and depends on the AST order. When we (currently) serialize proc macro data, we rely on the HIR order, which AFAIK is not guaranteed to be equivalent to the AST order in any way.

We could sort the proc macros before generating harnesses, but this would require us to ensure that the sorting stays in sync between the harness code and the metadata serialization. It seems much simpler to just record the actual order used by the harness code, and not worry about what that order ends up being.

@petrochenkov
Copy link
Contributor

petrochenkov commented Sep 17, 2019

we rely on the HIR order, which AFAIK is not guaranteed to be equivalent to the AST order in any way.

HIR visiting order needs to follow AST visiting order when it matters (e.g. any parameter/argument order, or statement order) and don't have many reasons to deviate from it even when it technically could.
Proc macros is just one more place where the order matters.

I'd change the harness to visit macros in the AST visiting order, without grouping into derives/attributes/etc, that's a pretty easy order to keep in sync.

This ensures that we match the order used by proc macro metadata
serialization.

Fixes rust-lang#64251
@Aaron1011
Copy link
Member Author

@petrochenkov @alexcrichton : I've modified the harness code to generate macro definitions in AST order.

@alexcrichton
Copy link
Member

@bors: r+

@bors
Copy link
Contributor

bors commented Sep 18, 2019

📌 Commit 3daa8bd has been approved by alexcrichton

@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 Sep 18, 2019
tmandry added a commit to tmandry/rust that referenced this pull request Sep 18, 2019
…excrichton

Load proc macro metadata in the correct order.

Serialized proc macro metadata is assumed to have a one-to-one
correspondence with the entries in static array generated by proc_macro_harness.
However, we were previously serializing proc macro metadata in a
different order than proc macros were laied out in the static array.
This lead to us associating the wrong data with a proc macro when
generating documentation, causing Rustdoc to generate incorrect docs for
proc macros.

This commit keeps track of the order in which we insert proc macros into
the generated static array. We use this same order when serializing proc
macro metadata, ensuring that we can later associate the metadata for a
proc macro with its entry in the static array.

Fixes rust-lang#64251
tmandry added a commit to tmandry/rust that referenced this pull request Sep 18, 2019
…excrichton

Load proc macro metadata in the correct order.

Serialized proc macro metadata is assumed to have a one-to-one
correspondence with the entries in static array generated by proc_macro_harness.
However, we were previously serializing proc macro metadata in a
different order than proc macros were laied out in the static array.
This lead to us associating the wrong data with a proc macro when
generating documentation, causing Rustdoc to generate incorrect docs for
proc macros.

This commit keeps track of the order in which we insert proc macros into
the generated static array. We use this same order when serializing proc
macro metadata, ensuring that we can later associate the metadata for a
proc macro with its entry in the static array.

Fixes rust-lang#64251
tmandry added a commit to tmandry/rust that referenced this pull request Sep 18, 2019
…excrichton

Load proc macro metadata in the correct order.

Serialized proc macro metadata is assumed to have a one-to-one
correspondence with the entries in static array generated by proc_macro_harness.
However, we were previously serializing proc macro metadata in a
different order than proc macros were laied out in the static array.
This lead to us associating the wrong data with a proc macro when
generating documentation, causing Rustdoc to generate incorrect docs for
proc macros.

This commit keeps track of the order in which we insert proc macros into
the generated static array. We use this same order when serializing proc
macro metadata, ensuring that we can later associate the metadata for a
proc macro with its entry in the static array.

Fixes rust-lang#64251
bors added a commit that referenced this pull request Sep 18, 2019
Rollup of 4 pull requests

Successful merges:

 - #64486 (Print out more information for `-Zunpretty=expanded,hygiene`)
 - #64503 (rename Allocation::retag -> with_tags_and_extra)
 - #64516 (update Nomicon and Reference)
 - #64528 (Load proc macro metadata in the correct order.)

Failed merges:

r? @ghost
@bors bors merged commit 3daa8bd into rust-lang:master Sep 18, 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.

Incorrect mixing of reexport and definition documentation of proc macros
6 participants