From bee28ef7b23f48b759ce6c358a50cba5d24698d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Thu, 12 Mar 2026 14:24:32 +0100 Subject: [PATCH] Remove `MTLock` --- compiler/rustc_data_structures/src/sync.rs | 37 ------------------- compiler/rustc_monomorphize/src/collector.rs | 22 +++++------ src/doc/rustc-dev-guide/src/parallel-rustc.md | 1 - 3 files changed, 11 insertions(+), 49 deletions(-) diff --git a/compiler/rustc_data_structures/src/sync.rs b/compiler/rustc_data_structures/src/sync.rs index 31768fe189ae..327c28fd1389 100644 --- a/compiler/rustc_data_structures/src/sync.rs +++ b/compiler/rustc_data_structures/src/sync.rs @@ -21,11 +21,6 @@ //! | `Lock` | `RefCell` | `RefCell` or | //! | | | `parking_lot::Mutex` | //! | `RwLock` | `RefCell` | `parking_lot::RwLock` | -//! | `MTLock` [^1] | `T` | `Lock` | -//! -//! [^1]: `MTLock` is similar to `Lock`, but the serial version avoids the cost -//! of a `RefCell`. This is appropriate when interior mutability is not -//! required. use std::collections::HashMap; use std::hash::{BuildHasher, Hash}; @@ -106,38 +101,6 @@ pub fn set_dyn_thread_safe_mode(mode: bool) { } } -// FIXME(parallel_compiler): Get rid of these aliases across the compiler. - -#[derive(Debug, Default)] -pub struct MTLock(Lock); - -impl MTLock { - #[inline(always)] - pub fn new(inner: T) -> Self { - MTLock(Lock::new(inner)) - } - - #[inline(always)] - pub fn into_inner(self) -> T { - self.0.into_inner() - } - - #[inline(always)] - pub fn get_mut(&mut self) -> &mut T { - self.0.get_mut() - } - - #[inline(always)] - pub fn lock(&self) -> LockGuard<'_, T> { - self.0.lock() - } - - #[inline(always)] - pub fn lock_mut(&self) -> LockGuard<'_, T> { - self.lock() - } -} - /// This makes locks panic if they are already held. /// It is only useful when you are running in a single thread const ERROR_CHECKING: bool = false; diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index f6bb70b21446..8bd6730ab0eb 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -209,7 +209,7 @@ use std::ops::ControlFlow; use rustc_data_structures::fx::FxIndexMap; -use rustc_data_structures::sync::{MTLock, par_for_each_in}; +use rustc_data_structures::sync::{Lock, par_for_each_in}; use rustc_data_structures::unord::{UnordMap, UnordSet}; use rustc_hir as hir; use rustc_hir::attrs::InlineAttr; @@ -251,12 +251,12 @@ pub(crate) enum MonoItemCollectionStrategy { /// The state that is shared across the concurrent threads that are doing collection. struct SharedState<'tcx> { /// Items that have been or are currently being recursively collected. - visited: MTLock>>, + visited: Lock>>, /// Items that have been or are currently being recursively treated as "mentioned", i.e., their /// consts are evaluated but nothing is added to the collection. - mentioned: MTLock>>, + mentioned: Lock>>, /// Which items are being used where, for better errors. - usage_map: MTLock>, + usage_map: Lock>, } pub(crate) struct UsageMap<'tcx> { @@ -359,7 +359,7 @@ fn collect_items_root<'tcx>( state: &SharedState<'tcx>, recursion_limit: Limit, ) { - if !state.visited.lock_mut().insert(starting_item.node) { + if !state.visited.lock().insert(starting_item.node) { // We've been here already, no need to search again. return; } @@ -568,7 +568,7 @@ fn collect_items_rec<'tcx>( // This is part of the output of collection and hence only relevant for "used" items. // ("Mentioned" items are only considered internally during collection.) if mode == CollectionMode::UsedItems { - state.usage_map.lock_mut().record_used(starting_item.node, &used_items); + state.usage_map.lock().record_used(starting_item.node, &used_items); } { @@ -576,13 +576,13 @@ fn collect_items_rec<'tcx>( if mode == CollectionMode::UsedItems { used_items .items - .retain(|k, _| visited.get_mut_or_init(|| state.visited.lock_mut()).insert(*k)); + .retain(|k, _| visited.get_mut_or_init(|| state.visited.lock()).insert(*k)); } let mut mentioned = OnceCell::default(); mentioned_items.items.retain(|k, _| { !visited.get_or_init(|| state.visited.lock()).contains(k) - && mentioned.get_mut_or_init(|| state.mentioned.lock_mut()).insert(*k) + && mentioned.get_mut_or_init(|| state.mentioned.lock()).insert(*k) }); } if mode == CollectionMode::MentionedItems { @@ -1810,9 +1810,9 @@ pub(crate) fn collect_crate_mono_items<'tcx>( debug!("building mono item graph, beginning at roots"); let state = SharedState { - visited: MTLock::new(UnordSet::default()), - mentioned: MTLock::new(UnordSet::default()), - usage_map: MTLock::new(UsageMap::new()), + visited: Lock::new(UnordSet::default()), + mentioned: Lock::new(UnordSet::default()), + usage_map: Lock::new(UsageMap::new()), }; let recursion_limit = tcx.recursion_limit(); diff --git a/src/doc/rustc-dev-guide/src/parallel-rustc.md b/src/doc/rustc-dev-guide/src/parallel-rustc.md index ce69b66c2daf..f83aaa639ecc 100644 --- a/src/doc/rustc-dev-guide/src/parallel-rustc.md +++ b/src/doc/rustc-dev-guide/src/parallel-rustc.md @@ -48,7 +48,6 @@ are implemented differently depending on whether `parallel-compiler` is true. | -------------------------------- | --------------------------------------------------- | ------------ | | Lock\ | (parking_lot::Mutex\) | (std::cell::RefCell) | | RwLock\ | (parking_lot::RwLock\) | (std::cell::RefCell) | -| MTLock\ | (Lock\) | (T) | | ReadGuard | parking_lot::RwLockReadGuard | std::cell::Ref | | MappedReadGuard | parking_lot::MappedRwLockReadGuard | std::cell::Ref | | WriteGuard | parking_lot::RwLockWriteGuard | std::cell::RefMut |