about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-05-23 14:53:41 +0000
committerbors <bors@rust-lang.org>2024-05-23 14:53:41 +0000
commit9c8a58fdb895204cb19eeb97472a78caa1c57c19 (patch)
tree1eea71e3acb3d157f9e03493a8a65b997aec03f7 /tests
parented172dbbaf1c702b99da54554b33b3fe65021da9 (diff)
parent60bf1ab46687a41f92a39d9bddcde5a2a0cd8c15 (diff)
downloadrust-9c8a58fdb895204cb19eeb97472a78caa1c57c19.tar.gz
rust-9c8a58fdb895204cb19eeb97472a78caa1c57c19.zip
Auto merge of #116123 - joboet:rewrite_native_tls, r=m-ou-se
Rewrite native thread-local storage

(part of #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](https://github.com/rust-lang/rust/issues/110897#issuecomment-1525705682), 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
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/threads-sendsync/issue-43733-2.rs30
-rw-r--r--tests/ui/threads-sendsync/issue-43733.rs32
-rw-r--r--tests/ui/threads-sendsync/issue-43733.stderr19
3 files changed, 0 insertions, 81 deletions
diff --git a/tests/ui/threads-sendsync/issue-43733-2.rs b/tests/ui/threads-sendsync/issue-43733-2.rs
deleted file mode 100644
index 372ebf2cff9..00000000000
--- a/tests/ui/threads-sendsync/issue-43733-2.rs
+++ /dev/null
@@ -1,30 +0,0 @@
-//@ needs-threads
-//@ dont-check-compiler-stderr
-#![feature(cfg_target_thread_local, thread_local_internals)]
-
-// On platforms *without* `#[thread_local]`, use
-// a custom non-`Sync` type to fake the same error.
-#[cfg(not(target_thread_local))]
-struct Key<T> {
-    _data: std::cell::UnsafeCell<Option<T>>,
-    _flag: std::cell::Cell<()>,
-}
-
-#[cfg(not(target_thread_local))]
-impl<T> Key<T> {
-    const fn new() -> Self {
-        Key {
-            _data: std::cell::UnsafeCell::new(None),
-            _flag: std::cell::Cell::new(()),
-        }
-    }
-}
-
-#[cfg(target_thread_local)]
-use std::thread::local_impl::Key;
-
-static __KEY: Key<()> = Key::new();
-//~^ ERROR `UnsafeCell<Option<()>>` cannot be shared between threads
-//~| ERROR cannot be shared between threads safely [E0277]
-
-fn main() {}
diff --git a/tests/ui/threads-sendsync/issue-43733.rs b/tests/ui/threads-sendsync/issue-43733.rs
deleted file mode 100644
index c90f60887cf..00000000000
--- a/tests/ui/threads-sendsync/issue-43733.rs
+++ /dev/null
@@ -1,32 +0,0 @@
-//@ needs-threads
-#![feature(thread_local)]
-#![feature(cfg_target_thread_local, thread_local_internals)]
-
-use std::cell::RefCell;
-
-type Foo = std::cell::RefCell<String>;
-
-#[cfg(target_thread_local)]
-#[thread_local]
-static __KEY: std::thread::local_impl::Key<Foo> = std::thread::local_impl::Key::new();
-
-#[cfg(not(target_thread_local))]
-static __KEY: std::thread::local_impl::Key<Foo> = std::thread::local_impl::Key::new();
-
-fn __getit(_: Option<&mut Option<RefCell<String>>>) -> std::option::Option<&'static Foo> {
-    __KEY.get(Default::default)
-    //~^ ERROR call to unsafe function `Key::<T>::get` is unsafe
-}
-
-static FOO: std::thread::LocalKey<Foo> = std::thread::LocalKey::new(__getit);
-//~^ ERROR call to unsafe function `LocalKey::<T>::new` is unsafe
-
-fn main() {
-    FOO.with(|foo| println!("{}", foo.borrow()));
-    std::thread::spawn(|| {
-        FOO.with(|foo| *foo.borrow_mut() += "foo");
-    })
-    .join()
-    .unwrap();
-    FOO.with(|foo| println!("{}", foo.borrow()));
-}
diff --git a/tests/ui/threads-sendsync/issue-43733.stderr b/tests/ui/threads-sendsync/issue-43733.stderr
deleted file mode 100644
index 9b13646a228..00000000000
--- a/tests/ui/threads-sendsync/issue-43733.stderr
+++ /dev/null
@@ -1,19 +0,0 @@
-error[E0133]: call to unsafe function `Key::<T>::get` is unsafe and requires unsafe function or block
-  --> $DIR/issue-43733.rs:17:5
-   |
-LL |     __KEY.get(Default::default)
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function
-   |
-   = note: consult the function's documentation for information on how to avoid undefined behavior
-
-error[E0133]: call to unsafe function `LocalKey::<T>::new` is unsafe and requires unsafe function or block
-  --> $DIR/issue-43733.rs:21:42
-   |
-LL | static FOO: std::thread::LocalKey<Foo> = std::thread::LocalKey::new(__getit);
-   |                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function
-   |
-   = note: consult the function's documentation for information on how to avoid undefined behavior
-
-error: aborting due to 2 previous errors
-
-For more information about this error, try `rustc --explain E0133`.