Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 32c5449

Browse files
committed
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`.
1 parent 5afd122 commit 32c5449

File tree

8 files changed

+23
-39
lines changed

8 files changed

+23
-39
lines changed

compiler/rustc_data_structures/src/sync.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,16 @@
1818
//!
1919
//! | Type | Serial version | Parallel version |
2020
//! | ----------------------- | ------------------- | ------------------------------- |
21-
//! | `LRef<'a, T>` [^2] | `&'a mut T` | `&'a T` |
22-
//! | | | |
2321
//! | `Lock<T>` | `RefCell<T>` | `RefCell<T>` or |
2422
//! | | | `parking_lot::Mutex<T>` |
2523
//! | `RwLock<T>` | `RefCell<T>` | `parking_lot::RwLock<T>` |
2624
//! | `MTLock<T>` [^1] | `T` | `Lock<T>` |
27-
//! | `MTLockRef<'a, T>` [^2] | `&'a mut MTLock<T>` | `&'a MTLock<T>` |
2825
//! | | | |
2926
//! | `ParallelIterator` | `Iterator` | `rayon::iter::ParallelIterator` |
3027
//!
3128
//! [^1]: `MTLock` is similar to `Lock`, but the serial version avoids the cost
3229
//! of a `RefCell`. This is appropriate when interior mutability is not
3330
//! required.
34-
//!
35-
//! [^2]: `MTRef`, `MTLockRef` are type aliases.
3631
3732
use std::collections::HashMap;
3833
use std::hash::{BuildHasher, Hash};
@@ -97,7 +92,6 @@ mod mode {
9792

9893
// FIXME(parallel_compiler): Get rid of these aliases across the compiler.
9994

100-
pub use std::sync::OnceLock;
10195
// Use portable AtomicU64 for targets without native 64-bit atomics
10296
#[cfg(target_has_atomic = "64")]
10397
pub use std::sync::atomic::AtomicU64;
@@ -110,8 +104,6 @@ pub use parking_lot::{
110104
#[cfg(not(target_has_atomic = "64"))]
111105
pub use portable_atomic::AtomicU64;
112106

113-
pub type LRef<'a, T> = &'a T;
114-
115107
#[derive(Debug, Default)]
116108
pub struct MTLock<T>(Lock<T>);
117109

@@ -148,8 +140,6 @@ use parking_lot::RwLock as InnerRwLock;
148140
/// It is only useful when you are running in a single thread
149141
const ERROR_CHECKING: bool = false;
150142

151-
pub type MTLockRef<'a, T> = LRef<'a, MTLock<T>>;
152-
153143
#[derive(Default)]
154144
#[repr(align(64))]
155145
pub struct CacheAligned<T>(pub T);

compiler/rustc_interface/src/passes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ use std::any::Any;
22
use std::ffi::OsString;
33
use std::io::{self, BufWriter, Write};
44
use std::path::{Path, PathBuf};
5-
use std::sync::{Arc, LazyLock};
5+
use std::sync::{Arc, LazyLock, OnceLock};
66
use std::{env, fs, iter};
77

88
use rustc_ast as ast;
99
use rustc_codegen_ssa::traits::CodegenBackend;
1010
use rustc_data_structures::parallel;
1111
use rustc_data_structures::steal::Steal;
12-
use rustc_data_structures::sync::{AppendOnlyIndexVec, FreezeLock, OnceLock, WorkerLocal};
12+
use rustc_data_structures::sync::{AppendOnlyIndexVec, FreezeLock, WorkerLocal};
1313
use rustc_expand::base::{ExtCtxt, LintStoreExpand};
1414
use rustc_feature::Features;
1515
use rustc_fs_util::try_canonicalize;

compiler/rustc_metadata/src/rmeta/decoder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use std::iter::TrustedLen;
44
use std::path::Path;
5-
use std::sync::Arc;
5+
use std::sync::{Arc, OnceLock};
66
use std::{io, iter, mem};
77

88
pub(super) use cstore_impl::provide;
@@ -11,7 +11,7 @@ use rustc_ast as ast;
1111
use rustc_data_structures::fingerprint::Fingerprint;
1212
use rustc_data_structures::fx::FxIndexMap;
1313
use rustc_data_structures::owned_slice::OwnedSlice;
14-
use rustc_data_structures::sync::{Lock, OnceLock};
14+
use rustc_data_structures::sync::Lock;
1515
use rustc_data_structures::unhash::UnhashMap;
1616
use rustc_expand::base::{SyntaxExtension, SyntaxExtensionKind};
1717
use rustc_expand::proc_macro::{AttrProcMacro, BangProcMacro, DeriveProcMacro};

compiler/rustc_middle/src/mir/basic_blocks.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
use std::sync::OnceLock;
2+
13
use rustc_data_structures::fx::FxHashMap;
24
use rustc_data_structures::graph;
35
use rustc_data_structures::graph::dominators::{Dominators, dominators};
46
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
5-
use rustc_data_structures::sync::OnceLock;
67
use rustc_index::{IndexSlice, IndexVec};
78
use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable};
89
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};

