Skip to content

Commit 94d9f65

Browse files
authored
Unrolled build for #151203
Rollup merge of #151203 - revert-QueryStackFrame-split, r=oli-obk Revert `QueryStackFrame` split PR #138672 fixed a query cycle OOM reported in #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](#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 b08c11d + 90e4a42 commit 94d9f65

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.
@@ -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::{
@@ -160,7 +160,7 @@ pub mod plumbing;
160160
// The result type of each query must implement `Clone`, and additionally
161161
// `ty::query::values::Value`, which produces an appropriate placeholder
162162
// (error) value if the query resulted in a query cycle.
163-
// Queries marked with `fatal_cycle` do not need the latter implementation,
163+
// Queries marked with `cycle_fatal` do not need the latter implementation,
164164
// as they will raise an fatal error on query cycles instead.
165165
rustc_queries! {
166166
/// This exists purely for testing the interactions between delayed bugs and incremental.
@@ -584,7 +584,7 @@ rustc_queries! {
584584
}
585585

586586
query is_panic_runtime(_: CrateNum) -> bool {
587-
fatal_cycle
587+
cycle_fatal
588588
desc { "checking if the crate is_panic_runtime" }
589589
separate_provide_extern
590590
}
@@ -1315,7 +1315,7 @@ rustc_queries! {
13151315
/// Return the set of (transitive) callees that may result in a recursive call to `key`,
13161316
/// if we were able to walk all callees.
13171317
query mir_callgraph_cyclic(key: LocalDefId) -> &'tcx Option<UnordSet<LocalDefId>> {
1318-
fatal_cycle
1318+
cycle_fatal
13191319
arena_cache
13201320
desc { |tcx|
13211321
"computing (transitive) callees of `{}` that may recurse",
@@ -1326,7 +1326,7 @@ rustc_queries! {
13261326

13271327
/// Obtain all the calls into other local functions
13281328
query mir_inliner_callees(key: ty::InstanceKind<'tcx>) -> &'tcx [(DefId, GenericArgsRef<'tcx>)] {
1329-
fatal_cycle
1329+
cycle_fatal
13301330
desc { |tcx|
13311331
"computing all local function calls in `{}`",
13321332
tcx.def_path_str(key.def_id()),
@@ -1822,31 +1822,31 @@ rustc_queries! {
18221822
}
18231823

18241824
query is_compiler_builtins(_: CrateNum) -> bool {
1825-
fatal_cycle
1825+
cycle_fatal
18261826
desc { "checking if the crate is_compiler_builtins" }
18271827
separate_provide_extern
18281828
}
18291829
query has_global_allocator(_: CrateNum) -> bool {
18301830
// This query depends on untracked global state in CStore
18311831
eval_always
1832-
fatal_cycle
1832+
cycle_fatal
18331833
desc { "checking if the crate has_global_allocator" }
18341834
separate_provide_extern
18351835
}
18361836
query has_alloc_error_handler(_: CrateNum) -> bool {
18371837
// This query depends on untracked global state in CStore
18381838
eval_always
1839-
fatal_cycle
1839+
cycle_fatal
18401840
desc { "checking if the crate has_alloc_error_handler" }
18411841
separate_provide_extern
18421842
}
18431843
query has_panic_handler(_: CrateNum) -> bool {
1844-
fatal_cycle
1844+
cycle_fatal
18451845
desc { "checking if the crate has_panic_handler" }
18461846
separate_provide_extern
18471847
}
18481848
query is_profiler_runtime(_: CrateNum) -> bool {
1849-
fatal_cycle
1849+
cycle_fatal
18501850
desc { "checking if a crate is `#![profiler_runtime]`" }
18511851
separate_provide_extern
18521852
}
@@ -1855,22 +1855,22 @@ rustc_queries! {
18551855
cache_on_disk_if { true }
18561856
}
18571857
query required_panic_strategy(_: CrateNum) -> Option<PanicStrategy> {
1858-
fatal_cycle
1858+
cycle_fatal
18591859
desc { "getting a crate's required panic strategy" }
18601860
separate_provide_extern
18611861
}
18621862
query panic_in_drop_strategy(_: CrateNum) -> PanicStrategy {
1863-
fatal_cycle
1863+
cycle_fatal
18641864
desc { "getting a crate's configured panic-in-drop strategy" }
18651865
separate_provide_extern
18661866
}
18671867
query is_no_builtins(_: CrateNum) -> bool {
1868-
fatal_cycle
1868+
cycle_fatal
18691869
desc { "getting whether a crate has `#![no_builtins]`" }
18701870
separate_provide_extern
18711871
}
18721872
query symbol_mangling_version(_: CrateNum) -> SymbolManglingVersion {
1873-
fatal_cycle
1873+
cycle_fatal
18741874
desc { "getting a crate's symbol mangling version" }
18751875
separate_provide_extern
18761876
}

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)