Skip to content

Commit

Permalink
Fix the parallel compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoxc committed Feb 14, 2020
1 parent e6a06b7 commit 022416d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/librustc/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ rustc_queries! {

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

Expand Down
23 changes: 17 additions & 6 deletions src/librustc/ty/query/caches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use rustc_index::vec::IndexVec;
use std::cell::RefCell;
use std::default::Default;
use std::hash::Hash;
use std::marker::PhantomData;

pub(crate) trait CacheSelector<K, V> {
type Cache: QueryCache<K, V>;
Expand Down Expand Up @@ -57,13 +58,18 @@ pub(crate) trait QueryCache<K, V>: Default {
pub struct DefaultCacheSelector;

impl<K: Eq + Hash, V: Clone> CacheSelector<K, V> for DefaultCacheSelector {
type Cache = DefaultCache;
type Cache = DefaultCache<()>;
}

#[derive(Default)]
pub struct DefaultCache;
pub struct DefaultCache<D>(PhantomData<D>);

impl<K: Eq + Hash, V: Clone> QueryCache<K, V> for DefaultCache {
impl<D> Default for DefaultCache<D> {
fn default() -> Self {
DefaultCache(PhantomData)
}
}

impl<D, K: Eq + Hash, V: Clone> QueryCache<K, V> for DefaultCache<D> {
type Sharded = FxHashMap<K, (V, DepNodeIndex)>;

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

#[cfg(parallel_compiler)]
pub type LocalDenseDefIdCacheSelector<V> = DefaultCache<V>;
#[cfg(not(parallel_compiler))]
pub type LocalDenseDefIdCacheSelector<V> = LocalDenseDefIdCache<V>;

pub struct LocalDenseDefIdCache<V> {
local: RefCell<IndexVec<DefIndex, Option<(V, DepNodeIndex)>>>,
other: DefaultCache,
other: DefaultCache<()>,
}

impl<V> Default for LocalDenseDefIdCache<V> {
Expand All @@ -126,7 +137,7 @@ impl<V> Default for LocalDenseDefIdCache<V> {
}

impl<V: Clone> QueryCache<DefId, V> for LocalDenseDefIdCache<V> {
type Sharded = <DefaultCache as QueryCache<DefId, V>>::Sharded;
type Sharded = <DefaultCache<()> as QueryCache<DefId, V>>::Sharded;

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

0 comments on commit 022416d

Please sign in to comment.