Closed
Description
The WorkerLocal
type used in the parallel-compiler
cfg:
which comes from the Rust fork of rayon, rustc-rayon, implements Send
and Sync
unconditionally for all types T
:
/// Holds worker-locals values for each thread in a thread pool.
/// You can only access the worker local value through the Deref impl
/// on the thread pool it was constructed on. It will panic otherwise
pub struct WorkerLocal<T> {
locals: Vec<CacheAligned<T>>,
registry: Arc<Registry>,
}
unsafe impl<T> Send for WorkerLocal<T> {}
unsafe impl<T> Sync for WorkerLocal<T> {}
While all the current inhabitants of the type T
in rustc are sound, as in they are safe to send across threads, this allows for the potential of data races if someone accidentally uses a non-Send
type such as Rc
in a WorkerLocal
.
As per @cuviper in #t-compiler/wg-parallel-rustc on Zulip, this should be bound by T: Send
. https://rust-lang.zulipchat.com/#narrow/stream/187679-t-compiler.2Fwg-parallel-rustc/topic/WorkerLocal.20type.20in.20rustc.20rayon.20fork/near/224118580