Skip to content

Commit 48bcaf7

Browse files
committed
Revert the QueryStackFrameExtra/QueryStackDeferred split.
PR rust-lang#138672 introduced a complex and invasive split of `QueryStackFrame` to avoid a query cycle. This commit reverts that change because there is a much simpler change that fixes the problem, which will be in the next commit.
1 parent 2e58d05 commit 48bcaf7

9 files changed

Lines changed: 145 additions & 286 deletions

File tree

compiler/rustc_middle/src/query/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ use rustc_index::IndexVec;
8787
use rustc_lint_defs::LintId;
8888
use rustc_macros::rustc_queries;
8989
use rustc_query_system::ich::StableHashingContext;
90-
use rustc_query_system::query::{QueryMode, QueryStackDeferred, QueryState};
90+
use rustc_query_system::query::{QueryMode, QueryState};
9191
use rustc_session::Limits;
9292
use rustc_session::config::{EntryFnType, OptLevel, OutputFilenames, SymbolManglingVersion};
9393
use rustc_session::cstore::{

compiler/rustc_middle/src/query/plumbing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ macro_rules! define_callbacks {
431431
#[derive(Default)]
432432
pub struct QueryStates<'tcx> {
433433
$(
434-
pub $name: QueryState<$($K)*, QueryStackDeferred<'tcx>>,
434+
pub $name: QueryState<$($K)*>,
435435
)*
436436
}
437437

compiler/rustc_middle/src/values.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl<'tcx> Value<TyCtxt<'tcx>> for Representability {
8888
if info.query.dep_kind == dep_kinds::representability
8989
&& let Some(field_id) = info.query.def_id
9090
&& let Some(field_id) = field_id.as_local()
91-
&& let Some(DefKind::Field) = info.query.info.def_kind
91+
&& let Some(DefKind::Field) = info.query.def_kind
9292
{
9393
let parent_id = tcx.parent(field_id.to_def_id());
9494
let item_id = match tcx.def_kind(parent_id) {
@@ -224,7 +224,7 @@ impl<'tcx, T> Value<TyCtxt<'tcx>> for Result<T, &'_ ty::layout::LayoutError<'_>>
224224
continue;
225225
};
226226
let frame_span =
227-
frame.query.info.default_span(cycle[(i + 1) % cycle.len()].span);
227+
frame.query.default_span(cycle[(i + 1) % cycle.len()].span);
228228
if frame_span.is_dummy() {
229229
continue;
230230
}

compiler/rustc_query_impl/src/lib.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ use rustc_middle::ty::TyCtxt;
2121
use rustc_query_system::dep_graph::SerializedDepNodeIndex;
2222
use rustc_query_system::ich::StableHashingContext;
2323
use rustc_query_system::query::{
24-
CycleError, HashResult, QueryCache, QueryConfig, QueryMap, QueryMode, QueryStackDeferred,
25-
QueryState, get_query_incr, get_query_non_incr,
24+
CycleError, HashResult, QueryCache, QueryConfig, QueryMap, QueryMode, QueryState,
25+
get_query_incr, get_query_non_incr,
2626
};
2727
use rustc_query_system::{HandleCycleError, Value};
2828
use rustc_span::{ErrorGuaranteed, Span};
@@ -79,10 +79,7 @@ where
7979
}
8080

8181
#[inline(always)]
82-
fn query_state<'a>(
83-
self,
84-
qcx: QueryCtxt<'tcx>,
85-
) -> &'a QueryState<Self::Key, QueryStackDeferred<'tcx>>
82+
fn query_state<'a>(self, qcx: QueryCtxt<'tcx>) -> &'a QueryState<Self::Key>
8683
where
8784
QueryCtxt<'tcx>: 'a,
8885
{
@@ -91,7 +88,7 @@ where
9188
unsafe {
9289
&*(&qcx.tcx.query_system.states as *const QueryStates<'tcx>)
9390
.byte_add(self.dynamic.query_state)
94-
.cast::<QueryState<Self::Key, QueryStackDeferred<'tcx>>>()
91+
.cast::<QueryState<Self::Key>>()
9592
}
9693
}
9794

compiler/rustc_query_impl/src/plumbing.rs

Lines changed: 27 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use std::num::NonZero;
66

77
use rustc_data_structures::jobserver::Proxy;
88
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
9-
use rustc_data_structures::sync::{DynSend, DynSync};
109
use rustc_data_structures::unord::UnordMap;
1110
use rustc_hashes::Hash64;
1211
use rustc_hir::limit::Limit;
@@ -27,8 +26,8 @@ use rustc_middle::ty::{self, TyCtxt};
2726
use rustc_query_system::dep_graph::{DepNodeParams, HasDepContext};
2827
use rustc_query_system::ich::StableHashingContext;
2928
use rustc_query_system::query::{
30-
QueryCache, QueryConfig, QueryContext, QueryJobId, QueryMap, QuerySideEffect,
31-
QueryStackDeferred, QueryStackFrame, QueryStackFrameExtra, force_query,
29+
QueryCache, QueryConfig, QueryContext, QueryJobId, QueryMap, QuerySideEffect, QueryStackFrame,
30+
force_query,
3231
};
3332
use rustc_query_system::{QueryOverflow, QueryOverflowNote};
3433
use rustc_serialize::{Decodable, Encodable};
@@ -67,9 +66,7 @@ impl<'tcx> HasDepContext for QueryCtxt<'tcx> {
6766
}
6867
}
6968

