Skip to content

Commit 022416d

Browse files
committed
Fix the parallel compiler
1 parent e6a06b7 commit 022416d

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

src/librustc/query/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ rustc_queries! {
5757

5858
/// Records the type of every item.
5959
query type_of(key: DefId) -> Ty<'tcx> {
60-
storage(caches::LocalDenseDefIdCache<Ty<'tcx>>)
60+
storage(caches::LocalDenseDefIdCacheSelector<Ty<'tcx>>)
6161
cache_on_disk_if { key.is_local() }
6262
}
6363

src/librustc/ty/query/caches.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use rustc_index::vec::IndexVec;
1010
use std::cell::RefCell;
1111
use std::default::Default;
1212
use std::hash::Hash;
13+
use std::marker::PhantomData;
1314

1415
pub(crate) trait CacheSelector<K, V> {
1516
type Cache: QueryCache<K, V>;
@@ -57,13 +58,18 @@ pub(crate) trait QueryCache<K, V>: Default {
5758
pub struct DefaultCacheSelector;
5859

5960
impl<K: Eq + Hash, V: Clone> CacheSelector<K, V> for DefaultCacheSelector {
60-
type Cache = DefaultCache;
61+
type Cache = DefaultCache<()>;
6162
}
6263

63-
#[derive(Default)]
64-
pub struct DefaultCache;
64+
pub struct DefaultCache<D>(PhantomData<D>);
6565

66-
impl<K: Eq + Hash, V: Clone> QueryCache<K, V> for DefaultCache {
66+
impl<D> Default for DefaultCache<D> {
67+
fn default() -> Self {
68+
DefaultCache(PhantomData)
69+
}
70+
}
71+
72+
impl<D, K: Eq + Hash, V: Clone> QueryCache<K, V> for DefaultCache<D> {
6773
type Sharded = FxHashMap<K, (V, DepNodeIndex)>;
6874

6975
#[inline(always)]
@@ -114,9 +120,14 @@ impl<K: Eq + Hash, V: Clone> QueryCache<K, V> for DefaultCache {
114120
}
115121
}
116122

123+
#[cfg(parallel_compiler)]
124+
pub type LocalDenseDefIdCacheSelector<V> = DefaultCache<V>;
125+
#[cfg(not(parallel_compiler))]
126+
pub type LocalDenseDefIdCacheSelector<V> = LocalDenseDefIdCache<V>;
127+
117128
pub struct LocalDenseDefIdCache<V> {
118129
local: RefCell<IndexVec<DefIndex, Option<(V, DepNodeIndex)>>>,
119-
other: DefaultCache,
130+
other: DefaultCache<()>,
120131
}
121132

122133
impl<V> Default for LocalDenseDefIdCache<V> {
@@ -126,7 +137,7 @@ impl<V> Default for LocalDenseDefIdCache<V> {
126137
}
127138

128139
impl<V: Clone> QueryCache<DefId, V> for LocalDenseDefIdCache<V> {
129-
type Sharded = <DefaultCache as QueryCache<DefId, V>>::Sharded;
140+
type Sharded = <DefaultCache<()> as QueryCache<DefId, V>>::Sharded;
130141

131142
#[inline(always)]
132143
fn lookup<'tcx, R, GetCache, OnHit, OnMiss, Q>(

0 commit comments

Comments
 (0)