Skip to content

Commit f7b31e9

Browse files
Rollup merge of rust-lang#137996 - safinaskar:2025-03-04-revert-parallel, r=compiler-errors
Revert "compiler/rustc_data_structures/src/sync/worker_local.rs: delete "unsafe impl Sync"" Revert "compiler/rustc_data_structures/src/sync/worker_local.rs: delete "unsafe impl Sync"" This reverts commit 0240690. See rust-lang#136858 (comment) cc "Parallel Rustc Front-end" rust-lang#113349 r? SparrowLii `@rustbot` label: +WG-compiler-parallel `@rustbot` label: +C-cleanup
2 parents 4e102f8 + c6c4ea4 commit f7b31e9

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

compiler/rustc_data_structures/src/sync/worker_local.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ pub struct WorkerLocal<T> {
106106
registry: Registry,
107107
}
108108

109+
// This is safe because the `deref` call will return a reference to a `T` unique to each thread
110+
// or it will panic for threads without an associated local. So there isn't a need for `T` to do
111+
// it's own synchronization. The `verify` method on `RegistryId` has an issue where the id
112+
// can be reused, but `WorkerLocal` has a reference to `Registry` which will prevent any reuse.
113+
unsafe impl<T: Send> Sync for WorkerLocal<T> {}
114+
109115
impl<T> WorkerLocal<T> {
110116
/// Creates a new worker local where the `initial` closure computes the
111117
/// value this worker local should take for each thread in the registry.
@@ -132,11 +138,6 @@ impl<T> Deref for WorkerLocal<T> {
132138
fn deref(&self) -> &T {
133139
// This is safe because `verify` will only return values less than
134140
// `self.registry.thread_limit` which is the size of the `self.locals` array.
135-
136-
// The `deref` call will return a reference to a `T` unique to each thread
137-
// or it will panic for threads without an associated local. So there isn't a need for `T` to do
138-
// it's own synchronization. The `verify` method on `RegistryId` has an issue where the id
139-
// can be reused, but `WorkerLocal` has a reference to `Registry` which will prevent any reuse.
140141
unsafe { &self.locals.get_unchecked(self.registry.id().verify()).0 }
141142
}
142143
}

0 commit comments

Comments
 (0)