Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
dd50e18
Revert "Update `rustc-perf` submodule before running tidy"
onur-ozkan Jun 10, 2024
f3facf1
std: refactor the TLS implementation
joboet Jun 15, 2024
e9e3c38
tidy: skip submodules if not present for non-CI environments
onur-ozkan Jun 10, 2024
d70f071
std: simplify `#[cfg]`s for TLS
joboet Jun 17, 2024
b2f29ed
std: use the `c_int` from `core::ffi` instead of `libc`
joboet Jun 17, 2024
35f050b
std: update TLS module documentation
joboet Jun 17, 2024
32f9b8b
std: rename module for clarity
joboet Jun 17, 2024
455e2f9
Update outdated README in build-manifest.
ehuss Jun 17, 2024
f76c3b7
replace `remove_dir` with `remove_dir_all` in `helpers::symlink_dir`
onur-ozkan Jun 17, 2024
521e707
make codegen-backend config warning less noisy
onur-ozkan Jun 18, 2024
279bf05
remove `GIT_DIR` handling in pre-push hook
onur-ozkan Jun 19, 2024
0937996
make unsized_fn_params an internal feature
RalfJung Jun 22, 2024
763e313
don't ICE when encountering an extern type field during validation
RalfJung Jun 22, 2024
0a26595
delegation: Do not crash on qpaths without a trait
petrochenkov Jun 22, 2024
470b0e9
Import `NonterminalKind` in `compiler/rustc_expand/src/mbe/quoted.rs`.
nnethercote Jun 22, 2024
70fa67c
Tweak some ugly formatting.
nnethercote Jun 22, 2024
e2aa38e
Rework pattern and expression nonterminal kinds.
nnethercote Jun 22, 2024
ed0ba52
Rollup merge of #126230 - onur-ozkan:followup-126225, r=Mark-Simulacrum
compiler-errors Jun 23, 2024
18c2de0
Rollup merge of #126523 - joboet:the_great_big_tls_refactor, r=Mark-S…
compiler-errors Jun 23, 2024
b56b0e9
Rollup merge of #126612 - ehuss:build-manifest-readme, r=Mark-Simulacrum
compiler-errors Jun 23, 2024
bcb3e12
Rollup merge of #126616 - onur-ozkan:less-warnings, r=Mark-Simulacrum
compiler-errors Jun 23, 2024
fa67bfd
Rollup merge of #126663 - onur-ozkan:gitdir-thing, r=Mark-Simulacrum
compiler-errors Jun 23, 2024
7c3c544
Rollup merge of #126830 - RalfJung:unsized-fn-params, r=compiler-errors
compiler-errors Jun 23, 2024
f8c2e06
Rollup merge of #126833 - RalfJung:extern-type-field-ice, r=compiler-…
compiler-errors Jun 23, 2024
f0897c9
Rollup merge of #126837 - petrochenkov:delegfix, r=compiler-errors
compiler-errors Jun 23, 2024
073e768
Rollup merge of #126851 - nnethercote:NtExprKind-NtPatKind, r=compile…
compiler-errors Jun 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
std: refactor the TLS implementation
As discovered by Mara in #110897, our TLS implementation is a total mess. In the past months, I have simplified the actual macros and their expansions, but the majority of the complexity comes from the platform-specific support code needed to create keys and register destructors. In keeping with #117276, I have therefore moved all of the `thread_local_key`/`thread_local_dtor` modules to the `thread_local` module in `sys` and merged them into a new structure, so that future porters of `std` can simply mix-and-match the existing code instead of having to copy the same (bad) implementation everywhere. The new structure should become obvious when looking at `sys/thread_local/mod.rs`.

Unfortunately, the documentation changes associated with the refactoring have made this PR rather large. That said, this contains no functional changes except for two small ones:
* the key-based destructor fallback now, by virtue of sharing the implementation used by macOS and others, stores its list in a `#[thread_local]` static instead of in the key, eliminating one indirection layer and drastically simplifying its code.
* I've switched over ZKVM (tier 3) to use the same implementation as WebAssembly, as the implementation was just a way worse version of that

Please let me know if I can make this easier to review! I know these large PRs aren't optimal, but I couldn't think of any good intermediate steps.

@rustbot label +A-thread-locals
  • Loading branch information
joboet committed Jun 15, 2024
commit f3facf11758af878bcfaf47fc773962dbb565024
6 changes: 1 addition & 5 deletions library/std/src/sys/pal/hermit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ pub mod pipe;
pub mod process;
pub mod stdio;
pub mod thread;
pub mod thread_local_dtor;
#[path = "../unsupported/thread_local_key.rs"]
pub mod thread_local_key;
pub mod time;

