-
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
Use UnsafeCell
for fast constant thread locals
#122583
Conversation
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 good to me! Could you also remove the FIXME and the #[allow(static_mut_ref)]
in line 16-18? They are no longer needed thanks to this change.
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'm very confused by that one comment..
Thank you! |
…enton Rollup of 7 pull requests Successful merges: - rust-lang#122323 (configure.py: add flag for loongarch64 musl-root) - rust-lang#122372 (prevent notifying the same changes more than once) - rust-lang#122390 (Bump windows-bindgen to 0.55.0) - rust-lang#122401 (Check library crates for all tier 1 targets in PR CI) - rust-lang#122489 (Bump `cargo update` PR more often) - rust-lang#122583 (Use `UnsafeCell` for fast constant thread locals) - rust-lang#122590 (bootstrap: Don't name things copy that are not copies) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#122583 - Zoxc:tls-non-mut, r=joboet Use `UnsafeCell` for fast constant thread locals This uses `UnsafeCell` instead of `static mut` for fast constant thread locals. This changes the type of the TLS shims to return `&UnsafeCell<T>` instead of `*mut T` which means they are always non-null so LLVM can optimize away the check for `Some` in `LocalKey::with` if `T` has no destructor. LLVM is currently unable to do this optimization as we lose the fact that `__getit` always returns `Some` as it gets optimized to just returning the value of the TLS shim.
This uses
UnsafeCell
instead ofstatic mut
for fast constant thread locals. This changes the type of the TLS shims to return&UnsafeCell<T>
instead of*mut T
which means they are always non-null so LLVM can optimize away the check forSome
inLocalKey::with
ifT
has no destructor.LLVM is currently unable to do this optimization as we lose the fact that
__getit
always returnsSome
as it gets optimized to just returning the value of the TLS shim.