Skip to content

Commit 380a7fa

Browse files
Rollup merge of #163130 - Gmes23:fix-provisional-cache-invalidation, r=oli-obk
Fix provisional cache invalidation in the old trait solver (ran into probing ICE issue) Hi I found this issue while trying to fix incremental compilation ICE issue in a ledger system i was working at owrk(luckily it panic early) I noticed that ! in ProvisionalEvaluationCache::on_failure at compiler/rustc_trait_selection/src/traits/select/mod.rs:3094 was not doing its intended behavior. The documentation says that on_failure should remove provisional cache entries created at or after the failing node, meaning entries where from_dfn >= dfn. The current condition is !eval.from_dfn >= dfn. Since from_dfn is usize and ! binds more tightly than >=; this applies a bitwise NOT to from_dfn before comparing it with dfn. For the small DFN values we normally encountered here, that produces a huge number causing the condition to always be true on_failure then clears the entire provisional cache instead of preserving entries created before the failing node. This PR removes the ! so fn works as is intended behavior makign the comments true, I also compared local compilation times using the old trait solver and emitting metadata only. The median results were: ``` Test case Before With ! removed Regression test for #150907 32.56 ms 32.44 ms Synthetic cyclic types with an error 32.15 ms 32.18 ms Synthetic cyclic types without errors 27.15 ms 26.92 ms ``` I tested this on all avilable toolchains, all seem to produce similar results. This DOES NOT fix the ICE issue it still happens this is just a correction on behavior and that boost performance and then i can fix the ICE issue, The ICE issue I fix by removing the tainted_by_errors() lines 1098-1105 else condition (introduced by pr #155355 from what i believe was fixing a performance issue so timing is important)that allows caching results that depend on the evaluation stack This fix plus the removal of the ! makes the existing regression test much slower yet faster than the original issue which was 30s (i believe) (here is a small sample data i took) ``` Change Time Baseline 0.035 s Remove the tainted_by_errors() branch 30.59 s Remove that branch and remove the ! 2.73 s ``` While its not beating the current baseline it does correctly not throw a panic(which has cause issues in our ledger), I would like to fix the ICE issue, but that needs more work if the intention is to equal the .03 time and i heard this trait solver is being deprecrated soon? For now I am keeping this PR focused on the provisional cache invalidation and would like to follow up on the ICE in a separate PR
2 parents 16bd816 + e0b4fd0 commit 380a7fa

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

  • compiler/rustc_trait_selection/src/traits/select

‎compiler/rustc_trait_selection/src/traits/select/mod.rs‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3082,16 +3082,16 @@ impl<'tcx> ProvisionalEvaluationCache<'tcx> {
30823082

30833083
/// Invoked when the node with dfn `dfn` does not get a successful
30843084
/// result. This will clear out any provisional cache entries
3085-
/// that were added since `dfn` was created. This is because the
3086-
/// provisional entries are things which must assume that the
3087-
/// things on the stack at the time of their creation succeeded --
3088-
/// since the failing node is presently at the top of the stack,
3089-
/// these provisional entries must either depend on it or some
3090-
/// ancestor of it.
3085+
/// originating from nodes visited before this node (`from_dfn < dfn`).
3086+
/// This is because the provisional entries are things which must
3087+
/// assume that the things on the stack at the time of their creation
3088+
/// succeeded -- since the failing node is presently at the top of
3089+
/// the stack, these provisional entries must either depend on it or
3090+
/// some ancestor of it.
30913091
fn on_failure(&self, dfn: usize) {
30923092
debug!(?dfn, "on_failure");
30933093
self.map.borrow_mut().retain(|key, eval| {
3094-
if !eval.from_dfn >= dfn {
3094+
if eval.from_dfn < dfn {
30953095
debug!("on_failure: removing {:?}", key);
30963096
false
30973097
} else {

0 commit comments

Comments
 (0)