Skip to content

Commit

Permalink
Fix #107910, Shorten backtraces in ICEs
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyukang committed Mar 9, 2023
1 parent 39f2657 commit 1e80402
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
1 change: 1 addition & 0 deletions compiler/rustc_query_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ pub use on_disk_cache::OnDiskCache;

mod profiling_support;
pub use self::profiling_support::alloc_self_profile_query_strings;
use rustc_query_system::dep_graph::__rust_begin_short_backtrace;

rustc_query_append! { define_queries! }

Expand Down
14 changes: 8 additions & 6 deletions compiler/rustc_query_impl/src/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -779,12 +779,14 @@ macro_rules! define_queries_struct {
mode: QueryMode,
) -> Option<query_values::$name<'tcx>> {
let qcx = QueryCtxt { tcx, queries: self };
get_query(
queries::$name::default(),
qcx,
span,
key,
mode
__rust_begin_short_backtrace(||
get_query(
queries::$name::default(),
qcx,
span,
key,
mode
)
)
})*
}
Expand Down
12 changes: 12 additions & 0 deletions compiler/rustc_query_system/src/dep_graph/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,15 @@ impl<K: DepKind> EdgeFilter<K> {
self.source.test(source) && self.target.test(target)
}
}

#[inline(never)]
pub fn __rust_begin_short_backtrace<F, T>(f: F) -> T
where
F: FnOnce() -> T,
{
let result = f();
// prevent this frame from being tail-call optimised away
std::hint::black_box(());

result
}
3 changes: 2 additions & 1 deletion compiler/rustc_query_system/src/dep_graph/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use std::sync::atomic::Ordering::Relaxed;
use super::query::DepGraphQuery;
use super::serialized::{GraphEncoder, SerializedDepGraph, SerializedDepNodeIndex};
use super::{DepContext, DepKind, DepNode, HasDepContext, WorkProductId};
use crate::dep_graph::debug::__rust_begin_short_backtrace;
use crate::ich::StableHashingContext;
use crate::query::{QueryContext, QuerySideEffects};

Expand Down Expand Up @@ -340,7 +341,7 @@ impl<K: DepKind> DepGraph<K> {
None => TaskDepsRef::Ignore,
};

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

let dcx = cx.dep_context();
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_query_system/src/dep_graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ mod graph;
mod query;
mod serialized;

pub use crate::dep_graph::debug::__rust_begin_short_backtrace;
pub use dep_node::{DepKindStruct, DepNode, DepNodeParams, WorkProductId};
pub use graph::{
hash_result, DepGraph, DepNodeColor, DepNodeIndex, TaskDeps, TaskDepsRef, WorkProduct,
Expand Down

0 comments on commit 1e80402

Please sign in to comment.