-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Allow unsafe_code in __thread_local_inner. #23579
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
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
@@ -205,6 +205,7 @@ macro_rules! __thread_local_inner { | |||
|
|||
#[cfg(any(not(any(target_os = "macos", target_os = "linux")), target_arch = "aarch64"))] | |||
const _INIT: ::std::thread_local::__impl::KeyInner<$t> = { | |||
#[allow(unsafe_code)] | |||
unsafe extern fn __destroy(ptr: *mut u8) { | |||
::std::thread_local::__impl::destroy_value::<$t>(ptr); |
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 one of the weird things I might have cleaned up in my post-const-fn branch - thread_local
definitely took the longest out of all of libstd.
Would using ::std::thread_local::__impl::destroy_value::<$t>
instead of __destroy
work at all?
Is it perhaps an ABI mismatch? If it is, can the destroy_value
definition be changed, instead?
Also, take great care in keeping consistency across the supported combinations (IMO they should go in separate files to avoid #[cfg]
confusion).
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.
Would using ::std::thread_local::__impl::destroy_value::<$t> instead of __destroy work at all?
Yeah that worked locally for me. I think that I may have just been playing around with various strategies and never revisited this.
@Ms2ger could you update the PR with something like:
diff --git a/src/libstd/thread_local/mod.rs b/src/libstd/thread_local/mod.rs
index 0878029..15cc469 100644
--- a/src/libstd/thread_local/mod.rs
+++ b/src/libstd/thread_local/mod.rs
@@ -205,15 +205,14 @@ macro_rules! __thread_local_inner {
#[cfg(any(not(any(target_os = "macos", target_os = "linux")), target_arch = "aarch64"))]
const _INIT: ::std::thread_local::__impl::KeyInner<$t> = {
- unsafe extern fn __destroy(ptr: *mut u8) {
- ::std::thread_local::__impl::destroy_value::<$t>(ptr);
- }
-
::std::thread_local::__impl::KeyInner {
inner: ::std::cell::UnsafeCell { value: $init },
os: ::std::thread_local::__impl::OsStaticKey {
inner: ::std::thread_local::__impl::OS_INIT_INNER,
- dtor: ::std::option::Option::Some(__destroy as unsafe extern fn(*mut u8)),
+ dtor: ::std::option::Option::Some(
+ ::std::thread_local::__impl::destroy_value::<$t>
+ as unsafe extern fn(*mut u8)
+ ),
},
}
};
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.
Nice, but do you still need the cast? I'm mainly asking because if you do, that looks like a bug/limitation in the "coerce to expected type" logic in typeck.
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.
Oh nice, it is no longer necessary as well!
This fixes a build error when using thread_local!() in a deny(unsafe_code) scope in Servo for Android.
86e649a
to
29aca83
Compare
⌛ Testing commit 29aca83 with merge 8692e1c... |
💔 Test failed - auto-win-64-opt |
@bors: retry |
Conflicts: src/libstd/thread/local.rs
This fixes a build error when using thread_local!() in a deny(unsafe_code)
scope in Servo for Android.