Skip to content

Commit db5ed4b

Browse files
committed
Allow for try_force_from_dep_node to fail
The way it is implemented currently try_force_from_dep_node returns true as long as there's a function to force the query. It wasn't this way from the beginning, earlier version was producing forcing result and it was changed in rust-lang#89978, I couldn't find any comments addressing this change. One way it can fail is by failing to recover the query in DepNodeParams::recover - when we are trying to query something that no longer exists in the current environment
1 parent 3c0f019 commit db5ed4b

File tree

2 files changed

+51
-7
lines changed

2 files changed

+51
-7
lines changed

Diff for: compiler/rustc_query_system/src/dep_graph/mod.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,24 @@ pub trait DepContext: Copy {
5151
}
5252

5353
/// Try to force a dep node to execute and see if it's green.
54+
///
55+
/// Returns true if the query has actually been forced. It is valid that a query
56+
/// fails to be forced, e.g. when the query key cannot be reconstructed from the
57+
/// dep-node or when the query kind outright does not support it.
5458
#[inline]
5559
#[instrument(skip(self, frame), level = "debug")]
5660
fn try_force_from_dep_node(self, dep_node: DepNode, frame: Option<&MarkFrame<'_>>) -> bool {
5761
let cb = self.dep_kind_info(dep_node.kind);
5862
if let Some(f) = cb.force_from_dep_node {
59-
if let Err(value) = panic::catch_unwind(panic::AssertUnwindSafe(|| {
60-
f(self, dep_node);
61-
})) {
62-
if !value.is::<rustc_errors::FatalErrorMarker>() {
63-
print_markframe_trace(self.dep_graph(), frame);
63+
match panic::catch_unwind(panic::AssertUnwindSafe(|| f(self, dep_node))) {
64+
Err(value) => {
65+
if !value.is::<rustc_errors::FatalErrorMarker>() {
66+
print_markframe_trace(self.dep_graph(), frame);
67+
}
68+
panic::resume_unwind(value)
6469
}
65-
panic::resume_unwind(value)
70+
Ok(query_has_been_forced) => query_has_been_forced,
6671
}
67-
true
6872
} else {
6973
false
7074
}

Diff for: tests/incremental/unrecoverable_query.rs

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// If it is impossible to find query arguments just from the hash
2+
// compiler should treat the node as red
3+
4+
// In this test prior to fixing compiler was having problems figuring out
5+
// drop impl for T inside of m
6+
7+
//@ revisions:cfail1 cfail2
8+
//@ compile-flags: --crate-type=lib
9+
//@ build-pass
10+
11+
pub trait P {
12+
type A;
13+
}
14+
15+
struct S;
16+
17+
impl P for S {
18+
type A = C;
19+
}
20+
21+
struct T<D: P>(D::A, Z<D>);
22+
23+
struct Z<D: P>(D::A, String);
24+
25+
impl<D: P> T<D> {
26+
pub fn i() -> Self {
27+
loop {}
28+
}
29+
}
30+
31+
enum C {
32+
#[cfg(cfail1)]
33+
Up(()),
34+
#[cfg(cfail2)]
35+
Lorry(()),
36+
}
37+
38+
pub fn m() {
39+
T::<S>::i();
40+
}

0 commit comments

Comments
 (0)