-
Notifications
You must be signed in to change notification settings - Fork 13.3k
rustdoc: Compute some fields of clean::Crate
on-demand to reduce size
#90391
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
27d47d9
rustdoc: Add static size assertion for `clean::Crate`
camelid 47b0059
rustdoc: Document that `Crate` is always local
camelid 85f8ae8
rustdoc: Remove `Crate.src` and instead compute it on-demand
camelid ebe9a11
rustdoc: Remove `Crate.name` and instead compute it on-demand
camelid a58e214
rustdoc: Stop sorting external crates
camelid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,10 +113,9 @@ impl From<DefId> for ItemId { | |
} | ||
} | ||
|
||
/// The crate currently being documented. | ||
#[derive(Clone, Debug)] | ||
crate struct Crate { | ||
crate name: Symbol, | ||
crate src: FileName, | ||
crate module: Item, | ||
crate externs: Vec<ExternalCrate>, | ||
crate primitives: ThinVec<(DefId, PrimitiveType)>, | ||
|
@@ -125,6 +124,20 @@ crate struct Crate { | |
crate collapsed: bool, | ||
} | ||
|
||
// `Crate` is frequently moved by-value. Make sure it doesn't unintentionally get bigger. | ||
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] | ||
rustc_data_structures::static_assert_size!(Crate, 104); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice idea to add this check! 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks :) |
||
|
||
impl Crate { | ||
crate fn name(&self, tcx: TyCtxt<'_>) -> Symbol { | ||
ExternalCrate::LOCAL.name(tcx) | ||
} | ||
|
||
crate fn src(&self, tcx: TyCtxt<'_>) -> FileName { | ||
ExternalCrate::LOCAL.src(tcx) | ||
} | ||
} | ||
|
||
/// This struct is used to wrap additional information added by rustdoc on a `trait` item. | ||
#[derive(Clone, Debug)] | ||
crate struct TraitWithExtraInfo { | ||
|
@@ -138,6 +151,8 @@ crate struct ExternalCrate { | |
} | ||
|
||
impl ExternalCrate { | ||
const LOCAL: Self = Self { crate_num: LOCAL_CRATE }; | ||
|
||
#[inline] | ||
crate fn def_id(&self) -> DefId { | ||
DefId { krate: self.crate_num, index: CRATE_DEF_INDEX } | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Note to self: remove this field as well.
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.
Update: In order to remove this field,
Cache::populate
will need to take a DocContext, which I think is possible but will require some changes. I'm also working on that as part of #90365, so I'll save removing this field for a future PR.