Skip to content

Commit 43381a2

Browse files
Rollup merge of rust-lang#102783 - RalfJung:tls, r=thomcc
sync thread_local key conditions exactly with what the macro uses This makes the `cfg` in `mod.rs` syntactically the same as those in `local.rs`. I don't think this should actually change anything, but seems better to be consistent? I looked into this due to rust-lang#102549, but this PR would make it *less* likely that `__OsLocalKeyInner` is going to get provided, so this cannot help with that issue. r? `@thomcc`
2 parents 3f3fcc6 + 5218e24 commit 43381a2

File tree

6 files changed

+29
-14
lines changed

6 files changed

+29
-14
lines changed

library/std/src/sys/unix/thread_local_dtor.rs

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
target_os = "redox",
1818
target_os = "emscripten"
1919
))]
20+
#[cfg_attr(target_family = "wasm", allow(unused))] // might remain unused depending on target details (e.g. wasm32-unknown-emscripten)
2021
pub unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern "C" fn(*mut u8)) {
2122
use crate::mem;
2223
use crate::sys_common::thread_local_dtor::register_dtor_fallback;

library/std/src/sys/unsupported/thread_local_dtor.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![unstable(feature = "thread_local_internals", issue = "none")]
22

3+
#[cfg_attr(target_family = "wasm", allow(unused))] // unused on wasm32-unknown-unknown
34
pub unsafe fn register_dtor(_t: *mut u8, _dtor: unsafe extern "C" fn(*mut u8)) {
45
// FIXME: right now there is no concept of "thread exit", but this is likely
56
// going to show up at some point in the form of an exported symbol that the

library/std/src/thread/local.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@ pub mod statik {
901901
}
902902

903903
#[doc(hidden)]
904-
#[cfg(target_thread_local)]
904+
#[cfg(all(target_thread_local, not(all(target_family = "wasm", not(target_feature = "atomics"))),))]
905905
pub mod fast {
906906
use super::lazy::LazyKeyInner;
907907
use crate::cell::Cell;
@@ -1037,7 +1037,10 @@ pub mod fast {
10371037
}
10381038

10391039
#[doc(hidden)]
1040-
#[cfg(not(target_thread_local))]
1040+
#[cfg(all(
1041+
not(target_thread_local),
1042+
not(all(target_family = "wasm", not(target_feature = "atomics"))),
1043+
))]
10411044
pub mod os {
10421045
use super::lazy::LazyKeyInner;
10431046
use crate::cell::Cell;

library/std/src/thread/mod.rs

+20-10
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@
150150
151151
#![stable(feature = "rust1", since = "1.0.0")]
152152
#![deny(unsafe_op_in_unsafe_fn)]
153+
// Under `test`, `__FastLocalKeyInner` seems unused.
154+
#![cfg_attr(test, allow(dead_code))]
153155

154156
#[cfg(all(test, not(target_os = "emscripten")))]
155157
mod tests;
@@ -192,32 +194,40 @@ pub use scoped::{scope, Scope, ScopedJoinHandle};
192194
#[stable(feature = "rust1", since = "1.0.0")]
193195
pub use self::local::{AccessError, LocalKey};
194196

195-
// Select the type used by the thread_local! macro to access TLS keys. There
196-
// are three types: "static", "fast", "OS". The "OS" thread local key
197+
// Provide the type used by the thread_local! macro to access TLS keys. This
198+
// needs to be kept in sync with the macro itself (in `local.rs`).
199+
// There are three types: "static", "fast", "OS". The "OS" thread local key
197200
// type is accessed via platform-specific API calls and is slow, while the "fast"
198201
// key type is accessed via code generated via LLVM, where TLS keys are set up
199202
// by the elf linker. "static" is for single-threaded platforms where a global
200203
// static is sufficient.
201204

202205
#[unstable(feature = "libstd_thread_internals", issue = "none")]
203-
#[cfg(target_thread_local)]
204206
#[cfg(not(test))]
207+
#[cfg(all(
208+
target_thread_local,
209+
not(all(target_family = "wasm", not(target_feature = "atomics"))),
210+
))]
205211
#[doc(hidden)]
206212
pub use self::local::fast::Key as __FastLocalKeyInner;
207-
#[unstable(feature = "libstd_thread_internals", issue = "none")]
208-
#[cfg(target_thread_local)]
209-
#[cfg(test)] // when building for tests, use real std's key
210-
pub use realstd::thread::__FastLocalKeyInner;
211213

214+
// when building for tests, use real std's type
212215
#[unstable(feature = "libstd_thread_internals", issue = "none")]
213-
#[cfg(target_thread_local)]
214216
#[cfg(test)]
215-
pub use self::local::fast::Key as __FastLocalKeyInnerUnused; // we import this anyway to silence 'unused' warnings
217+
#[cfg(all(
218+
target_thread_local,
219+
not(all(target_family = "wasm", not(target_feature = "atomics"))),
220+
))]
221+
pub use realstd::thread::__FastLocalKeyInner;
216222

217223
#[unstable(feature = "libstd_thread_internals", issue = "none")]
224+
#[cfg(all(
225+
not(target_thread_local),
226+
not(all(target_family = "wasm", not(target_feature = "atomics"))),
227+
))]
218228
#[doc(hidden)]
219-
#[cfg(not(target_thread_local))]
220229
pub use self::local::os::Key as __OsLocalKeyInner;
230+
221231
#[unstable(feature = "libstd_thread_internals", issue = "none")]
222232
#[cfg(all(target_family = "wasm", not(target_feature = "atomics")))]
223233
#[doc(hidden)]

src/test/ui/threads-sendsync/issue-43733-2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
// ignore-wasm32
12
// dont-check-compiler-stderr
2-
33
#![feature(cfg_target_thread_local, thread_local_internals)]
44

55
// On platforms *without* `#[thread_local]`, use

src/test/ui/threads-sendsync/issue-43733.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
// ignore-wasm32
12
// revisions: mir thir
23
// [thir]compile-flags: -Z thir-unsafeck
34
// normalize-stderr-test: "__FastLocalKeyInner::<T>::get" -> "$$LOCALKEYINNER::<T>::get"
45
// normalize-stderr-test: "__OsLocalKeyInner::<T>::get" -> "$$LOCALKEYINNER::<T>::get"
5-
66
#![feature(thread_local)]
77
#![feature(cfg_target_thread_local, thread_local_internals)]
88

0 commit comments

Comments
 (0)