Skip to content

Commit

Permalink
Move QueryContext to the parent module.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed Mar 27, 2020
1 parent 4faf701 commit db5be1f
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 42 deletions.
2 changes: 1 addition & 1 deletion src/librustc_query_system/query/caches.rs
@@ -1,6 +1,6 @@
use crate::dep_graph::DepNodeIndex;
use crate::query::config::QueryContext;
use crate::query::plumbing::{QueryLookup, QueryState};
use crate::query::QueryContext;

use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::sharded::Sharded;
Expand Down
40 changes: 2 additions & 38 deletions src/librustc_query_system/query/config.rs
@@ -1,20 +1,14 @@
//! Query configuration and description traits.

use crate::dep_graph::DepNode;
use crate::dep_graph::SerializedDepNodeIndex;
use crate::dep_graph::{DepContext, DepGraph, DepNode};
use crate::query::caches::QueryCache;
use crate::query::job::{QueryJobId, QueryJobInfo};
use crate::query::plumbing::CycleError;
use crate::query::QueryState;
use crate::query::{QueryContext, QueryState};
use rustc_data_structures::profiling::ProfileCategory;
use rustc_span::def_id::DefId;

use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::stable_hasher::HashStable;
use rustc_data_structures::sync::Lock;
use rustc_data_structures::thin_vec::ThinVec;
use rustc_errors::Diagnostic;
use std::borrow::Cow;
use std::fmt::Debug;
use std::hash::Hash;
Expand All @@ -29,36 +23,6 @@ pub trait QueryConfig<CTX> {
type Value: Clone;
}

pub trait QueryContext: DepContext {
type Query: Clone + HashStable<Self::StableHashingContext>;

fn incremental_verify_ich(&self) -> bool;
fn verbose(&self) -> bool;

/// Get string representation from DefPath.
fn def_path_str(&self, def_id: DefId) -> String;

/// Access the DepGraph.
fn dep_graph(&self) -> &DepGraph<Self::DepKind>;

/// Get the query information from the TLS context.
fn current_query_job(&self) -> Option<QueryJobId<Self::DepKind>>;

fn try_collect_active_jobs(
&self,
) -> Option<FxHashMap<QueryJobId<Self::DepKind>, QueryJobInfo<Self>>>;

/// Executes a job by changing the `ImplicitCtxt` to point to the
/// new query job while it executes. It returns the diagnostics
/// captured during execution and the actual result.
fn start_query<R>(
&self,
token: QueryJobId<Self::DepKind>,
diagnostics: Option<&Lock<ThinVec<Diagnostic>>>,
compute: impl FnOnce(Self) -> R,
) -> R;
}

pub trait QueryAccessors<CTX: QueryContext>: QueryConfig<CTX> {
const ANON: bool;
const EVAL_ALWAYS: bool;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_query_system/query/job.rs
@@ -1,6 +1,6 @@
use crate::dep_graph::{DepContext, DepKind};
use crate::query::config::QueryContext;
use crate::query::plumbing::CycleError;
use crate::query::QueryContext;

use rustc_data_structures::fx::FxHashMap;
use rustc_span::Span;
Expand Down
41 changes: 40 additions & 1 deletion src/librustc_query_system/query/mod.rs
Expand Up @@ -10,4 +10,43 @@ mod caches;
pub use self::caches::{CacheSelector, DefaultCacheSelector, QueryCache};

mod config;
pub use self::config::{QueryAccessors, QueryConfig, QueryContext, QueryDescription};
pub use self::config::{QueryAccessors, QueryConfig, QueryDescription};

use crate::dep_graph::{DepContext, DepGraph};

use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::stable_hasher::HashStable;
use rustc_data_structures::sync::Lock;
use rustc_data_structures::thin_vec::ThinVec;
use rustc_errors::Diagnostic;
use rustc_span::def_id::DefId;

pub trait QueryContext: DepContext {
type Query: Clone + HashStable<Self::StableHashingContext>;

fn incremental_verify_ich(&self) -> bool;
fn verbose(&self) -> bool;

/// Get string representation from DefPath.
fn def_path_str(&self, def_id: DefId) -> String;

/// Access the DepGraph.
fn dep_graph(&self) -> &DepGraph<Self::DepKind>;

/// Get the query information from the TLS context.
fn current_query_job(&self) -> Option<QueryJobId<Self::DepKind>>;

fn try_collect_active_jobs(
&self,
) -> Option<FxHashMap<QueryJobId<Self::DepKind>, QueryJobInfo<Self>>>;

/// Executes a job by changing the `ImplicitCtxt` to point to the
/// new query job while it executes. It returns the diagnostics
/// captured during execution and the actual result.
fn start_query<R>(
&self,
token: QueryJobId<Self::DepKind>,
diagnostics: Option<&Lock<ThinVec<Diagnostic>>>,
compute: impl FnOnce(Self) -> R,
) -> R;
}
3 changes: 2 additions & 1 deletion src/librustc_query_system/query/plumbing.rs
Expand Up @@ -5,8 +5,9 @@
use crate::dep_graph::{DepKind, DepNode};
use crate::dep_graph::{DepNodeIndex, SerializedDepNodeIndex};
use crate::query::caches::QueryCache;
use crate::query::config::{QueryContext, QueryDescription};
use crate::query::config::QueryDescription;
use crate::query::job::{QueryInfo, QueryJob, QueryJobId, QueryJobInfo, QueryShardJobId};
use crate::query::QueryContext;

#[cfg(not(parallel_compiler))]
use rustc_data_structures::cold_path;
Expand Down

0 comments on commit db5be1f

Please sign in to comment.