8000 Move the query system to a dedicated crate by cjgillot · Pull Request #70162 · rust-lang/rust · GitHub
[go: up one dir, main page]

Skip to content

Move the query system to a dedicated crate #70162

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

Merged
merged 31 commits into from
Mar 28, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
8c1c90b
Make QueryConfig argument a type.
cjgillot Mar 8, 2020
f74fd03
Make QueryAccessor argument a type.
cjgillot Mar 8, 2020
57c3177
Make QueryDescription parameter a type.
cjgillot Mar 8, 2020
c4a451e
Make QueryCache generic on the context.
cjgillot Mar 11, 2020
ee9781c
Make QueryContext a subtrait of DepContext.
cjgillot Mar 18, 2020
2a52436
Generalise QueryJobId.
cjgillot Mar 18, 2020
a51ad88
Decouple from DepKind.
cjgillot Mar 18, 2020
232364a
Generalise QueryLatch.
cjgillot Mar 18, 2020
63087b6
Parametrise by try_collect_active_jobs.
cjgillot Mar 19, 2020
42f0db5
Move HashStable bound to the trait definition.
cjgillot Mar 19, 2020
decfd70
Generalise try_get_cached.
cjgillot Mar 19, 2020
4ac4ccd
Generalise JobOwner::try_start.
cjgillot Mar 19, 2020
27e8a95
Generalise Query starting.
cjgillot Mar 19, 2020
6184a71
Make get_query into an extension trait.
cjgillot Mar 19, 2020
5b8dac3
Move query system to librustc_query_system.
cjgillot Mar 19, 2020
8e873c3
Make librustc_query_system compile.
cjgillot Mar 19, 2020
dca0344
Make librustc compile.
cjgillot Mar 19, 2020
301ad11
Rustfmt.
cjgillot Mar 26, 2020
d305b2c
Unify key types in get_lookup.
cjgillot Mar 24, 2020
228ca8e
Access QueryStateShard directly.
cjgillot Mar 24, 2020
b6033fc
Retire DepGraphSafe and HashStableContext.
cjgillot Mar 24, 2020
0e8b59a
Prune dependencies.
cjgillot Mar 24, 2020
fa06cfd
Move generics on QueryCache.
cjgillot Mar 24, 2020
5dfed41
Simplify generics on try_start.
cjgillot Mar 24, 2020
fce0d37
Add comment.
cjgillot Mar 24, 2020
d224e21
Rename read_query_job -> current_query_job and simplify it.
cjgillot Mar 25, 2020
260cfab
Don't allow access to the Session.
cjgillot Mar 25, 2020
4faf701
Remove the QueryGetter trait.
cjgillot Mar 27, 2020
db5be1f
Move QueryContext to the parent module.
cjgillot Mar 27, 2020
222d010
Cleanups.
cjgillot Mar 27, 2020
2d7bbda
Implement HashStable directly.
cjgillot Mar 27, 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
10000
Diff view
Prev Previous commit
Next Next commit
Move generics on QueryCache.
  • Loading branch information