compiler/rustc_monomorphize/src/collector.rs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ use std::path::PathBuf;
209209

210210
use rustc_attr_parsing::InlineAttr;
211211
use rustc_data_structures::fx::FxIndexMap;
212-
use rustc_data_structures::sync::{LRef, MTLock, par_for_each_in};
212+
use rustc_data_structures::sync::{MTLock, par_for_each_in};
213213
use rustc_data_structures::unord::{UnordMap, UnordSet};
214214
use rustc_hir as hir;
215215
use rustc_hir::def::DefKind;
@@ -357,7 +357,7 @@ impl<'tcx> Extend<Spanned<MonoItem<'tcx>>> for MonoItems<'tcx> {
357357
fn collect_items_rec<'tcx>(
358358
tcx: TyCtxt<'tcx>,
359359
starting_item: Spanned<MonoItem<'tcx>>,
360-
state: LRef<'_, SharedState<'tcx>>,
360+
state: &SharedState<'tcx>,
361361
recursion_depths: &mut DefIdMap<usize>,
362362
recursion_limit: Limit,
363363
mode: CollectionMode,
@@ -1671,30 +1671,26 @@ pub(crate) fn collect_crate_mono_items<'tcx>(
16711671

16721672
debug!("building mono item graph, beginning at roots");
16731673

1674-
let mut state = SharedState {
1674+
let state = SharedState {
16751675
visited: MTLock::new(UnordSet::default()),
16761676
mentioned: MTLock::new(UnordSet::default()),
16771677
usage_map: MTLock::new(UsageMap::new()),
16781678
};
16791679
let recursion_limit = tcx.recursion_limit();
16801680

1681-
{
1682-
let state: LRef<'_, _> = &mut state;
1683-
1684-
tcx.sess.time("monomorphization_collector_graph_walk", || {
1685-
par_for_each_in(roots, |root| {
1686-
let mut recursion_depths = DefIdMap::default();
1687-
collect_items_rec(
1688-
tcx,
1689-
dummy_spanned(root),
1690-
state,
1691-
&mut recursion_depths,
1692-
recursion_limit,
1693-
CollectionMode::UsedItems,
1694-
);
1695-
});
1681+
tcx.sess.time("monomorphization_collector_graph_walk", || {
1682+
par_for_each_in(roots, |root| {
1683+
let mut recursion_depths = DefIdMap::default();
1684+
collect_items_rec(
1685+
tcx,
1686+
dummy_spanned(root),
1687+
&state,
1688+
&mut recursion_depths,
1689+
recursion_limit,
1690+
CollectionMode::UsedItems,
1691+
);
16961692
});
1697-
}
1693+
});
16981694

16991695
// The set of MonoItems was created in an inherently indeterministic order because
17001696
// of parallelism. We sort it here to ensure that the output is deterministic.

compiler/rustc_query_system/src/query/caches.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use std::fmt::Debug;
22
use std::hash::Hash;
3+
use std::sync::OnceLock;
34

45
use rustc_data_structures::fx::FxHashMap;
56
use rustc_data_structures::sharded::{self, Sharded};
6-
use rustc_data_structures::sync::OnceLock;
77
pub use rustc_data_structures::vec_cache::VecCache;
88
use rustc_hir::def_id::LOCAL_CRATE;
99
use rustc_index::Idx;

src/doc/rustc-dev-guide/src/parallel-rustc.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,8 @@ are implemented differently depending on whether `parallel-compiler` is true.
4646

4747
| data structure | parallel | non-parallel |
4848
| -------------------------------- | --------------------------------------------------- | ------------ |
49-
| OnceCell | std::sync::OnceLock | std::cell::OnceCell |
5049
| Lock\<T> | (parking_lot::Mutex\<T>) | (std::cell::RefCell) |
5150
| RwLock\<T> | (parking_lot::RwLock\<T>) | (std::cell::RefCell) |
52-
| MTRef<'a, T> | &'a T | &'a mut T |
5351
| MTLock\<T> | (Lock\<T>) | (T) |
5452
| ReadGuard | parking_lot::RwLockReadGuard | std::cell::Ref |
5553
| MappedReadGuard | parking_lot::MappedRwLockReadGuard | std::cell::Ref |

src/tools/clippy/clippy_utils/src/macros.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
#![allow(clippy::similar_names)] // `expr` and `expn`
22

3-
use std::sync::Arc;
3+
use std::sync::{Arc, OnceLock};
44

55
use crate::get_unique_attr;
66
use crate::visitors::{Descend, for_each_expr_without_closures};
77

88
use arrayvec::ArrayVec;
99
use rustc_ast::{FormatArgs, FormatArgument, FormatPlaceholder};
1010
use rustc_data_structures::fx::FxHashMap;
11-
use rustc_data_structures::sync::OnceLock;
1211
use rustc_hir::{self as hir, Expr, ExprKind, HirId, Node, QPath};
1312
use rustc_lint::{LateContext, LintContext};
1413
use rustc_span::def_id::DefId;

0 commit comments

Comments
 (0)