Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 5 pull requests #70141

Closed
wants to merge 28 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
cdc7304
Compute the correct layout for variants of uninhabited enums and read…
oli-obk Mar 6, 2020
ec88ffa
Comment nits
oli-obk Mar 11, 2020
74608c7
Rustfmt and adjust capitalization
oli-obk Mar 11, 2020
24dc2cb
librustc_codegen_llvm: Replace deprecated API usage
tmiasko Mar 11, 2020
bee1513
codegen/mir: support polymorphic `InstanceDef`s
davidtwco Mar 11, 2020
0bf5cae
Remove __query_compute module.
cjgillot Mar 6, 2020
fc82376
Make QueryAccessor::dep_kind an associated const.
cjgillot Mar 6, 2020
cf238fd
Inline QueryAccessor::query.
cjgillot Mar 7, 2020
1249032
Move impl of Queries with its definition.
cjgillot Mar 7, 2020
b089433
Unpack type arguments for QueryStateShard.
cjgillot Mar 6, 2020
486a082
Unpack type arguments for QueryLookup.
cjgillot Mar 6, 2020
a0f57e2
Unpack type arguments for QueryState.
cjgillot Mar 6, 2020
fa02dca
Remove Q parameter from QueryCache::lookup.
cjgillot Mar 6, 2020
a18aa81
Remove Q parameter from alloc_self_profile_query_strings_for_query_ca…
cjgillot Mar 6, 2020
d125bbb
Remove Q parameter from query stats.
cjgillot Mar 6, 2020
fa0794d
Remove Q parameter from JobOwner.
cjgillot Mar 7, 2020
5dc7c2e
Remove Q parameter from try_get_cached.
cjgillot Mar 7, 2020
7d84f4f
Offload try_collect_active_jobs.
cjgillot Mar 7, 2020
7309b3c
Simplify type aliases.
cjgillot Mar 7, 2020
3abd475
Make QueryCache parameters associated types.
cjgillot Mar 7, 2020
5557407
Remove QueryState type alias.
cjgillot Mar 7, 2020
8aa1328
Make stuff private.
cjgillot Mar 15, 2020
2c22da0
Fix abort-on-eprintln during process shutdown
alexcrichton Mar 12, 2020
46d8095
Rollup merge of #69768 - oli-obk:union_field_ice, r=eddyb,RalfJung
Centril Mar 19, 2020
50656db
Rollup merge of #69910 - cjgillot:polym, r=Zoxc
Centril Mar 19, 2020
dc46a7f
Rollup merge of #69935 - davidtwco:issue-69925, r=eddyb
Centril Mar 19, 2020
b09b114
Rollup merge of #69940 - tmiasko:llvm-api, r=hanna-kruppe
Centril Mar 19, 2020
cb8af5e
Rollup merge of #69955 - alexcrichton:stderr-infallible, r=sfackler
Centril Mar 19, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Simplify type aliases.
  • Loading branch information
cjgillot committed Mar 16, 2020
commit 7309b3cd8be928a0ec9e3219d9562ddeb54ff994
16 changes: 7 additions & 9 deletions src/librustc/ty/query/caches.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::dep_graph::DepNodeIndex;
use crate::ty::query::plumbing::{QueryLookupImpl, QueryStateImpl, QueryStateShardImpl};
use crate::ty::query::plumbing::{QueryLookup, QueryStateImpl, QueryStateShard};
use crate::ty::TyCtxt;

