Skip to content

Commit 9b1a7a9

Browse files
committed
chore(query_system): Improve error reporting esp. during unwinding
1 parent 8698ba3 commit 9b1a7a9

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

compiler/rustc_query_impl/src/plumbing.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -702,11 +702,18 @@ macro_rules! define_queries {
702702
let name = stringify!($name);
703703
$crate::plumbing::create_query_frame(tcx, rustc_middle::query::descs::$name, key, kind, name)
704704
};
705-
tcx.query_system.states.$name.try_collect_active_jobs(
705+
let res = tcx.query_system.states.$name.try_collect_active_jobs(
706706
tcx,
707707
make_query,
708708
qmap,
709-
).unwrap();
709+
);
710+
// this can be called during unwinding, and the function has a `try_`-prefix, so
711+
// don't `unwrap()` here, just manually check for `None` and do best-effort error
712+
// reporting.
713+
if res.is_none() {
714+
// TODO: something else than just `eprintln!`?
715+
eprintln!("Failed to collect active jobs for query with name `{}`!", stringify!($name));
716+
}
710717
}
711718

712719
pub fn alloc_self_profile_query_strings<'tcx>(tcx: TyCtxt<'tcx>, string_cache: &mut QueryKeyStringCache) {

compiler/rustc_query_system/src/query/plumbing.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,14 @@ where
181181
cache.complete(key, result, dep_node_index);
182182

183183
let job = {
184-
let mut lock = state.active.lock_shard_by_value(&key);
185-
lock.remove(&key).unwrap().expect_job()
184+
let val = {
185+
// don't keep the lock during the `unwrap()` of the retrieved value, or we taint the
186+
// underlying shard.
187+
// since unwinding also wants to look at this map, just avoid it.
188+
let mut lock = state.active.lock_shard_by_value(&key);
189+
lock.remove(&key)
190+
};
191+
val.unwrap().expect_job()
186192
};
187193

188194
job.signal_complete();

0 commit comments

Comments
 (0)