-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
rustdoc: calculate visibility on-demand #91408
Conversation
/// If this item was inlined, the DefId of the `use` statement. | ||
crate inline_stmt_id: Option<DefId>, |
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.
boooooo
This comment has been minimized.
This comment has been minimized.
fc9f894
to
19fdd05
Compare
@bors try @rust-timer queue |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
⌛ Trying commit 19fdd05f4e02e7a40d8f639e38cb7ead3a8e2ab2 with merge fbec2c38e225491dba4fab51850edaaacea88976... |
☀️ Try build successful - checks-actions |
Queued fbec2c38e225491dba4fab51850edaaacea88976 with parent 207c80f, future comparison URL. |
Finished benchmarking commit (fbec2c38e225491dba4fab51850edaaacea88976): comparison url. Summary: This change led to moderate relevant improvements 🎉 in compiler performance.
If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR led to changes in compiler perf. @bors rollup=never |
Up to 1% improvements on doc instructions counts :) max-rss is a bit mixed, though I think overall positive. |
Hmm, I'd rather avoid |
} | ||
_ => {} | ||
} | ||
// If this item was inlined, show the visibility of the `use` statement, not the definition. |
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.
This doesn't seem quite correct. Take this code for example:
// crate a
pub struct S {
pub x: i32,
y: i32,
}
// crate b
pub(crate) use a::S;
If --document-private-items
is passed, then I think the documentation for b::S
should look like this (although I may not be remembering the inlining rules quite right):
pub(crate) struct S {
pub(crate) x: i32,
y: i32,
}
But with your change, I think it will look like this:
pub(crate) struct S {
pub(crate) x: i32,
pub(crate) y: i32,
}
Can you test that code (or a variant of it to get the inlining to happen) before and after this change to check?
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.
Or perhaps this won't happen because inlining doesn't occur for struct fields? But I feel like this sort of bug could probably occur with other items.
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.
This is exactly the same behavior as before, whatever that happened to be. I just moved the logic from try_inline
to visibility()
.
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.
also, I don't think this can happen for struct fields because you can't import them directly, only the struct itself. Enum variants can be imported, but they're special-cased earlier anyway.
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 couldn't get y
to appear with pub(crate) use
(maybe due to #91094 ?) but with pub use
the docs look like this on nightly:
so uhh yeah this is a pre-existing bug, good catch 😅
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.
This is exactly the same behavior as before, whatever that happened to be. I just moved the logic from try_inline to visibility().
Ah, I see.
let def_id = match self.inline_stmt_id { | ||
Some(inlined) => inlined, | ||
None => def_id, | ||
}; |
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.
Shouldn't this check be done before the big match *self.kind {
above? It seems like this does extra work for inlined items, and the code's a bit harder to understand.
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.
No, because then all the uses of def_id
in the match would be wrong (e.g. associated_item
and overriding the ExternCrateItem
def_id).
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.
also I'm not sure what you mean by extra work - this isn't doing an early return, it's just reassigning def_id
.
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.
What I'm suggesting is changing this to be an early return. What's the point of calculating def_id
earlier if this code overrides it anyway?
- lots of staring really hard at the existing code to make sure the behavior matches - store `inline_stmt_id` and `crate_stmt_id` to be able to get their visibility (rustdoc stores the IDs of the item definition in `clean::Item`, not the re-export)
/// The id of the `extern crate` statement, not the crate itself. | ||
crate_stmt_id: LocalDefId, |
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.
Why can't this use Item.inline_stmt_id
? Or I guess is this not quite the same as inline_stmt_id
? Still, it feels like they should be merged somehow since they're similar.
☔ The latest upstream changes (presumably #91291) made this pull request unmergeable. Please resolve the merge conflicts. |
@bors rollup=never (since the |
not planning to follow up on this |
@camelid is there any interest in resolving the merge conflict on this PR ? |
… r=notriddle Make rustdoc Item::visibility computed on-demand This is a take-over of rust-lang#91408. Helps with rust-lang#90852 (needs to use `ty::Visibility` directly too). cc `@camelid` r? `@notriddle`
Make rustdoc Item::visibility computed on-demand This is a take-over of rust-lang/rust#91408. Helps with rust-lang/rust#90852 (needs to use `ty::Visibility` directly too). cc `@camelid` r? `@notriddle`
Make rustdoc Item::visibility computed on-demand This is a take-over of rust-lang/rust#91408. Helps with rust-lang/rust#90852 (needs to use `ty::Visibility` directly too). cc `@camelid` r? `@notriddle`
Make rustdoc Item::visibility computed on-demand This is a take-over of rust-lang/rust#91408. Helps with rust-lang/rust#90852 (needs to use `ty::Visibility` directly too). cc `@camelid` r? `@notriddle`
inline_stmt_id
is very hacky and will probably lose all the memory improvements I was hoping for. Maybe we can change inlined items to have theDefId
of theuse
statement directly instead of storing both?Helps with #90852 (doesn't fix it because I haven't yet switched to
ty::Visibility
directly).r? @camelid