Skip to content

Commit 503706f

Browse files
committed
Auto merge of rust-lang#116123 - joboet:rewrite_native_tls, r=<try>
Rewrite native thread-local storage (part of rust-lang#110897) The current native thread-local storage implementation has become quite messy, uses indescriptive names and unnecessarily adds code to the macro expansion. This PR tries to fix that by using a new implementation that also allows more layout optimizations and potentially increases performance by eliminating unnecessary TLS accesses. This does not change the recursive initialization behaviour I described in [this comment](rust-lang#110897 (comment)), so it should be a library-only change. Changing that behaviour should be quite easy now, however. r? `@m-ou-se` `@rustbot` label +T-libs
2 parents 774ae59 + a087a37 commit 503706f

File tree

9 files changed

+336
-355
lines changed

9 files changed

+336
-355
lines changed

library/std/src/sys/thread_local/fast_local.rs

+244-188
Large diffs are not rendered by default.

library/std/src/sys/thread_local/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ cfg_if::cfg_if! {
1515
#[doc(hidden)]
1616
mod fast_local;
1717
#[doc(hidden)]
18-
pub use fast_local::{Key, thread_local_inner};
18+
pub use fast_local::{Storage, take_or_call, thread_local_inner};
1919
} else {
2020
#[doc(hidden)]
2121
mod os_local;
@@ -24,6 +24,9 @@ cfg_if::cfg_if! {
2424
}
2525
}
2626

27+
// Not used by the fast-local TLS anymore.
28+
// FIXME(#110897): remove this.
29+
#[allow(unused)]
2730
mod lazy {
2831
use crate::cell::UnsafeCell;
2932
use crate::hint;

library/std/src/thread/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ cfg_if::cfg_if! {
205205
#[doc(hidden)]
206206
#[unstable(feature = "thread_local_internals", issue = "none")]
207207
pub mod local_impl {
208-
pub use crate::sys::thread_local::{thread_local_inner, Key, abort_on_dtor_unwind};
208+
pub use crate::sys::thread_local::*;
209209
}
210210
}
211211
}

src/tools/tidy/src/issues.txt

-2
Original file line numberDiff line numberDiff line change
@@ -4009,8 +4009,6 @@
40094009
"ui/test-attrs/issue-53675-a-test-called-panic.rs",
40104010
"ui/threads-sendsync/issue-24313.rs",
40114011
"ui/threads-sendsync/issue-29488.rs",
4012-
"ui/threads-sendsync/issue-43733-2.rs",
4013-
"ui/threads-sendsync/issue-43733.rs",
40144012
"ui/threads-sendsync/issue-4446.rs",
40154013
"ui/threads-sendsync/issue-4448.rs",
40164014
"ui/threads-sendsync/issue-8827.rs",

tests/ui/suggestions/missing-lifetime-specifier.rs

+18-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
// different number of duplicated diagnostics on different targets
2-
//@ only-x86_64
3-
//@ only-linux
1+
// The specific errors produced depend the thread-local implementation.
2+
// Run only on platforms with "fast" TLS.
3+
//@ ignore-windows FIXME(#84933)
4+
//@ ignore-wasm globals are used instead of thread locals
5+
//@ ignore-emscripten globals are used instead of thread locals
6+
//@ ignore-android does not use #[thread_local]
7+
//@ ignore-nto does not use #[thread_local]
8+
// Different number of duplicated diagnostics on different targets
49
//@ compile-flags: -Zdeduplicate-diagnostics=yes
510

611
#![allow(bare_trait_objects)]
@@ -20,31 +25,31 @@ pub union Qux<'t, 'k, I> {
2025
trait Tar<'t, 'k, I> {}
2126

2227
thread_local! {
23-
//~^ ERROR lifetime may not live long enough
24-
//~| ERROR lifetime may not live long enough
28+
//~^ ERROR borrowed data escapes outside of function
29+
//~| ERROR borrowed data escapes outside of function
2530
static a: RefCell<HashMap<i32, Vec<Vec<Foo>>>> = RefCell::new(HashMap::new());
2631
//~^ ERROR missing lifetime specifiers
2732
//~| ERROR missing lifetime specifiers
2833
}
2934
thread_local! {
30-
//~^ ERROR lifetime may not live long enough
31-
//~| ERROR lifetime may not live long enough
32-
//~| ERROR lifetime may not live long enough
35+
//~^ ERROR borrowed data escapes outside of function
36+
//~| ERROR borrowed data escapes outside of function
37+
//~| ERROR borrowed data escapes outside of function
3338
static b: RefCell<HashMap<i32, Vec<Vec<&Bar>>>> = RefCell::new(HashMap::new());
3439
//~^ ERROR missing lifetime specifiers
3540
//~| ERROR missing lifetime specifiers
3641
}
3742
thread_local! {
38-
//~^ ERROR lifetime may not live long enough
39-
//~| ERROR lifetime may not live long enough
43+
//~^ ERROR borrowed data escapes outside of function
44+
//~| ERROR borrowed data escapes outside of function
4045
static c: RefCell<HashMap<i32, Vec<Vec<Qux<i32>>>>> = RefCell::new(HashMap::new());
4146
//~^ ERROR missing lifetime specifiers
4247
//~| ERROR missing lifetime specifiers
4348
}
4449
thread_local! {
45-
//~^ ERROR lifetime may not live long enough
46-
//~| ERROR lifetime may not live long enough
47-
//~| ERROR lifetime may not live long enough
50+
//~^ ERROR borrowed data escapes outside of function
51+
//~| ERROR borrowed data escapes outside of function
52+
//~| ERROR borrowed data escapes outside of function
4853
static d: RefCell<HashMap<i32, Vec<Vec<&Tar<i32>>>>> = RefCell::new(HashMap::new());
4954
//~^ ERROR missing lifetime specifiers
5055
//~| ERROR missing lifetime specifiers

0 commit comments

Comments
 (0)