Skip to content

Commit efe7cf4

Browse files
committed
Remove WorkerLocal from AttrIdGenerator
1 parent 64474a4 commit efe7cf4

File tree

2 files changed

+4
-51
lines changed

2 files changed

+4
-51
lines changed

compiler/rustc_ast/src/attr/mod.rs

+4-32
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,10 @@ use crate::tokenstream::{DelimSpan, Spacing, TokenTree};
1010
use crate::tokenstream::{LazyAttrTokenStream, TokenStream};
1111
use crate::util::comments;
1212
use crate::util::literal::escape_string_symbol;
13-
use rustc_data_structures::sync::WorkerLocal;
1413
use rustc_index::bit_set::GrowableBitSet;
1514
use rustc_span::symbol::{sym, Ident, Symbol};
1615
use rustc_span::Span;
17-
use std::cell::Cell;
1816
use std::iter;
19-
#[cfg(debug_assertions)]
20-
use std::ops::BitXor;
21-
#[cfg(debug_assertions)]
2217
use std::sync::atomic::{AtomicU32, Ordering};
2318
use thin_vec::{thin_vec, ThinVec};
2419

@@ -40,39 +35,16 @@ impl MarkedAttrs {
4035
}
4136
}
4237

43-
pub struct AttrIdGenerator(WorkerLocal<Cell<u32>>);
44-
45-
#[cfg(debug_assertions)]
46-
static MAX_ATTR_ID: AtomicU32 = AtomicU32::new(u32::MAX);
38+
pub struct AttrIdGenerator(AtomicU32);
4739

4840
impl AttrIdGenerator {
4941
pub fn new() -> Self {
50-
// We use `(index as u32).reverse_bits()` to initialize the
51-
// starting value of AttrId in each worker thread.
52-
// The `index` is the index of the worker thread.
53-
// This ensures that the AttrId generated in each thread is unique.
54-
AttrIdGenerator(WorkerLocal::new(|index| {
55-
let index: u32 = index.try_into().unwrap();
56-
57-
#[cfg(debug_assertions)]
58-
{
59-
let max_id = ((index + 1).next_power_of_two() - 1).bitxor(u32::MAX).reverse_bits();
60-
MAX_ATTR_ID.fetch_min(max_id, Ordering::Release);
61-
}
62-
63-
Cell::new(index.reverse_bits())
64-
}))
42+
AttrIdGenerator(AtomicU32::new(0))
6543
}
6644

6745
pub fn mk_attr_id(&self) -> AttrId {
68-
let id = self.0.get();
69-
70-
// Ensure the assigned attr_id does not overlap the bits
71-
// representing the number of threads.
72-
#[cfg(debug_assertions)]
73-
assert!(id <= MAX_ATTR_ID.load(Ordering::Acquire));
74-
75-
self.0.set(id + 1);
46+
let id = self.0.fetch_add(1, Ordering::Relaxed);
47+
assert!(id != u32::MAX);
7648
AttrId::from_u32(id)
7749
}
7850
}

compiler/rustc_interface/src/interface.rs

-19
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use rustc_session::Session;
1919
use rustc_session::{early_error, CompilerIO};
2020
use rustc_span::source_map::{FileLoader, FileName};
2121
use rustc_span::symbol::sym;
22-
use std::cell::OnceCell;
2322
use std::path::PathBuf;
2423
use std::result;
2524

@@ -59,25 +58,9 @@ impl Compiler {
5958
}
6059
}
6160

62-
fn registry_setup() {
63-
thread_local! {
64-
static ONCE: OnceCell<()> = OnceCell::new();
65-
}
66-
67-
// Create a dummy registry to allow `WorkerLocal` construction.
68-
// We use `OnceCell` so we only register one dummy registry per thread.
69-
ONCE.with(|once| {
70-
once.get_or_init(|| {
71-
rustc_data_structures::sync::Registry::new(1).register();
72-
});
73-
});
74-
}
75-
7661
/// Converts strings provided as `--cfg [cfgspec]` into a `crate_cfg`.
7762
pub fn parse_cfgspecs(cfgspecs: Vec<String>) -> FxHashSet<(String, Option<String>)> {
7863
rustc_span::create_default_session_if_not_set_then(move |_| {
79-
registry_setup();
80-
8164
let cfg = cfgspecs
8265
.into_iter()
8366
.map(|s| {
@@ -137,8 +120,6 @@ pub fn parse_cfgspecs(cfgspecs: Vec<String>) -> FxHashSet<(String, Option<String
137120
/// Converts strings provided as `--check-cfg [specs]` into a `CheckCfg`.
138121
pub fn parse_check_cfg(specs: Vec<String>) -> CheckCfg {
139122
rustc_span::create_default_session_if_not_set_then(move |_| {
140-
registry_setup();
141-
142123
let mut cfg = CheckCfg::default();
143124

144125
'specs: for s in specs {

0 commit comments

Comments
 (0)