Skip to content

Commit a277c20

Browse files
committed
Rename and remove Cell
1 parent 7948340 commit a277c20

File tree

3 files changed

+18
-37
lines changed

3 files changed

+18
-37
lines changed

compiler/rustc_middle/src/query/mod.rs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ rustc_queries! {
2323
query hir_crate(key: ()) -> &'tcx Crate<'tcx> {
2424
eval_always
2525
no_hash
26-
storage(CellCacheSelector<'tcx>)
2726
desc { "get the crate HIR" }
2827
}
2928

@@ -32,7 +31,6 @@ rustc_queries! {
3231
query index_hir(_: ()) -> &'tcx crate::hir::IndexedHir<'tcx> {
3332
eval_always
3433
no_hash
35-
storage(CellCacheSelector<'tcx>)
3634
desc { "index HIR" }
3735
}
3836

@@ -118,7 +116,6 @@ rustc_queries! {
118116

119117
query analysis(key: ()) -> Result<(), ErrorReported> {
120118
eval_always
121-
storage(CellCacheSelector<'tcx>)
122119
desc { "running analysis passes on this crate" }
123120
}
124121

@@ -704,7 +701,6 @@ rustc_queries! {
704701
}
705702

706703
query typeck_item_bodies(_: ()) -> () {
707-
storage(CellCacheSelector<'tcx>)
708704
desc { "type-checking all item bodies" }
709705
}
710706

@@ -774,7 +770,6 @@ rustc_queries! {
774770
query crate_inherent_impls_overlap_check(_: ())
775771
-> () {
776772
eval_always
777-
storage(CellCacheSelector<'tcx>)
778773
desc { "check for overlap between inherent impls defined in this crate" }
779774
}
780775

@@ -868,12 +863,10 @@ rustc_queries! {
868863
/// Performs part of the privacy check and computes "access levels".
869864
query privacy_access_levels(_: ()) -> &'tcx AccessLevels {
870865
eval_always
871-
storage(CellCacheSelector<'tcx>)
872866
desc { "privacy access levels" }
873867
}
874868
query check_private_in_public(_: ()) -> () {
875869
eval_always
876-
storage(CellCacheSelector<'tcx>)
877870
desc { "checking for private elements in public interfaces" }
878871
}
879872

@@ -988,7 +981,6 @@ rustc_queries! {
988981
///
989982
/// [`LOCAL_CRATE`]: rustc_hir::def_id::LOCAL_CRATE
990983
query all_local_trait_impls(_: ()) -> &'tcx BTreeMap<DefId, Vec<LocalDefId>> {
991-
storage(CellCacheSelector<'tcx>)
992984
desc { "local trait impls" }
993985
}
994986

@@ -1237,15 +1229,12 @@ rustc_queries! {
12371229
/// Identifies the entry-point (e.g., the `main` function) for a given
12381230
/// crate, returning `None` if there is no entry point (such as for library crates).
12391231
query entry_fn(_: ()) -> Option<(DefId, EntryFnType)> {
1240-
storage(CellCacheSelector<'tcx>)
12411232
desc { "looking up the entry function of a crate" }
12421233
}
12431234
query plugin_registrar_fn(_: ()) -> Option<LocalDefId> {
1244-
storage(CellCacheSelector<'tcx>)
12451235
desc { "looking up the plugin registrar for a crate" }
12461236
}
12471237
query proc_macro_decls_static(_: ()) -> Option<LocalDefId> {
1248-
storage(CellCacheSelector<'tcx>)
12491238
desc { "looking up the derive registrar for a crate" }
12501239
}
12511240
query crate_disambiguator(_: CrateNum) -> CrateDisambiguator {
@@ -1423,7 +1412,6 @@ rustc_queries! {
14231412
}
14241413
query postorder_cnums(_: ()) -> &'tcx [CrateNum] {
14251414
eval_always
1426-
storage(CellCacheSelector<'tcx>)
14271415
desc { "generating a postorder list of CrateNums" }
14281416
}
14291417
/// Returns whether or not the crate with CrateNum 'cnum'
@@ -1443,7 +1431,6 @@ rustc_queries! {
14431431
}
14441432
query maybe_unused_extern_crates(_: ()) -> &'tcx [(LocalDefId, Span)] {
14451433
eval_always
1446-
storage(CellCacheSelector<'tcx>)
14471434
desc { "looking up all possibly unused extern crates" }
14481435
}
14491436
query names_imported_by_glob_use(def_id: LocalDefId)
@@ -1459,15 +1446,13 @@ rustc_queries! {
14591446
}
14601447
query all_crate_nums(_: ()) -> &'tcx [CrateNum] {
14611448
eval_always
1462-
storage(CellCacheSelector<'tcx>)
14631449
desc { "fetching all foreign CrateNum instances" }
14641450
}
14651451

14661452
/// A vector of every trait accessible in the whole crate
14671453
/// (i.e., including those from subcrates). This is used only for
14681454
/// error reporting.
14691455
query all_traits(_: ()) -> &'tcx [DefId] {
1470-
storage(CellCacheSelector<'tcx>)
14711456
desc { "fetching all foreign and local traits" }
14721457
}
14731458

@@ -1483,7 +1468,6 @@ rustc_queries! {
14831468

14841469
query collect_and_partition_mono_items(_: ()) -> (&'tcx DefIdSet, &'tcx [CodegenUnit<'tcx>]) {
14851470
eval_always
1486-
storage(CellCacheSelector<'tcx>)
14871471
desc { "collect_and_partition_mono_items" }
14881472
}
14891473
query is_codegened_item(def_id: DefId) -> bool {
@@ -1493,7 +1477,6 @@ rustc_queries! {
14931477
/// All items participating in code generation together with items inlined into them.
14941478
query codegened_and_inlined_items(_: ()) -> &'tcx DefIdSet {
14951479
eval_always
1496-
storage(CellCacheSelector<'tcx>)
14971480
desc { "codegened_and_inlined_items" }
14981481
}
14991482

@@ -1508,7 +1491,6 @@ rustc_queries! {
15081491
}
15091492
}
15101493
query backend_optimization_level(_: ()) -> OptLevel {
1511-
storage(CellCacheSelector<'tcx>)
15121494
desc { "optimization level used by backend" }
15131495
}
15141496

@@ -1689,8 +1671,8 @@ rustc_queries! {
16891671
}
16901672

16911673
query features_query(_: ()) -> &'tcx rustc_feature::Features {
1674+
storage(SingletonCacheSelector<'tcx>)
16921675
eval_always
1693-
storage(CellCacheSelector<'tcx>)
16941676
desc { "looking up enabled feature gates" }
16951677
}
16961678

compiler/rustc_query_system/src/query/caches.rs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use rustc_data_structures::sync::WorkerLocal;
88
use std::default::Default;
99
use std::fmt::Debug;
1010
use std::hash::Hash;
11-
use std::cell::Cell;
1211
use std::marker::PhantomData;
1312

1413
pub trait CacheSelector<K, V> {
@@ -223,29 +222,29 @@ where
223222
}
224223
}
225224

226-
pub struct CellCacheSelector<'tcx>(PhantomData<&'tcx ()>);
225+
pub struct SingletonCacheSelector<'tcx>(PhantomData<&'tcx ()>);
227226

228-
impl<'tcx, K: Eq + Hash, V: Clone> CacheSelector<K, V> for CellCacheSelector<'tcx> {
229-
type Cache = CellCache<K, V>;
227+
impl<'tcx, K: Eq + Hash, V: Clone> CacheSelector<K, V> for SingletonCacheSelector<'tcx> {
228+
type Cache = SingletonCache<K, V>;
230229
}
231230

232-
pub struct CellCache<K, V>(PhantomData<(K, V)>);
231+
pub struct SingletonCache<K, V>(PhantomData<(K, V)>);
233232

234-
impl<K, V> Default for CellCache<K, V> {
233+
impl<K, V> Default for SingletonCache<K, V> {
235234
fn default() -> Self {
236-
CellCache(PhantomData)
235+
SingletonCache(PhantomData)
237236
}
238237
}
239238

240-
impl<K, V> CellCache<K, V> {
239+
impl<K, V> SingletonCache<K, V> {
241240
const KEY_IS_ZST: () = {
242241
if std::mem::size_of::<K>() != 0 {
243242
panic!("Key must be a ZST");
244243
}
245244
};
246245
}
247246

248-
impl<K: Eq + Hash, V: Clone + Debug> QueryStorage for CellCache<K, V> {
247+
impl<K: Eq + Hash, V: Clone + Debug> QueryStorage for SingletonCache<K, V> {
249248
type Value = V;
250249
type Stored = V;
251250

@@ -256,13 +255,13 @@ impl<K: Eq + Hash, V: Clone + Debug> QueryStorage for CellCache<K, V> {
256255
}
257256
}
258257

259-
impl<K, V> QueryCache for CellCache<K, V>
258+
impl<K, V> QueryCache for SingletonCache<K, V>
260259
where
261260
K: Eq + Hash + Copy + Clone + Debug,
262-
V: Copy + Clone + Debug,
261+
V: Clone + Debug,
263262
{
264263
type Key = K;
265-
type Sharded = Cell<Option<(K, V, DepNodeIndex)>>;
264+
type Sharded = Option<(K, V, DepNodeIndex)>;
266265

267266
#[inline(always)]
268267
fn lookup<'s, R, OnHit>(
@@ -277,8 +276,8 @@ where
277276
let _ = Self::KEY_IS_ZST;
278277

279278
let lock = state.shards.get_shard_by_index(0).lock();
280-
if let Some((_key, val, dep_node)) = lock.get() {
281-
Ok(on_hit(&val, dep_node))
279+
if let Some((_key, val, dep_node)) = &*lock {
280+
Ok(on_hit(&val, *dep_node))
282281
} else {
283282
Err(QueryLookup {
284283
key_hash: 0,
@@ -295,7 +294,7 @@ where
295294
value: V,
296295
index: DepNodeIndex,
297296
) -> Self::Stored {
298-
lock_sharded_storage.set(Some((key, value, index)));
297+
*lock_sharded_storage = Some((key, value.clone(), index));
299298
value
300299
}
301300

@@ -305,8 +304,8 @@ where
305304
f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex),
306305
) {
307306
let lock = shards.get_shard_by_index(0).lock();
308-
if let Some((key, val, dep_node)) = lock.get() {
309-
f(&key, &val, dep_node);
307+
if let Some((key, val, dep_node)) = &*lock {
308+
f(&key, &val, *dep_node);
310309
}
311310
}
312311
}

compiler/rustc_query_system/src/query/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub use self::job::{print_query_stack, QueryInfo, QueryJob, QueryJobId, QueryJob
88

99
mod caches;
1010
pub use self::caches::{
11-
ArenaCacheSelector, CacheSelector, CellCacheSelector, DefaultCacheSelector, QueryCache, QueryStorage,
11+
ArenaCacheSelector, CacheSelector, SingletonCacheSelector, DefaultCacheSelector, QueryCache, QueryStorage,
1212
};
1313

1414
mod config;

0 commit comments

Comments
 (0)