Skip to content

Commit 8f2d75d

Browse files
authored
Rollup merge of rust-lang#110986 - cjgillot:delay-feed-bug, r=WaffleLapkin
Delay a bug when overwriting fed value. Fixes rust-lang#110887
2 parents 9052ca9 + 3bb5d1d commit 8f2d75d

File tree

3 files changed

+46
-15
lines changed

3 files changed

+46
-15
lines changed

compiler/rustc_middle/src/query/plumbing.rs

+13-5
Original file line numberDiff line numberDiff line change
@@ -533,12 +533,20 @@ macro_rules! define_feedable {
533533
let (value_hash, old_hash): (Fingerprint, Fingerprint) = tcx.with_stable_hashing_context(|mut hcx|
534534
(hasher(&mut hcx, &value), hasher(&mut hcx, &old))
535535
);
536-
assert_eq!(
537-
old_hash, value_hash,
538-
"Trying to feed an already recorded value for query {} key={key:?}:\nold value: {old:?}\nnew value: {value:?}",
539-
stringify!($name),
540-
)
536+
if old_hash != value_hash {
537+
// We have an inconsistency. This can happen if one of the two
538+
// results is tainted by errors. In this case, delay a bug to
539+
// ensure compilation is doomed, and keep the `old` value.
540+
tcx.sess.delay_span_bug(DUMMY_SP, format!(
541+
"Trying to feed an already recorded value for query {} key={key:?}:\n\
542+
old value: {old:?}\nnew value: {value:?}",
543+
stringify!($name),
544+
));
545+
}
541546
} else {
547+
// The query is `no_hash`, so we have no way to perform a sanity check.
548+
// If feeding the same value multiple times needs to be supported,
549+
// the query should not be marked `no_hash`.
542550
bug!(
543551
"Trying to feed an already recorded value for query {} key={key:?}:\nold value: {old:?}\nnew value: {value:?}",
544552
stringify!($name),

compiler/rustc_query_system/src/query/plumbing.rs

+16-10
Original file line numberDiff line numberDiff line change
@@ -433,16 +433,22 @@ where
433433
(hasher(&mut hcx, &cached_result), hasher(&mut hcx, &result))
434434
});
435435
let formatter = query.format_value();
436-
debug_assert_eq!(
437-
old_hash,
438-
new_hash,
439-
"Computed query value for {:?}({:?}) is inconsistent with fed value,\n\
440-
computed={:#?}\nfed={:#?}",
441-
query.dep_kind(),
442-
key,
443-
formatter(&result),
444-
formatter(&cached_result),
445-
);
436+
if old_hash != new_hash {
437+
// We have an inconsistency. This can happen if one of the two
438+
// results is tainted by errors. In this case, delay a bug to
439+
// ensure compilation is doomed.
440+
qcx.dep_context().sess().delay_span_bug(
441+
DUMMY_SP,
442+
format!(
443+
"Computed query value for {:?}({:?}) is inconsistent with fed value,\n\
444+
computed={:#?}\nfed={:#?}",
445+
query.dep_kind(),
446+
key,
447+
formatter(&result),
448+
formatter(&cached_result),
449+
),
450+
);
451+
}
446452
}
447453
}
448454
job_owner.complete(cache, result, dep_node_index);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Verify that we do not ICE when we try to overwrite an anon-const's type because of a trait
2+
// cycle.
3+
//
4+
// compile-flags: -Zincremental-ignore-spans
5+
// revisions: cpass cfail
6+
// error-pattern: cycle detected when computing type of `Bar::N`
7+
8+
#![feature(trait_alias)]
9+
#![crate_type="lib"]
10+
11+
#[cfg(cpass)]
12+
trait Bar<const N: usize> {}
13+
14+
#[cfg(cfail)]
15+
trait Bar<const N: dyn BB> {}
16+
17+
trait BB = Bar<{ 2 + 1 }>;

0 commit comments

Comments
 (0)