70-
impl<'tcx> QueryContext for QueryCtxt<'tcx> {
71-
type QueryInfo = QueryStackDeferred<'tcx>;
72-
69+
impl QueryContext for QueryCtxt<'_> {
7370
#[inline]
7471
fn jobserver_proxy(&self) -> &Proxy {
7572
&*self.jobserver_proxy
@@ -98,10 +95,7 @@ impl<'tcx> QueryContext for QueryCtxt<'tcx> {
9895
/// Prefer passing `false` to `require_complete` to avoid potential deadlocks,
9996
/// especially when called from within a deadlock handler, unless a
10097
/// complete map is needed and no deadlock is possible at this call site.
101-
fn collect_active_jobs(
102-
self,
103-
require_complete: bool,
104-
) -> Result<QueryMap<QueryStackDeferred<'tcx>>, QueryMap<QueryStackDeferred<'tcx>>> {
98+
fn collect_active_jobs(self, require_complete: bool) -> Result<QueryMap, QueryMap> {
10599
let mut jobs = QueryMap::default();
106100
let mut complete = true;
107101

@@ -114,13 +108,6 @@ impl<'tcx> QueryContext for QueryCtxt<'tcx> {
114108
if complete { Ok(jobs) } else { Err(jobs) }
115109
}
116110

117-
fn lift_query_info(
118-
self,
119-
info: &QueryStackDeferred<'tcx>,
120-
) -> rustc_query_system::query::QueryStackFrameExtra {
121-
info.extract()
122-
}
123-
124111
// Interactions with on_disk_cache
125112
fn load_side_effect(
126113
self,
@@ -181,10 +168,7 @@ impl<'tcx> QueryContext for QueryCtxt<'tcx> {
181168

182169
self.sess.dcx().emit_fatal(QueryOverflow {
183170
span: info.job.span,
184-
note: QueryOverflowNote {
185-
desc: self.lift_query_info(&info.query.info).description,
186-
depth,
187-
},
171+
note: QueryOverflowNote { desc: info.query.description, depth },
188172
suggested_limit,
189173
crate_name: self.crate_name(LOCAL_CRATE),
190174
});
@@ -321,17 +305,16 @@ macro_rules! should_ever_cache_on_disk {
321305
};
322306
}
323307

324-
fn create_query_frame_extra<'tcx, K: Key + Copy + 'tcx>(
325-
(tcx, key, kind, name, do_describe): (
326-
TyCtxt<'tcx>,
327-
K,
328-
DepKind,
329-
&'static str,
330-
fn(TyCtxt<'tcx>, K) -> String,
331-
),
332-
) -> QueryStackFrameExtra {
333-
let def_id = key.key_as_def_id();
334-
308+
pub(crate) fn create_query_frame<
309+
'tcx,
310+
K: Copy + Key + for<'a> HashStable<StableHashingContext<'a>>,
311+
>(
312+
tcx: TyCtxt<'tcx>,
313+
do_describe: fn(TyCtxt<'tcx>, K) -> String,
314+
key: K,
315+
kind: DepKind,
316+
name: &'static str,
317+
) -> QueryStackFrame {
335318
// If reduced queries are requested, we may be printing a query stack due
336319
// to a panic. Avoid using `default_span` and `def_kind` in that case.
337320
let reduce_queries = with_reduced_queries();
@@ -343,6 +326,7 @@ fn create_query_frame_extra<'tcx, K: Key + Copy + 'tcx>(
343326
} else {
344327
description
345328
};
329+
346330
let span = if kind == dep_graph::dep_kinds::def_span || reduce_queries {
347331
// The `def_span` query is used to calculate `default_span`,
348332
// so exit to avoid infinite recursion.
@@ -351,41 +335,25 @@ fn create_query_frame_extra<'tcx, K: Key + Copy + 'tcx>(
351335
Some(key.default_span(tcx))
352336
};
353337

338+
let def_id = key.key_as_def_id();
339+
354340
let def_kind = if kind == dep_graph::dep_kinds::def_kind || reduce_queries {
355341
// Try to avoid infinite recursion.
356342
None
357343
} else {
358344
def_id.and_then(|def_id| def_id.as_local()).map(|def_id| tcx.def_kind(def_id))
359345
};
360-
QueryStackFrameExtra::new(description, span, def_kind)
361-
}
362-
363-
pub(crate) fn create_query_frame<
364-
'tcx,
365-
K: Copy + DynSend + DynSync + Key + for<'a> HashStable<StableHashingContext<'a>> + 'tcx,
366-
>(
367-
tcx: TyCtxt<'tcx>,
368-
do_describe: fn(TyCtxt<'tcx>, K) -> String,
369-
key: K,
370-
kind: DepKind,
371-
name: &'static str,
372-
) -> QueryStackFrame<QueryStackDeferred<'tcx>> {
373-
let def_id = key.key_as_def_id();
374346

375-
let hash = || {
376-
tcx.with_stable_hashing_context(|mut hcx| {
377-
let mut hasher = StableHasher::new();
378-
kind.as_usize().hash_stable(&mut hcx, &mut hasher);
379-
key.hash_stable(&mut hcx, &mut hasher);
380-
hasher.finish::<Hash64>()
381-
})
382-
};
383347
let def_id_for_ty_in_cycle = key.def_id_for_ty_in_cycle();
384348

385-
let info =
386-
QueryStackDeferred::new((tcx, key, kind, name, do_describe), create_query_frame_extra);
349+
let hash = tcx.with_stable_hashing_context(|mut hcx| {
350+
let mut hasher = StableHasher::new();
351+
kind.as_usize().hash_stable(&mut hcx, &mut hasher);
352+
key.hash_stable(&mut hcx, &mut hasher);
353+
hasher.finish::<Hash64>()
354+
});
387355

388-
QueryStackFrame::new(info, kind, hash, def_id, def_id_for_ty_in_cycle)
356+
QueryStackFrame::new(description, span, def_id, def_kind, kind, def_id_for_ty_in_cycle, hash)
389357
}
390358

391359
pub(crate) fn encode_query_results<'a, 'tcx, Q>(
@@ -737,7 +705,7 @@ macro_rules! define_queries {
737705

738706
pub(crate) fn collect_active_jobs<'tcx>(
739707
tcx: TyCtxt<'tcx>,
740-
qmap: &mut QueryMap<QueryStackDeferred<'tcx>>,
708+
qmap: &mut QueryMap,
741709
require_complete: bool,
742710
) -> Option<()> {
743711
let make_query = |tcx, key| {
@@ -821,7 +789,7 @@ macro_rules! define_queries {
821789
// These arrays are used for iteration and can't be indexed by `DepKind`.
822790

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

compiler/rustc_query_system/src/query/config.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use std::hash::Hash;
66
use rustc_data_structures::fingerprint::Fingerprint;
77
use rustc_span::ErrorGuaranteed;
88

9-
use super::QueryStackFrameExtra;
109
use crate::dep_graph::{DepKind, DepNode, DepNodeParams, SerializedDepNodeIndex};
1110
use crate::error::HandleCycleError;
1211
use crate::ich::StableHashingContext;
@@ -28,7 +27,7 @@ pub trait QueryConfig<Qcx: QueryContext>: Copy {
2827
fn format_value(self) -> fn(&Self::Value) -> String;
2928

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

@@ -58,7 +57,7 @@ pub trait QueryConfig<Qcx: QueryContext>: Copy {
5857
fn value_from_cycle_error(
5958
self,
6059
tcx: Qcx::DepContext,
61-
cycle_error: &CycleError<QueryStackFrameExtra>,
60+
cycle_error: &CycleError,
6261
guar: ErrorGuaranteed,
6362
) -> Self::Value;
6463

0 commit comments

Comments
 (0)