-
Notifications
You must be signed in to change notification settings - Fork 14k
Enforce the compiler-builtins partitioning scheme #135395
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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 |
|---|---|---|
|
|
@@ -319,6 +319,13 @@ fn merge_codegen_units<'tcx>( | |
| let mut cgu_contents: UnordMap<Symbol, Vec<Symbol>> = | ||
| codegen_units.iter().map(|cgu| (cgu.name(), vec![cgu.name()])).collect(); | ||
|
|
||
| // When compiling compiler_builtins, we do not want to put multiple intrinsics in a CGU. | ||
| // There may be mergeable CGUs under this constraint, but just skipping over merging is much | ||
| // simpler. | ||
| if cx.tcx.is_compiler_builtins(LOCAL_CRATE) { | ||
| return cgu_contents; | ||
| } | ||
|
|
||
| // If N is the maximum number of CGUs, and the CGUs are sorted from largest | ||
| // to smallest, we repeatedly find which CGU in codegen_units[N..] has the | ||
| // greatest overlap of inlined items with codegen_units[N-1], merge that | ||
|
|
@@ -680,6 +687,16 @@ fn compute_codegen_unit_name<'tcx>( | |
| mono_item: MonoItem<'tcx>, | ||
| cache: &mut CguNameCache, | ||
| ) -> Symbol { | ||
| // When compiling compiler_builtins, we do not want to put multiple intrinsics in a CGU. | ||
| // Using the symbol name as the CGU name puts every GloballyShared item in its own CGU, but in | ||
| // an optimized build we actually want every item in the crate that isn't an intrinsic to get | ||
| // LocalCopy so that it is easy to inline away. In an unoptimized build, this CGU naming | ||
| // strategy probably generates more CGUs than we strictly need. But it is simple. | ||
| if tcx.is_compiler_builtins(LOCAL_CRATE) { | ||
| let name = mono_item.symbol_name(tcx); | ||
| return Symbol::intern(name.name); | ||
|
Member
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. One of the symbols in compiler-builtins is 132 characters long, together with the crate name and the temporary directory, this could exceed MAX_PATH on Windows I think. Maybe hash the name if its length exceeds say 50 characters |
||
| } | ||
|
|
||
| let Some(def_id) = characteristic_def_id_of_mono_item(tcx, mono_item) else { | ||
| return fallback_cgu_name(name_builder); | ||
| }; | ||
|
|
||
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.
Is there a way to make inlining inside the crate more likely without causing MIR for all functions in compiler-builtins to get encoded in the crate metadata?
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 think what you're pointing out here is that these functions are not reachable as MIR, so we don't need to encode MIR for them. The problem as I see it is that our notion of reachable uses this worklist/visited algorithm that tracks items in a path-independent way:
rust/compiler/rustc_passes/src/reachable.rs
Lines 168 to 173 in 2ae9916
Also we already have an issue for the inverse inefficiency, emitting object code when we only need MIR: #119214
I put a hack in this place specifically because the compiler is designed around this function either true or false for whatever reason, past the first few checks. I'm not aware of anywhere else we could make a small localized change to get the behavior we want.
The only other place I could think of putting a hack is
MonoItem::instantiation_mode, but that doesn't work because then we get linker errors because instantiation mode needs to agree withexported_symbols, and those disagree because becauseexported_symbolsis based onreachable_set. I really think the inaccuracy of thereachable_setanalysis is the root problem here, and it's net better to implement this in a non-invasive way that will be fixed automatically ifreachable_setgets improved.Uh oh!
There was an error while loading. Please reload this page.
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, if I back up to my merge-base,
x build library, thenar xthe stage1-std libcompiler_builtins.rlib and rundu -sch *I get:Then with my changes:
So even though it's not perfect, this PR is still a net win.