Skip to content

Commit 1e80402

Browse files
committed
Fix #107910, Shorten backtraces in ICEs
1 parent 39f2657 commit 1e80402

File tree

5 files changed

+24
-7
lines changed

5 files changed

+24
-7
lines changed

compiler/rustc_query_impl/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ pub use on_disk_cache::OnDiskCache;
4242

4343
mod profiling_support;
4444
pub use self::profiling_support::alloc_self_profile_query_strings;
45+
use rustc_query_system::dep_graph::__rust_begin_short_backtrace;
4546

4647
rustc_query_append! { define_queries! }
4748

compiler/rustc_query_impl/src/plumbing.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -779,12 +779,14 @@ macro_rules! define_queries_struct {
779779
mode: QueryMode,
780780
) -> Option<query_values::$name<'tcx>> {
781781
let qcx = QueryCtxt { tcx, queries: self };
782-
get_query(
783-
queries::$name::default(),
784-
qcx,
785-
span,
786-
key,
787-
mode
782+
__rust_begin_short_backtrace(||
783+
get_query(
784+
queries::$name::default(),
785+
qcx,
786+
span,
787+
key,
788+
mode
789+
)
788790
)
789791
})*
790792
}

compiler/rustc_query_system/src/dep_graph/debug.rs

+12
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,15 @@ impl<K: DepKind> EdgeFilter<K> {
6161
self.source.test(source) && self.target.test(target)
6262
}
6363
}
64+
65+
#[inline(never)]
66+
pub fn __rust_begin_short_backtrace<F, T>(f: F) -> T
67+
where
68+
F: FnOnce() -> T,
69+
{
70+
let result = f();
71+
// prevent this frame from being tail-call optimised away
72+
std::hint::black_box(());
73+
74+
result
75+
}

compiler/rustc_query_system/src/dep_graph/graph.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use std::sync::atomic::Ordering::Relaxed;
2020
use super::query::DepGraphQuery;
2121
use super::serialized::{GraphEncoder, SerializedDepGraph, SerializedDepNodeIndex};
2222
use super::{DepContext, DepKind, DepNode, HasDepContext, WorkProductId};
23+
use crate::dep_graph::debug::__rust_begin_short_backtrace;
2324
use crate::ich::StableHashingContext;
2425
use crate::query::{QueryContext, QuerySideEffects};
2526

@@ -340,7 +341,7 @@ impl<K: DepKind> DepGraph<K> {
340341
None => TaskDepsRef::Ignore,
341342
};
342343

343-
let result = K::with_deps(task_deps_ref, || task(cx, arg));
344+
let result = __rust_begin_short_backtrace(|| K::with_deps(task_deps_ref, || task(cx, arg)));
344345
let edges = task_deps.map_or_else(|| smallvec![], |lock| lock.into_inner().reads);
345346

346347
let dcx = cx.dep_context();

compiler/rustc_query_system/src/dep_graph/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ mod graph;
44
mod query;
55
mod serialized;
66

7+
pub use crate::dep_graph::debug::__rust_begin_short_backtrace;
78
pub use dep_node::{DepKindStruct, DepNode, DepNodeParams, WorkProductId};
89
pub use graph::{
910
hash_result, DepGraph, DepNodeColor, DepNodeIndex, TaskDeps, TaskDepsRef, WorkProduct,

0 commit comments

Comments
 (0)