cjgillot committed Mar 26, 2020
commit fa06cfd25b2f53d01eb92605caac8d39cbb57ab0
2 changes: 1 addition & 1 deletion src/librustc/ty/query/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ macro_rules! is_eval_always {

macro_rules! query_storage {
(<$tcx:tt>[][$K:ty, $V:ty]) => {
<<$K as Key>::CacheSelector as CacheSelector<TyCtxt<$tcx>, $K, $V>>::Cache
<<$K as Key>::CacheSelector as CacheSelector<$K, $V>>::Cache
};
(<$tcx:tt>[storage($ty:ty) $($rest:tt)*][$K:ty, $V:ty]) => {
$ty
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/query/profiling_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ pub(super) fn alloc_self_profile_query_strings_for_query_cache<'tcx, C>(
query_state: &QueryState<TyCtxt<'tcx>, C>,
string_cache: &mut QueryKeyStringCache,
) where
C: QueryCache<TyCtxt<'tcx>>,
C: QueryCache,
C::Key: Debug + Clone,
{
tcx.prof.with_profiler(|profiler| {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/query/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct QueryStats {
local_def_id_keys: Option<usize>,
}

fn stats<CTX: QueryContext, C: QueryCache<CTX>>(
fn stats<CTX: QueryContext, C: QueryCache>(
name: &'static str,
map: &QueryState<CTX, C>,
) -> QueryStats {
Expand Down
18 changes: 9 additions & 9 deletions src/librustc_query_system/query/caches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ use std::default::Default;
use std::hash::Hash;
use std::marker::PhantomData;

pub trait CacheSelector<CTX: QueryContext, K: Hash, V> {
type Cache: QueryCache<CTX, Key = K, Value = V>;
pub trait CacheSelector<K: Hash, V> {
type Cache: QueryCache<Key = K, Value = V>;
}

pub trait QueryCache<CTX: QueryContext>: Default {
pub trait QueryCache: Default {
type Key: Hash;
type Value;
type Sharded: Default;
Expand All @@ -21,7 +21,7 @@ pub trait QueryCache<CTX: QueryContext>: Default {
/// It returns the shard index and a lock guard to the shard,
/// which will be used if the query is not in the cache and we need
/// to compute it.
fn lookup<R, OnHit, OnMiss>(
fn lookup<CTX: QueryContext, R, OnHit, OnMiss>(
&self,
state: &QueryState<CTX, Self>,
key: Self::Key,
Expand All @@ -33,7 +33,7 @@ pub trait QueryCache<CTX: QueryContext>: Default {
OnHit: FnOnce(&Self::Value, DepNodeIndex) -> R,
OnMiss: FnOnce(Self::Key, QueryLookup<'_, CTX, Self::Key, Self::Sharded>) -> R;

fn complete(
fn complete<CTX: QueryContext>(
&self,
tcx: CTX,
lock_sharded_storage: &mut Self::Sharded,
Expand All @@ -54,7 +54,7 @@ pub trait QueryCache<CTX: QueryContext>: Default {

pub struct DefaultCacheSelector;

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

Expand All @@ -66,13 +66,13 @@ impl<K, V> Default for DefaultCache<K, V> {
}
}

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

#[inline(always)]
fn lookup<R, OnHit, OnMiss>(
fn lookup<CTX: QueryContext, R, OnHit, OnMiss>(
&self,
state: &QueryState<CTX, Self>,
key: K,
Expand All @@ -92,7 +92,7 @@ impl<CTX: QueryContext, K: Eq + Hash, V: Clone> QueryCache<CTX> for DefaultCache
}

#[inline]
fn complete(
fn complete<CTX: QueryContext>(
&self,
_: CTX,
lock_sharded_storage: &mut Self::Sharded,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_query_system/query/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub trait QueryAccessors<CTX: QueryContext>: QueryConfig<CTX> {
const EVAL_ALWAYS: bool;
const DEP_KIND: CTX::DepKind;

type Cache: QueryCache<CTX, Key = Self::Key, Value = Self::Value>;
type Cache: QueryCache<Key = Self::Key, Value = Self::Value>;

// Don't use this method to access query results, instead use the methods on TyCtxt
fn query_state<'a>(tcx: CTX) -> &'a QueryState<CTX, Self::Cache>;
Expand Down
20 changes: 10 additions & 10 deletions src/librustc_query_system/query/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ impl<CTX: QueryContext, K, C: Default> Default for QueryStateShard<CTX, K, C> {
}
}

pub struct QueryState<CTX: QueryContext, C: QueryCache<CTX>> {
pub struct QueryState<CTX: QueryContext, C: QueryCache> {
cache: C,
shards: Sharded<QueryStateShard<CTX, C::Key, C::Sharded>>,
#[cfg(debug_assertions)]
pub cache_hits: AtomicUsize,
}

impl<CTX: QueryContext, C: QueryCache<CTX>> QueryState<CTX, C> {
impl<CTX: QueryContext, C: QueryCache> QueryState<CTX, C> {
pub(super) fn get_lookup<'tcx>(
&'tcx self,
key: &C::Key,
Expand Down Expand Up @@ -77,7 +77,7 @@ enum QueryResult<CTX: QueryContext> {
Poisoned,
}

impl<CTX: QueryContext, C: QueryCache<CTX>> QueryState<CTX, C> {
impl<CTX: QueryContext, C: QueryCache> QueryState<CTX, C> {
pub fn iter_results<R>(
&self,
f: impl for<'a> FnOnce(
Expand Down Expand Up @@ -122,7 +122,7 @@ impl<CTX: QueryContext, C: QueryCache<CTX>> QueryState<CTX, C> {
}
}

impl<CTX: QueryContext, C: QueryCache<CTX>> Default for QueryState<CTX, C> {
impl<CTX: QueryContext, C: QueryCache> Default for QueryState<CTX, C> {
fn default() -> QueryState<CTX, C> {
QueryState {
cache: C::default(),
Expand All @@ -144,7 +144,7 @@ pub struct QueryLookup<'tcx, CTX: QueryContext, K, C> {
/// This will poison the relevant query if dropped.
struct JobOwner<'tcx, CTX: QueryContext, C>
where
C: QueryCache<CTX>,
C: QueryCache,
C::Key: Eq + Hash + Clone + Debug,
C::Value: Clone,
{
Expand All @@ -155,7 +155,7 @@ where

impl<'tcx, CTX: QueryContext, C> JobOwner<'tcx, CTX, C>
where
C: QueryCache<CTX>,
C: QueryCache,
C::Key: Eq + Hash + Clone + Debug,
C::Value: Clone,
{
Expand Down Expand Up @@ -292,7 +292,7 @@ where
(result, diagnostics.into_inner())
}

impl<'tcx, CTX: QueryContext, C: QueryCache<CTX>> Drop for JobOwner<'tcx, CTX, C>
impl<'tcx, CTX: QueryContext, C: QueryCache> Drop for JobOwner<'tcx, CTX, C>
where
C::Key: Eq + Hash + Clone + Debug,
C::Value: Clone,
Expand Down Expand Up @@ -326,7 +326,7 @@ pub struct CycleError<Q> {
}

/// The result of `try_start`.
enum TryGetJob<'tcx, CTX: QueryContext, C: QueryCache<CTX>>
enum TryGetJob<'tcx, CTX: QueryContext, C: QueryCache>
where
C::Key: Eq + Hash + Clone + Debug,
C::Value: Clone,
Expand Down Expand Up @@ -358,7 +358,7 @@ fn try_get_cached<CTX, C, R, OnHit, OnMiss>(
on_miss: OnMiss,
) -> R
where
C: QueryCache<CTX>,
C: QueryCache,
CTX: QueryContext,
OnHit: FnOnce(&C::Value, DepNodeIndex) -> R,
OnMiss: FnOnce(C::Key, QueryLookup<'_, CTX, C::Key, C::Sharded>) -> R,
Expand All @@ -385,7 +385,7 @@ fn try_execute_query<Q, CTX>(
tcx: CTX,
span: Span,
key: Q::Key,
lookup: QueryLookup<'_, CTX, Q::Key, <Q::Cache as QueryCache<CTX>>::Sharded>,
lookup: QueryLookup<'_, CTX, Q::Key, <Q::Cache as QueryCache>::Sharded>,
) -> Q::Value
where
Q: QueryDescription<CTX>,
Expand Down
0