Remove some unnecessary aliases from rustc_data_structures::sync

With the removal of `cfg(parallel_compiler)`, these are always shared
references and `std::sync::OnceLock`.
This commit is contained in:
Zalathar 2025-03-03 20:17:26 +11:00
parent 5afd12239a
commit 32c5449d45
8 changed files with 23 additions and 39 deletions

View file

@ -18,21 +18,16 @@
//!
//! | Type | Serial version | Parallel version |
//! | ----------------------- | ------------------- | ------------------------------- |
//! | `LRef<'a, T>` [^2] | `&'a mut T` | `&'a T` |
//! | | | |
//! | `Lock<T>` | `RefCell<T>` | `RefCell<T>` or |
//! | | | `parking_lot::Mutex<T>` |
//! | `RwLock<T>` | `RefCell<T>` | `parking_lot::RwLock<T>` |
//! | `MTLock<T>` [^1] | `T` | `Lock<T>` |
//! | `MTLockRef<'a, T>` [^2] | `&'a mut MTLock<T>` | `&'a MTLock<T>` |
//! | | | |
//! | `ParallelIterator` | `Iterator` | `rayon::iter::ParallelIterator` |
//!
//! [^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.
//!
//! [^2]: `MTRef`, `MTLockRef` are type aliases.
use std::collections::HashMap;
use std::hash::{BuildHasher, Hash};
@ -97,7 +92,6 @@ mod mode {
// FIXME(parallel_compiler): Get rid of these aliases across the compiler.
pub use std::sync::OnceLock;
// Use portable AtomicU64 for targets without native 64-bit atomics
#[cfg(target_has_atomic = "64")]
pub use std::sync::atomic::AtomicU64;
@ -110,8 +104,6 @@ pub use parking_lot::{
#[cfg(not(target_has_atomic = "64"))]
pub use portable_atomic::AtomicU64;
pub type LRef<'a, T> = &'a T;
#[derive(Debug, Default)]
pub struct MTLock<T>(Lock<T>);
@ -148,8 +140,6 @@ use parking_lot::RwLock as InnerRwLock;
/// It is only useful when you are running in a single thread
const ERROR_CHECKING: bool = false;
pub type MTLockRef<'a, T> = LRef<'a, MTLock<T>>;
#[derive(Default)]
#[repr(align(64))]
pub struct CacheAligned<T>(pub T);

View file

@ -2,14 +2,14 @@ use std::any::Any;
use std::ffi::OsString;
use std::io::{self, BufWriter, Write};
use std::path::{Path, PathBuf};
use std::sync::{Arc, LazyLock};
use std::sync::{Arc, LazyLock, OnceLock};
use std::{env, fs, iter};
use rustc_ast as ast;
use rustc_codegen_ssa::traits::CodegenBackend;
use rustc_data_structures::parallel;
use rustc_data_structures::steal::Steal;
use rustc_data_structures::sync::{AppendOnlyIndexVec, FreezeLock, OnceLock, WorkerLocal};
use rustc_data_structures::sync::{AppendOnlyIndexVec, FreezeLock, WorkerLocal};
use rustc_expand::base::{ExtCtxt, LintStoreExpand};
use rustc_feature::Features;
use rustc_fs_util::try_canonicalize;

View file

@ -2,7 +2,7 @@
use std::iter::TrustedLen;
use std::path::Path;
use std::sync::Arc;
use std::sync::{Arc, OnceLock};
use std::{io, iter, mem};
pub(super) use cstore_impl::provide;
@ -11,7 +11,7 @@ use rustc_ast as ast;
use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::fx::FxIndexMap;
use rustc_data_structures::owned_slice::OwnedSlice;
use rustc_data_structures::sync::{Lock, OnceLock};
use rustc_data_structures::sync::Lock;
use rustc_data_structures::unhash::UnhashMap;
use rustc_expand::base::{SyntaxExtension, SyntaxExtensionKind};
use rustc_expand::proc_macro::{AttrProcMacro, BangProcMacro, DeriveProcMacro};

View file

@ -1,8 +1,9 @@
use std::sync::OnceLock;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::graph;
use rustc_data_structures::graph::dominators::{Dominators, dominators};
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_data_structures::sync::OnceLock;
use rustc_index::{IndexSlice, IndexVec};
use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable};
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};

