Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ use rustc_index::IndexVec;
use rustc_lint_defs::LintId;
use rustc_macros::rustc_queries;
use rustc_query_system::ich::StableHashingContext;
use rustc_query_system::query::{QueryMode, QueryStackDeferred, QueryState};
use rustc_query_system::query::{QueryMode, QueryState};
use rustc_session::Limits;
use rustc_session::config::{EntryFnType, OptLevel, OutputFilenames, SymbolManglingVersion};
use rustc_session::cstore::{
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/query/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ macro_rules! define_callbacks {
#[derive(Default)]
pub struct QueryStates<'tcx> {
$(
pub $name: QueryState<$($K)*, QueryStackDeferred<'tcx>>,
pub $name: QueryState<'tcx, $($K)*>,
)*
}

Expand Down
18 changes: 8 additions & 10 deletions compiler/rustc_query_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use rustc_query_system::dep_graph::SerializedDepNodeIndex;
use rustc_query_system::ich::StableHashingContext;
use rustc_query_system::query::{
CycleError, CycleErrorHandling, HashResult, QueryCache, QueryConfig, QueryMap, QueryMode,
QueryStackDeferred, QueryState, get_query_incr, get_query_non_incr,
QueryState, get_query_incr, get_query_non_incr,
};
use rustc_span::{ErrorGuaranteed, Span};

Expand Down Expand Up @@ -60,7 +60,7 @@ impl<'tcx, C: QueryCache, const ANON: bool, const DEPTH_LIMIT: bool, const FEEDA
}

impl<'tcx, C: QueryCache, const ANON: bool, const DEPTH_LIMIT: bool, const FEEDABLE: bool>
QueryConfig<QueryCtxt<'tcx>> for DynamicConfig<'tcx, C, ANON, DEPTH_LIMIT, FEEDABLE>
QueryConfig<'tcx, QueryCtxt<'tcx>> for DynamicConfig<'tcx, C, ANON, DEPTH_LIMIT, FEEDABLE>
where
for<'a> C::Key: HashStable<StableHashingContext<'a>>,
{
Expand All @@ -79,10 +79,7 @@ where
}

