-
Notifications
You must be signed in to change notification settings - Fork 13k
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
rustc: Tweak visibility of some lang items #52993
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
Note that the diff looks gnarly, but the second commit is much cleaner and the first commit should have no functional changes included, just a refactoring. |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
fb9f0f0
to
236adc0
Compare
The travis failure above pointed me to some more worrying bugs to fix, but they should be fixed here now as well. The bug was that we were defining the We are, today, generating an allocator CGU for too many crates. If you link to the standard library dynamically, for example, you don't need an allocator CGU as libstd has already selected the allocator symbols for you, and you should reference those. This meant that the compiler failed to compile because it was generating allocator CGUs referencing hidden symbols defined in libstd's dynamic object, causing the link to fail. So the solution here was to generate an allocator CGU less of the time. Basically if anything is a rust dylib there's no need for an allocator CGU because the allocator has already been selected. Otherwise everything should proceed as usual today (all static compilations will continue to generate an allocator CGU) |
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.
Looks great, thanks Alex! r=me with the nits addressed.
tcx: TyCtxt<'a, 'tcx, 'tcx>, | ||
mono_item: &MonoItem<'tcx>, | ||
can_be_internalized: &mut bool, | ||
default: &dyn Fn(DefId, bool) -> 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.
It seems like default
could be just a regular function and doesn't need to be passed in as a closure.
// available to downstream crates. This depends on whether we are in | ||
// share-generics mode and whether the current crate can even have | ||
// downstream crates. | ||
let export_generics = tcx.share_generics() && |
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.
It might be good to compute this value just once (because doesn't depend on the specific mono-item) and pass it in as a simple boolean parameter.
// FIXME: eventually we don't want to always force this symbol to have | ||
// hidden visibility, it should indeed be a candidate for | ||
// internalization, but we have to understand that it's referenced | ||
// from the `main` symbol we'll generate 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.
This might be solvable by have a special InstanceDef
variant, like we have for all the shims...
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.
(Just thinking aloud, no action needed here)
The previous iteration was a large `match` which was quite heavily indented, making it slightly difficult to read and see what was going on. This iteration is a refactoring (no functional change intended) to make it a bit easier on the eyes and a bit easier to modify over time.
236adc0
to
4afcb44
Compare
@bors: r=michaelwoerister |
📌 Commit 4afcb44eb00575386162136f6ed715e8659240f9 has been approved by |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
@bors: r- |
This commit tweaks the linker-level visibility of some lang items that rustc uses and defines. Notably this means that `#[panic_implementation]` and `#[alloc_error_handler]` functions are never marked as `internal`. It's up to the linker to eliminate these, not rustc. Additionally `#[global_allocator]` generated symbols are no longer forced to `Default` visibility (fully exported), but rather they're relaxed to `Hidden` visibility). This symbols are *not* needed across DLL boundaries, only as a local implementation detail of the compiler-injected allocator symbols, so `Hidden` should suffice. Closes rust-lang#51342 Closes rust-lang#52795
4afcb44
to
7c58ab6
Compare
@bors: r=michaelwoerister |
📌 Commit 7c58ab6 has been approved by |
rustc: Tweak visibility of some lang items This commit tweaks the linker-level visibility of some lang items that rustc uses and defines. Notably this means that `#[panic_implementation]` and `#[alloc_error_handler]` functions are never marked as `internal`. It's up to the linker to eliminate these, not rustc. Additionally `#[global_allocator]` generated symbols are no longer forced to `Default` visibility (fully exported), but rather they're relaxed to `Hidden` visibility). This symbols are *not* needed across DLL boundaries, only as a local implementation detail of the compiler-injected allocator symbols, so `Hidden` should suffice. Closes #51342 Closes #52795
☀️ Test successful - status-appveyor, status-travis |
FWIW, this PR improved compile speed a bit on a couple of benchmarks, and regressed it on |
Intersting! I have a hunch for where the slowdown came from, I'll try to test it out. |
This is an attempt to recover a perf loss observed in rust-lang#52993 by making the result of the `codegen_fn_attrs` query cheap to clone as more and more parts of the compiler start to use this query.
Make `codegen_fn_attrs` query cheap to clone This is an attempt to recover a perf loss observed in #52993 by making the result of the `codegen_fn_attrs` query cheap to clone as more and more parts of the compiler start to use this query.
My attempt in #53499 to diagnose this unfortunately was unsuccessful |
This injected a bug that caused My current guess is that @alexcrichton was incorrect that " |
(BTW its certainly posslble that the correct fix here lies with |
This commit tweaks the linker-level visibility of some lang items that rustc
uses and defines. Notably this means that
#[panic_implementation]
and#[alloc_error_handler]
functions are never marked asinternal
. It's up tothe linker to eliminate these, not rustc.
Additionally
#[global_allocator]
generated symbols are no longer forced toDefault
visibility (fully exported), but rather they're relaxed toHidden
visibility). This symbols are not needed across DLL boundaries, only as a
local implementation detail of the compiler-injected allocator symbols, so
Hidden
should suffice.Closes #51342
Closes #52795