View file

@ -209,7 +209,7 @@ use std::path::PathBuf;
use rustc_attr_parsing::InlineAttr;
use rustc_data_structures::fx::FxIndexMap;
use rustc_data_structures::sync::{LRef, MTLock, par_for_each_in};
use rustc_data_structures::sync::{MTLock, par_for_each_in};
use rustc_data_structures::unord::{UnordMap, UnordSet};
use rustc_hir as hir;
use rustc_hir::def::DefKind;
@ -357,7 +357,7 @@ impl<'tcx> Extend<Spanned<MonoItem<'tcx>>> for MonoItems<'tcx> {
fn collect_items_rec<'tcx>(
tcx: TyCtxt<'tcx>,
starting_item: Spanned<MonoItem<'tcx>>,
state: LRef<'_, SharedState<'tcx>>,
state: &SharedState<'tcx>,
recursion_depths: &mut DefIdMap<usize>,
recursion_limit: Limit,
mode: CollectionMode,
@ -1671,30 +1671,26 @@ pub(crate) fn collect_crate_mono_items<'tcx>(
debug!("building mono item graph, beginning at roots");
let mut state = SharedState {
let state = SharedState {
visited: MTLock::new(UnordSet::default()),
mentioned: MTLock::new(UnordSet::default()),
usage_map: MTLock::new(UsageMap::new()),
};
let recursion_limit = tcx.recursion_limit();
{
let state: LRef<'_, _> = &mut state;
tcx.sess.time("monomorphization_collector_graph_walk", || {
par_for_each_in(roots, |root| {
let mut recursion_depths = DefIdMap::default();
collect_items_rec(
tcx,
dummy_spanned(root),
state,
&state,
&mut recursion_depths,
recursion_limit,
CollectionMode::UsedItems,
);
});
});
}
// The set of MonoItems was created in an inherently indeterministic order because
// of parallelism. We sort it here to ensure that the output is deterministic.

View file

@ -1,9 +1,9 @@
use std::fmt::Debug;
use std::hash::Hash;
use std::sync::OnceLock;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::sharded::{self, Sharded};
use rustc_data_structures::sync::OnceLock;
pub use rustc_data_structures::vec_cache::VecCache;
use rustc_hir::def_id::LOCAL_CRATE;
use rustc_index::Idx;

View file

@ -46,10 +46,8 @@ are implemented differently depending on whether `parallel-compiler` is true.
| data structure | parallel | non-parallel |
| -------------------------------- | --------------------------------------------------- | ------------ |
| OnceCell | std::sync::OnceLock | std::cell::OnceCell |
| Lock\<T> | (parking_lot::Mutex\<T>) | (std::cell::RefCell) |
| RwLock\<T> | (parking_lot::RwLock\<T>) | (std::cell::RefCell) |
| MTRef<'a, T> | &'a T | &'a mut T |
| MTLock\<T> | (Lock\<T>) | (T) |
| ReadGuard | parking_lot::RwLockReadGuard | std::cell::Ref |
| MappedReadGuard | parking_lot::MappedRwLockReadGuard | std::cell::Ref |

View file

@ -1,6 +1,6 @@
#![allow(clippy::similar_names)] // `expr` and `expn`
use std::sync::Arc;
use std::sync::{Arc, OnceLock};
use crate::get_unique_attr;
use crate::visitors::{Descend, for_each_expr_without_closures};
@ -8,7 +8,6 @@ use crate::visitors::{Descend, for_each_expr_without_closures};
use arrayvec::ArrayVec;
use rustc_ast::{FormatArgs, FormatArgument, FormatPlaceholder};
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::sync::OnceLock;
use rustc_hir::{self as hir, Expr, ExprKind, HirId, Node, QPath};
use rustc_lint::{LateContext, LintContext};
use rustc_span::def_id::DefId;