#[inline(always)]
fn query_state<'a>(
self,
qcx: QueryCtxt<'tcx>,
) -> &'a QueryState<Self::Key, QueryStackDeferred<'tcx>>
fn query_state<'a>(self, qcx: QueryCtxt<'tcx>) -> &'a QueryState<'tcx, Self::Key>
where
QueryCtxt<'tcx>: 'a,
{
Expand All @@ -91,7 +88,7 @@ where
unsafe {
&*(&qcx.tcx.query_system.states as *const QueryStates<'tcx>)
.byte_add(self.dynamic.query_state)
.cast::<QueryState<Self::Key, QueryStackDeferred<'tcx>>>()
.cast::<QueryState<'tcx, Self::Key>>()
}
}

Expand Down Expand Up @@ -198,13 +195,14 @@ where
/// and constructing a QueryConfig.
trait QueryConfigRestored<'tcx> {
type RestoredValue;
type Config: QueryConfig<QueryCtxt<'tcx>>;
type Config: QueryConfig<'tcx, QueryCtxt<'tcx>>;

const NAME: &'static &'static str;

fn config(tcx: TyCtxt<'tcx>) -> Self::Config;
fn restore(value: <Self::Config as QueryConfig<QueryCtxt<'tcx>>>::Value)
-> Self::RestoredValue;
fn restore(
value: <Self::Config as QueryConfig<'tcx, QueryCtxt<'tcx>>>::Value,
) -> Self::RestoredValue;
}

pub fn query_system<'a>(
Expand Down
39 changes: 16 additions & 23 deletions compiler/rustc_query_impl/src/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ impl<'tcx> HasDepContext for QueryCtxt<'tcx> {
}
}

impl<'tcx> QueryContext for QueryCtxt<'tcx> {
type QueryInfo = QueryStackDeferred<'tcx>;

impl<'tcx> QueryContext<'tcx> for QueryCtxt<'tcx> {
#[inline]
fn jobserver_proxy(&self) -> &Proxy {
&self.tcx.jobserver_proxy
Expand Down Expand Up @@ -93,10 +91,7 @@ impl<'tcx> QueryContext for QueryCtxt<'tcx> {
/// Prefer passing `false` to `require_complete` to avoid potential deadlocks,
/// especially when called from within a deadlock handler, unless a
/// complete map is needed and no deadlock is possible at this call site.
fn collect_active_jobs(
self,
require_complete: bool,
) -> Result<QueryMap<QueryStackDeferred<'tcx>>, QueryMap<QueryStackDeferred<'tcx>>> {
fn collect_active_jobs(self, require_complete: bool) -> Result<QueryMap<'tcx>, QueryMap<'tcx>> {
let mut jobs = QueryMap::default();
let mut complete = true;

Expand Down Expand Up @@ -319,7 +314,7 @@ macro_rules! should_ever_cache_on_disk {
};
}

fn create_query_frame_extra<'tcx, K: Key + Copy + 'tcx>(
fn mk_query_stack_frame_extra<'tcx, K: Key + Copy + 'tcx>(
(tcx, key, kind, name, do_describe): (
TyCtxt<'tcx>,
K,
Expand Down Expand Up @@ -370,18 +365,16 @@ pub(crate) fn create_query_frame<
) -> QueryStackFrame<QueryStackDeferred<'tcx>> {
let def_id = key.key_as_def_id();

let hash = || {
tcx.with_stable_hashing_context(|mut hcx| {
let mut hasher = StableHasher::new();
kind.as_usize().hash_stable(&mut hcx, &mut hasher);
key.hash_stable(&mut hcx, &mut hasher);
hasher.finish::<Hash64>()
})
};
let hash = tcx.with_stable_hashing_context(|mut hcx| {
let mut hasher = StableHasher::new();
kind.as_usize().hash_stable(&mut hcx, &mut hasher);
key.hash_stable(&mut hcx, &mut hasher);
hasher.finish::<Hash64>()
});
let def_id_for_ty_in_cycle = key.def_id_for_ty_in_cycle();

let info =
QueryStackDeferred::new((tcx, key, kind, name, do_describe), create_query_frame_extra);
QueryStackDeferred::new((tcx, key, kind, name, do_describe), mk_query_stack_frame_extra);

QueryStackFrame::new(info, kind, hash, def_id, def_id_for_ty_in_cycle)
}
Expand Down Expand Up @@ -414,7 +407,7 @@ pub(crate) fn encode_query_results<'a, 'tcx, Q>(
}

pub(crate) fn query_key_hash_verify<'tcx>(
query: impl QueryConfig<QueryCtxt<'tcx>>,
query: impl QueryConfig<'tcx, QueryCtxt<'tcx>>,
qcx: QueryCtxt<'tcx>,
) {
let _timer = qcx.tcx.prof.generic_activity_with_arg("query_key_hash_verify_for", query.name());
Expand Down Expand Up @@ -442,7 +435,7 @@ pub(crate) fn query_key_hash_verify<'tcx>(

fn try_load_from_on_disk_cache<'tcx, Q>(query: Q, tcx: TyCtxt<'tcx>, dep_node: DepNode)
where
Q: QueryConfig<QueryCtxt<'tcx>>,
Q: QueryConfig<'tcx, QueryCtxt<'tcx>>,
{
debug_assert!(tcx.dep_graph.is_green(&dep_node));

Expand Down Expand Up @@ -488,7 +481,7 @@ where

fn force_from_dep_node<'tcx, Q>(query: Q, tcx: TyCtxt<'tcx>, dep_node: DepNode) -> bool
where
Q: QueryConfig<QueryCtxt<'tcx>>,
Q: QueryConfig<'tcx, QueryCtxt<'tcx>>,
{
// We must avoid ever having to call `force_from_dep_node()` for a
// `DepNode::codegen_unit`:
Expand Down Expand Up @@ -730,14 +723,14 @@ macro_rules! define_queries {
}

#[inline(always)]
fn restore(value: <Self::Config as QueryConfig<QueryCtxt<'tcx>>>::Value) -> Self::RestoredValue {
fn restore(value: <Self::Config as QueryConfig<'tcx, QueryCtxt<'tcx>>>::Value) -> Self::RestoredValue {
restore::<queries::$name::Value<'tcx>>(value)
}
}

pub(crate) fn collect_active_jobs<'tcx>(
tcx: TyCtxt<'tcx>,
qmap: &mut QueryMap<QueryStackDeferred<'tcx>>,
qmap: &mut QueryMap<'tcx>,
require_complete: bool,
) -> Option<()> {
let make_query = |tcx, key| {
Expand Down Expand Up @@ -821,7 +814,7 @@ macro_rules! define_queries {
// These arrays are used for iteration and can't be indexed by `DepKind`.

const COLLECT_ACTIVE_JOBS: &[
for<'tcx> fn(TyCtxt<'tcx>, &mut QueryMap<QueryStackDeferred<'tcx>>, bool) -> Option<()>
for<'tcx> fn(TyCtxt<'tcx>, &mut QueryMap<'tcx>, bool) -> Option<()>
] =
&[$(query_impl::$name::collect_active_jobs),*];

Expand Down
20 changes: 12 additions & 8 deletions compiler/rustc_query_system/src/dep_graph/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,11 @@ impl<D: Deps> DepGraph<D> {
/// This encodes a diagnostic by creating a node with an unique index and associating
/// `diagnostic` with it, for use in the next session.
#[inline]
pub fn record_diagnostic<Qcx: QueryContext>(&self, qcx: Qcx, diagnostic: &DiagInner) {
pub fn record_diagnostic<'tcx, Qcx: QueryContext<'tcx>>(
&self,
qcx: Qcx,
diagnostic: &DiagInner,
) {
if let Some(ref data) = self.data {
D::read_deps(|task_deps| match task_deps {
TaskDepsRef::EvalAlways | TaskDepsRef::Ignore => return,
Expand All @@ -532,7 +536,7 @@ impl<D: Deps> DepGraph<D> {
/// This forces a diagnostic node green by running its side effect. `prev_index` would
/// refer to a node created used `encode_diagnostic` in the previous session.
#[inline]
pub fn force_diagnostic_node<Qcx: QueryContext>(
pub fn force_diagnostic_node<'tcx, Qcx: QueryContext<'tcx>>(
&self,
qcx: Qcx,
prev_index: SerializedDepNodeIndex,
Expand Down Expand Up @@ -669,7 +673,7 @@ impl<D: Deps> DepGraphData<D> {
/// This encodes a diagnostic by creating a node with an unique index and associating
/// `diagnostic` with it, for use in the next session.
#[inline]
fn encode_diagnostic<Qcx: QueryContext>(
fn encode_diagnostic<'tcx, Qcx: QueryContext<'tcx>>(
&self,
qcx: Qcx,
diagnostic: &DiagInner,
Expand All @@ -693,7 +697,7 @@ impl<D: Deps> DepGraphData<D> {
/// This forces a diagnostic node green by running its side effect. `prev_index` would
/// refer to a node created used `encode_diagnostic` in the previous session.
#[inline]
fn force_diagnostic_node<Qcx: QueryContext>(
fn force_diagnostic_node<'tcx, Qcx: QueryContext<'tcx>>(
&self,
qcx: Qcx,
prev_index: SerializedDepNodeIndex,
Expand Down Expand Up @@ -843,7 +847,7 @@ impl<D: Deps> DepGraph<D> {
DepNodeColor::Unknown
}

pub fn try_mark_green<Qcx: QueryContext<Deps = D>>(
pub fn try_mark_green<'tcx, Qcx: QueryContext<'tcx, Deps = D>>(
&self,
qcx: Qcx,
dep_node: &DepNode,
Expand All @@ -858,7 +862,7 @@ impl<D: Deps> DepGraphData<D> {
/// A node will have an index, when it's already been marked green, or when we can mark it
/// green. This function will mark the current task as a reader of the specified node, when
/// a node index can be found for that node.
pub(crate) fn try_mark_green<Qcx: QueryContext<Deps = D>>(
pub(crate) fn try_mark_green<'tcx, Qcx: QueryContext<'tcx, Deps = D>>(
&self,
qcx: Qcx,
dep_node: &DepNode,
Expand All @@ -883,7 +887,7 @@ impl<D: Deps> DepGraphData<D> {
}

#[instrument(skip(self, qcx, parent_dep_node_index, frame), level = "debug")]
fn try_mark_parent_green<Qcx: QueryContext<Deps = D>>(
fn try_mark_parent_green<'tcx, Qcx: QueryContext<'tcx, Deps = D>>(
&self,
qcx: Qcx,
parent_dep_node_index: SerializedDepNodeIndex,
Expand Down Expand Up @@ -973,7 +977,7 @@ impl<D: Deps> DepGraphData<D> {

/// Try to mark a dep-node which existed in the previous compilation session as green.
#[instrument(skip(self, qcx, prev_dep_node_index, frame), level = "debug")]
fn try_mark_previous_green<Qcx: QueryContext<Deps = D>>(
fn try_mark_previous_green<'tcx, Qcx: QueryContext<'tcx, Deps = D>>(
&self,
qcx: Qcx,
prev_dep_node_index: SerializedDepNodeIndex,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_query_system/src/query/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::query::{CycleError, CycleErrorHandling, DepNodeIndex, QueryContext, Q

pub type HashResult<V> = Option<fn(&mut StableHashingContext<'_>, &V) -> Fingerprint>;

pub trait QueryConfig<Qcx: QueryContext>: Copy {
pub trait QueryConfig<'tcx, Qcx: QueryContext<'tcx>>: Copy {
fn name(self) -> &'static str;

// `Key` and `Value` are `Copy` instead of `Clone` to ensure copying them stays cheap,
Expand All @@ -27,7 +27,7 @@ pub trait QueryConfig<Qcx: QueryContext>: Copy {
fn format_value(self) -> fn(&Self::Value) -> String;

// Don't use this method to access query results, instead use the methods on TyCtxt
fn query_state<'a>(self, tcx: Qcx) -> &'a QueryState<Self::Key, Qcx::QueryInfo>
fn query_state<'a>(self, tcx: Qcx) -> &'a QueryState<'tcx, Self::Key>
where
Qcx: 'a;

Expand Down
Loading
Loading