use crate::io::ErrorKind;
Expand Down Expand Up @@ -98,7 +95,6 @@ pub unsafe extern "C" fn runtime_entry(
argv: *const *const c_char,
env: *const *const c_char,
) -> ! {
use thread_local_dtor::run_dtors;
extern "C" {
fn main(argc: isize, argv: *const *const c_char) -> i32;
}
Expand All @@ -108,7 +104,7 @@ pub unsafe extern "C" fn runtime_entry(

let result = main(argc as isize, argv);

run_dtors();
crate::sys::thread_local::destructors::run();
hermit_abi::exit(result);
}

Expand Down
3 changes: 1 addition & 2 deletions library/std/src/sys/pal/hermit/thread.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#![allow(dead_code)]

use super::hermit_abi;
use super::thread_local_dtor::run_dtors;
use crate::ffi::CStr;
use crate::io;
use crate::mem;
Expand Down Expand Up @@ -50,7 +49,7 @@ impl Thread {
Box::from_raw(ptr::with_exposed_provenance::<Box<dyn FnOnce()>>(main).cast_mut())();

// run all destructors
run_dtors();
crate::sys::thread_local::destructors::run();
}
}
}
Expand Down
29 changes: 0 additions & 29 deletions library/std/src/sys/pal/hermit/thread_local_dtor.rs

This file was deleted.

3 changes: 1 addition & 2 deletions library/std/src/sys/pal/itron/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use crate::{
num::NonZero,
ptr::NonNull,
sync::atomic::{AtomicUsize, Ordering},
sys::thread_local_dtor::run_dtors,
time::Duration,
};

Expand Down Expand Up @@ -116,7 +115,7 @@ impl Thread {

// Run TLS destructors now because they are not
// called automatically for terminated tasks.
unsafe { run_dtors() };
unsafe { crate::sys::thread_local::destructors::run() };

let old_lifecycle = inner
.lifecycle
Expand Down
1 change: 0 additions & 1 deletion library/std/src/sys/pal/sgx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ pub mod pipe;
pub mod process;
pub mod stdio;
pub mod thread;
pub mod thread_local_key;
pub mod thread_parking;
pub mod time;
pub mod waitqueue;
Expand Down
2 changes: 0 additions & 2 deletions library/std/src/sys/pal/solid/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ pub mod pipe;
pub mod process;
pub mod stdio;
pub use self::itron::thread;
pub mod thread_local_dtor;
pub mod thread_local_key;
pub use self::itron::thread_parking;
pub mod time;

Expand Down
43 changes: 0 additions & 43 deletions library/std/src/sys/pal/solid/thread_local_dtor.rs

This file was deleted.

21 changes: 0 additions & 21 deletions library/std/src/sys/pal/solid/thread_local_key.rs

This file was deleted.

3 changes: 0 additions & 3 deletions library/std/src/sys/pal/teeos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ pub mod process;
mod rand;
pub mod stdio;
pub mod thread;
pub mod thread_local_dtor;
#[path = "../unix/thread_local_key.rs"]
pub mod thread_local_key;
#[allow(non_upper_case_globals)]
#[path = "../unix/time.rs"]
pub mod time;
Expand Down
4 changes: 0 additions & 4 deletions library/std/src/sys/pal/teeos/thread_local_dtor.rs

This file was deleted.

2 changes: 0 additions & 2 deletions library/std/src/sys/pal/uefi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ pub mod pipe;
pub mod process;
pub mod stdio;
pub mod thread;
#[path = "../unsupported/thread_local_key.rs"]
pub mod thread_local_key;
pub mod time;

mod helpers;
Expand Down
2 changes: 0 additions & 2 deletions library/std/src/sys/pal/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ pub mod rand;
pub mod stack_overflow;
pub mod stdio;
pub mod thread;
pub mod thread_local_dtor;
pub mod thread_local_key;
pub mod thread_parking;
pub mod time;

Expand Down
126 changes: 0 additions & 126 deletions library/std/src/sys/pal/unix/thread_local_dtor.rs

This file was deleted.

29 changes: 0 additions & 29 deletions library/std/src/sys/pal/unix/thread_local_key.rs

This file was deleted.

3 changes: 0 additions & 3 deletions library/std/src/sys/pal/unsupported/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ pub mod pipe;
pub mod process;
pub mod stdio;
pub mod thread;
#[cfg(target_thread_local)]
pub mod thread_local_dtor;
pub mod thread_local_key;
pub mod time;

mod common;
Expand Down
10 changes: 0 additions & 10 deletions library/std/src/sys/pal/unsupported/thread_local_dtor.rs

This file was deleted.

Loading