Skip to content

Commit 3773f4d

Browse files
committed
Use thread-safe types for interners
1 parent 70de2e8 commit 3773f4d

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

src/librustc/ty/context.rs

+23-23
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ use rustc_data_structures::stable_hasher::{HashStable, hash_stable_hashmap,
5757
StableVec};
5858
use arena::{TypedArena, DroplessArena};
5959
use rustc_data_structures::indexed_vec::IndexVec;
60-
use rustc_data_structures::sync::Lrc;
60+
use rustc_data_structures::sync::{Lrc, Lock};
6161
use std::any::Any;
6262
use std::borrow::Borrow;
6363
use std::cell::{Cell, RefCell};
@@ -130,28 +130,28 @@ pub struct CtxtInterners<'tcx> {
130130

131131
/// Specifically use a speedy hash algorithm for these hash sets,
132132
/// they're accessed quite often.
133-
type_: RefCell<FxHashSet<Interned<'tcx, TyS<'tcx>>>>,
134-
type_list: RefCell<FxHashSet<Interned<'tcx, Slice<Ty<'tcx>>>>>,
135-
substs: RefCell<FxHashSet<Interned<'tcx, Substs<'tcx>>>>,
136-
canonical_var_infos: RefCell<FxHashSet<Interned<'tcx, Slice<CanonicalVarInfo>>>>,
137-
region: RefCell<FxHashSet<Interned<'tcx, RegionKind>>>,
138-
existential_predicates: RefCell<FxHashSet<Interned<'tcx, Slice<ExistentialPredicate<'tcx>>>>>,
139-
predicates: RefCell<FxHashSet<Interned<'tcx, Slice<Predicate<'tcx>>>>>,
140-
const_: RefCell<FxHashSet<Interned<'tcx, Const<'tcx>>>>,
133+
type_: Lock<FxHashSet<Interned<'tcx, TyS<'tcx>>>>,
134+
type_list: Lock<FxHashSet<Interned<'tcx, Slice<Ty<'tcx>>>>>,
135+
substs: Lock<FxHashSet<Interned<'tcx, Substs<'tcx>>>>,
136+
canonical_var_infos: Lock<FxHashSet<Interned<'tcx, Slice<CanonicalVarInfo>>>>,
137+
region: Lock<FxHashSet<Interned<'tcx, RegionKind>>>,
138+
existential_predicates: Lock<FxHashSet<Interned<'tcx, Slice<ExistentialPredicate<'tcx>>>>>,
139+
predicates: Lock<FxHashSet<Interned<'tcx, Slice<Predicate<'tcx>>>>>,
140+
const_: Lock<FxHashSet<Interned<'tcx, Const<'tcx>>>>,
141141
}
142142

143143
impl<'gcx: 'tcx, 'tcx> CtxtInterners<'tcx> {
144144
fn new(arena: &'tcx DroplessArena) -> CtxtInterners<'tcx> {
145145
CtxtInterners {
146-
arena,
147-
type_: RefCell::new(FxHashSet()),
148-
type_list: RefCell::new(FxHashSet()),
149-
substs: RefCell::new(FxHashSet()),
150-
region: RefCell::new(FxHashSet()),
151-
existential_predicates: RefCell::new(FxHashSet()),
152-
canonical_var_infos: RefCell::new(FxHashSet()),
153-
predicates: RefCell::new(FxHashSet()),
154-
const_: RefCell::new(FxHashSet()),
146+
arena: arena,
147+
type_: Lock::new(FxHashSet()),
148+
type_list: Lock::new(FxHashSet()),
149+
substs: Lock::new(FxHashSet()),
150+
canonical_var_infos: Lock::new(FxHashSet()),
151+
region: Lock::new(FxHashSet()),
152+
existential_predicates: Lock::new(FxHashSet()),
153+
predicates: Lock::new(FxHashSet()),
154+
const_: Lock::new(FxHashSet()),
155155
}
156156
}
157157

@@ -891,11 +891,11 @@ pub struct GlobalCtxt<'tcx> {
891891
/// by `proc-macro` crates.
892892
pub derive_macros: RefCell<NodeMap<Symbol>>,
893893

894-
stability_interner: RefCell<FxHashSet<&'tcx attr::Stability>>,
894+
stability_interner: Lock<FxHashSet<&'tcx attr::Stability>>,
895895

896896
pub interpret_interner: InterpretInterner<'tcx>,
897897

898-
layout_interner: RefCell<FxHashSet<&'tcx LayoutDetails>>,
898+
layout_interner: Lock<FxHashSet<&'tcx LayoutDetails>>,
899899

900900
/// A vector of every trait accessible in the whole crate
901901
/// (i.e. including those from subcrates). This is used only for
@@ -917,7 +917,7 @@ pub struct GlobalCtxt<'tcx> {
917917
/// Everything needed to efficiently work with interned allocations
918918
#[derive(Debug, Default)]
919919
pub struct InterpretInterner<'tcx> {
920-
inner: RefCell<InterpretInternerInner<'tcx>>,
920+
inner: Lock<InterpretInternerInner<'tcx>>,
921921
}
922922

923923
#[derive(Debug, Default)]
@@ -1277,10 +1277,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
12771277
evaluation_cache: traits::EvaluationCache::new(),
12781278
crate_name: Symbol::intern(crate_name),
12791279
data_layout,
1280-
layout_interner: RefCell::new(FxHashSet()),
1280+
layout_interner: Lock::new(FxHashSet()),
12811281
layout_depth: Cell::new(0),
12821282
derive_macros: RefCell::new(NodeMap()),
1283-
stability_interner: RefCell::new(FxHashSet()),
1283+
stability_interner: Lock::new(FxHashSet()),
12841284
interpret_interner: Default::default(),
12851285
all_traits: RefCell::new(None),
12861286
tx_to_llvm_workers: tx,

0 commit comments

Comments
 (0)