use rustc_data_structures::fx::FxHashMap;
@@ -28,11 +28,10 @@ pub(crate) trait QueryCache<K, V>: Default {
on_miss: OnMiss,
) -> R
where
GetCache: for<'a> Fn(
&'a mut QueryStateShardImpl<'tcx, K, Self::Sharded>,
) -> &'a mut Self::Sharded,
GetCache:
for<'a> Fn(&'a mut QueryStateShard<'tcx, K, Self::Sharded>) -> &'a mut Self::Sharded,
OnHit: FnOnce(&V, DepNodeIndex) -> R,
OnMiss: FnOnce(K, QueryLookupImpl<'tcx, QueryStateShardImpl<'tcx, K, Self::Sharded>>) -> R;
OnMiss: FnOnce(K, QueryLookup<'tcx, K, Self::Sharded>) -> R;

fn complete(
&self,
@@ -73,11 +72,10 @@ impl<K: Eq + Hash, V: Clone> QueryCache<K, V> for DefaultCache {
on_miss: OnMiss,
) -> R
where
GetCache: for<'a> Fn(
&'a mut QueryStateShardImpl<'tcx, K, Self::Sharded>,
) -> &'a mut Self::Sharded,
GetCache:
for<'a> Fn(&'a mut QueryStateShard<'tcx, K, Self::Sharded>) -> &'a mut Self::Sharded,
OnHit: FnOnce(&V, DepNodeIndex) -> R,
OnMiss: FnOnce(K, QueryLookupImpl<'tcx, QueryStateShardImpl<'tcx, K, Self::Sharded>>) -> R,
OnMiss: FnOnce(K, QueryLookup<'tcx, K, Self::Sharded>) -> R,
{
let mut lookup = state.get_lookup(&key);
let lock = &mut *lookup.lock;
41 changes: 14 additions & 27 deletions src/librustc/ty/query/plumbing.rs
Original file line number Diff line number Diff line change
@@ -29,32 +29,23 @@ use std::ptr;
#[cfg(debug_assertions)]
use std::sync::atomic::{AtomicUsize, Ordering};

pub(crate) type QueryStateShard<'tcx, Q> = QueryStateShardImpl<
'tcx,
<Q as QueryConfig<'tcx>>::Key,
<<Q as QueryAccessors<'tcx>>::Cache as QueryCache<
<Q as QueryConfig<'tcx>>::Key,
<Q as QueryConfig<'tcx>>::Value,
>>::Sharded,
>;

pub(crate) struct QueryStateShardImpl<'tcx, K, C> {
pub(crate) struct QueryStateShard<'tcx, K, C> {
pub(super) cache: C,
pub(super) active: FxHashMap<K, QueryResult<'tcx>>,

/// Used to generate unique ids for active jobs.
pub(super) jobs: u32,
}

impl<'tcx, K, C> QueryStateShardImpl<'tcx, K, C> {
impl<'tcx, K, C> QueryStateShard<'tcx, K, C> {
fn get_cache(&mut self) -> &mut C {
&mut self.cache
}
}

impl<'tcx, K, C: Default> Default for QueryStateShardImpl<'tcx, K, C> {
fn default() -> QueryStateShardImpl<'tcx, K, C> {
QueryStateShardImpl { cache: Default::default(), active: Default::default(), jobs: 0 }
impl<'tcx, K, C: Default> Default for QueryStateShard<'tcx, K, C> {
fn default() -> QueryStateShard<'tcx, K, C> {
QueryStateShard { cache: Default::default(), active: Default::default(), jobs: 0 }
}
}

@@ -67,16 +58,13 @@ pub(crate) type QueryState<'tcx, Q> = QueryStateImpl<

pub(crate) struct QueryStateImpl<'tcx, K, V, C: QueryCache<K, V>> {
pub(super) cache: C,
pub(super) shards: Sharded<QueryStateShardImpl<'tcx, K, C::Sharded>>,
pub(super) shards: Sharded<QueryStateShard<'tcx, K, C::Sharded>>,
#[cfg(debug_assertions)]
pub(super) cache_hits: AtomicUsize,
}

impl<'tcx, K, V, C: QueryCache<K, V>> QueryStateImpl<'tcx, K, V, C> {
pub(super) fn get_lookup<K2: Hash>(
&'tcx self,
key: &K2,
) -> QueryLookupImpl<'tcx, QueryStateShardImpl<'tcx, K, C::Sharded>> {
pub(super) fn get_lookup<K2: Hash>(&'tcx self, key: &K2) -> QueryLookup<'tcx, K, C::Sharded> {
// We compute the key's hash once and then use it for both the
// shard lookup and the hashmap lookup. This relies on the fact
// that both of them use `FxHasher`.
@@ -86,7 +74,7 @@ impl<'tcx, K, V, C: QueryCache<K, V>> QueryStateImpl<'tcx, K, V, C> {

let shard = self.shards.get_shard_index_by_hash(key_hash);
let lock = self.shards.get_shard_by_index(shard).lock();
QueryLookupImpl { key_hash, shard, lock }
QueryLookup { key_hash, shard, lock }
}
}

@@ -154,11 +142,10 @@ impl<'tcx, K, V, C: QueryCache<K, V>> Default for QueryStateImpl<'tcx, K, V, C>
}

/// Values used when checking a query cache which can be reused on a cache-miss to execute the query.
pub(crate) type QueryLookup<'tcx, Q> = QueryLookupImpl<'tcx, QueryStateShard<'tcx, Q>>;
pub(crate) struct QueryLookupImpl<'tcx, QSS> {
pub(crate) struct QueryLookup<'tcx, K, C> {
pub(super) key_hash: u64,
pub(super) shard: usize,
pub(super) lock: LockGuard<'tcx, QSS>,
pub(super) lock: LockGuard<'tcx, QueryStateShard<'tcx, K, C>>,
}

/// A type representing the responsibility to execute the job in the `job` field.
@@ -198,7 +185,7 @@ where
tcx: TyCtxt<'tcx>,
span: Span,
key: &K,
mut lookup: QueryLookup<'tcx, Q>,
mut lookup: QueryLookup<'tcx, K, C::Sharded>,
) -> TryGetJob<'tcx, Q>
where
K: Eq + Hash + Clone + Debug,
@@ -502,11 +489,11 @@ impl<'tcx> TyCtxt<'tcx> {
where
C: QueryCache<K, V>,
OnHit: FnOnce(&V, DepNodeIndex) -> R,
OnMiss: FnOnce(K, QueryLookupImpl<'tcx, QueryStateShardImpl<'tcx, K, C::Sharded>>) -> R,
OnMiss: FnOnce(K, QueryLookup<'tcx, K, C::Sharded>) -> R,
{
state.cache.lookup(
state,
QueryStateShardImpl::<K, C::Sharded>::get_cache,
QueryStateShard::<K, C::Sharded>::get_cache,
key,
|value, index| {
if unlikely!(self.prof.enabled()) {
@@ -546,7 +533,7 @@ impl<'tcx> TyCtxt<'tcx> {
self,
span: Span,
key: Q::Key,
lookup: QueryLookup<'tcx, Q>,
lookup: QueryLookup<'tcx, Q::Key, <Q::Cache as QueryCache<Q::Key, Q::Value>>::Sharded>,
) -> Q::Value {
let job = match JobOwnerImpl::try_start::<Q>(self, span, &key, lookup) {
TryGetJob::NotYetStarted(job) => job,