Skip to content

Commit 57e950b

Browse files
authored
Rollup merge of rust-lang#151203 - revert-QueryStackFrame-split, r=oli-obk
Revert `QueryStackFrame` split PR rust-lang#138672 fixed a query cycle OOM reported in rust-lang#124901. The fix involved delaying computation of some query stack frame elements and was very complex. It involved the addition of two new types, the addition of a generic `I` parameter to eleven(!) other types, a `PhantomData` field, and even required an unsafe transmute of a closure. [This comment](rust-lang#124901 (comment)) had suggested a much simpler fix, but it was ignored. The PR also failed to add a test case. This PR adds a test case, reverts the complex fix, applies the simpler fix, and does a few other minor cleanups. r? @oli-obk
2 parents 712a178 + 90e4a42 commit 57e950b

12 files changed

Lines changed: 210 additions & 313 deletions

File tree

compiler/rustc_macros/src/query.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ struct QueryModifiers {
9393
cache: Option<(Option<Pat>, Block)>,
9494

9595
/// A cycle error for this query aborting the compilation with a fatal error.
96-
fatal_cycle: Option<Ident>,
96+
cycle_fatal: Option<Ident>,
9797

9898
/// A cycle error results in a delay_bug call
9999
cycle_delay_bug: Option<Ident>,
@@ -136,7 +136,7 @@ fn parse_query_modifiers(input: ParseStream<'_>) -> Result<QueryModifiers> {
136136
let mut arena_cache = None;
137137
let mut cache = None;
138138
let mut desc = None;
139-
let mut fatal_cycle = None;
139+
let mut cycle_fatal = None;
140140
let mut cycle_delay_bug = None;
141141
let mut cycle_stash = None;
142142
let mut no_hash = None;
@@ -189,8 +189,8 @@ fn parse_query_modifiers(input: ParseStream<'_>) -> Result<QueryModifiers> {
189189
try_insert!(cache = (args, block));
190190
} else if modifier == "arena_cache" {
191191
try_insert!(arena_cache = modifier);
192-
} else if modifier == "fatal_cycle" {
193-
try_insert!(fatal_cycle = modifier);
192+
} else if modifier == "cycle_fatal" {
193+
try_insert!(cycle_fatal = modifier);
194194
} else if modifier == "cycle_delay_bug" {
195195
try_insert!(cycle_delay_bug = modifier);
196196
} else if modifier == "cycle_stash" {
@@ -220,7 +220,7 @@ fn parse_query_modifiers(input: ParseStream<'_>) -> Result<QueryModifiers> {
220220
arena_cache,
221221
cache,
222222
desc,
223-
fatal_cycle,
223+
cycle_fatal,
224224
cycle_delay_bug,
225225
cycle_stash,
226226
no_hash,
@@ -366,8 +366,8 @@ pub(super) fn rustc_queries(input: TokenStream) -> TokenStream {
366366
}
367367

368368
passthrough!(
369-
fatal_cycle,
370369
arena_cache,
370+
cycle_fatal,
371371
cycle_delay_bug,
372372
cycle_stash,
373373
no_hash,

compiler/rustc_middle/src/query/mod.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
//! - `desc { ... }`: Sets the human-readable description for diagnostics and profiling. Required for every query.
2929
//! - `arena_cache`: Use an arena for in-memory caching of the query result.
3030
//! - `cache_on_disk_if { ... }`: Cache the query result to disk if the provided block evaluates to true.
31-
//! - `fatal_cycle`: If a dependency cycle is detected, abort compilation with a fatal error.
31+
//! - `cycle_fatal`: If a dependency cycle is detected, abort compilation with a fatal error.
3232
//! - `cycle_delay_bug`: If a dependency cycle is detected, emit a delayed bug instead of aborting immediately.
3333
//! - `cycle_stash`: If a dependency cycle is detected, stash the error for later handling.
3434
//! - `no_hash`: Do not hash the query result for incremental compilation; just mark as dirty if recomputed.
@@ -88,7 +88,7 @@ use rustc_index::IndexVec;
8888
use rustc_lint_defs::LintId;
8989
use rustc_macros::rustc_queries;
9090
use rustc_query_system::ich::StableHashingContext;
91-
use rustc_query_system::query::{QueryMode, QueryStackDeferred, QueryState};
91+
use rustc_query_system::query::{QueryMode, QueryState};
9292
use rustc_session::Limits;
9393
use rustc_session::config::{EntryFnType, OptLevel, OutputFilenames, SymbolManglingVersion};
9494
use rustc_session::cstore::{
@@ -161,7 +161,7 @@ pub mod plumbing;
161161
// The result type of each query must implement `Clone`, and additionally
162162
// `ty::query::values::Value`, which produces an appropriate placeholder
163163
// (error) value if the query resulted in a query cycle.
164-
// Queries marked with `fatal_cycle` do not need the latter implementation,
164+
// Queries marked with `cycle_fatal` do not need the latter implementation,
165165
// as they will raise an fatal error on query cycles instead.
166166
rustc_queries! {
167167
/// Caches the expansion of a derive proc macro, e.g. `#[derive(Serialize)]`.
@@ -596,7 +596,7 @@ rustc_queries! {
596596
}
597597

598598
query is_panic_runtime(_: CrateNum) -> bool {
599-
fatal_cycle
599+
cycle_fatal
600600
desc { "checking if the crate is_panic_runtime" }
601601
separate_provide_extern
602602
}
@@ -1327,7 +1327,7 @@ rustc_queries! {
13271327
/// Return the set of (transitive) callees that may result in a recursive call to `key`,
13281328
/// if we were able to walk all callees.
13291329
query mir_callgraph_cyclic(key: LocalDefId) -> &'tcx Option<UnordSet<LocalDefId>> {
1330-
fatal_cycle
1330+
cycle_fatal
13311331
arena_cache
13321332
desc { |tcx|
13331333
"computing (transitive) callees of `{}` that may recurse",
@@ -1338,7 +1338,7 @@ rustc_queries! {
13381338

13391339
/// Obtain all the calls into other local functions
13401340
query mir_inliner_callees(key: ty::InstanceKind<'tcx>) -> &'tcx [(DefId, GenericArgsRef<'tcx>)] {
1341-
fatal_cycle
1341+
cycle_fatal
13421342
desc { |tcx|
13431343
"computing all local function calls in `{}`",
13441344
tcx.def_path_str(key.def_id()),
@@ -1834,31 +1834,31 @@ rustc_queries! {
18341834
}
18351835

18361836
query is_compiler_builtins(_: CrateNum) -> bool {
1837-
fatal_cycle
1837+
cycle_fatal
18381838
desc { "checking if the crate is_compiler_builtins" }
18391839
separate_provide_extern
18401840
}
18411841
query has_global_allocator(_: CrateNum) -> bool {
18421842
// This query depends on untracked global state in CStore
18431843
eval_always
1844-
fatal_cycle
1844+
cycle_fatal
18451845
desc { "checking if the crate has_global_allocator" }
18461846
separate_provide_extern
18471847
}
18481848
query has_alloc_error_handler(_: CrateNum) -> bool {
18491849
// This query depends on untracked global state in CStore
18501850
eval_always
1851-
fatal_cycle
1851+
cycle_fatal
18521852
desc { "checking if the crate has_alloc_error_handler" }
18531853
separate_provide_extern
18541854
}
18551855
query has_panic_handler(_: CrateNum) -> bool {
1856-
fatal_cycle
1856+
cycle_fatal
18571857
desc { "checking if the crate has_panic_handler" }
18581858
separate_provide_extern
18591859
}
18601860
query is_profiler_runtime(_: CrateNum) -> bool {
1861-
fatal_cycle
1861+
cycle_fatal
18621862
desc { "checking if a crate is `#![profiler_runtime]`" }
18631863
separate_provide_extern
18641864
}
@@ -1867,22 +1867,22 @@ rustc_queries! {
18671867
cache_on_disk_if { true }
18681868
}
18691869
query required_panic_strategy(_: CrateNum) -> Option<PanicStrategy> {
1870-
fatal_cycle
1870+
cycle_fatal
18711871
desc { "getting a crate's required panic strategy" }
18721872
separate_provide_extern
18731873
}
18741874
query panic_in_drop_strategy(_: CrateNum) -> PanicStrategy {
1875-
fatal_cycle
1875+
cycle_fatal
18761876
desc { "getting a crate's configured panic-in-drop strategy" }
18771877
separate_provide_extern
18781878
}
18791879
query is_no_builtins(_: CrateNum) -> bool {
1880-
fatal_cycle
1880+
cycle_fatal
18811881
desc { "getting whether a crate has `#![no_builtins]`" }
18821882
separate_provide_extern
18831883
}
18841884
query symbol_mangling_version(_: CrateNum) -> SymbolManglingVersion {
1885-
fatal_cycle
1885+
cycle_fatal
18861886
desc { "getting a crate's symbol mangling version" }
18871887
separate_provide_extern
18881888
}

compiler/rustc_middle/src/query/plumbing.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ macro_rules! define_callbacks {
278278
($V)
279279
);
280280

281-
/// This function takes `ProvidedValue` and coverts it to an erased `Value` by
281+
/// This function takes `ProvidedValue` and converts it to an erased `Value` by
282282
/// allocating it on an arena if the query has the `arena_cache` modifier. The
283283
/// value is then erased and returned. This will happen when computing the query
284284
/// using a provider or decoding a stored result.
@@ -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

@@ -532,7 +532,7 @@ macro_rules! define_feedable {
532532
// The result type of each query must implement `Clone`, and additionally
533533
// `ty::query::values::Value`, which produces an appropriate placeholder
534534
// (error) value if the query resulted in a query cycle.
535-
// Queries marked with `fatal_cycle` do not need the latter implementation,
535+
// Queries marked with `cycle_fatal` do not need the latter implementation,
536536
// as they will raise an fatal error on query cycles instead.
537537

538538
mod sealed {

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

0 commit comments

Comments
 (0)