Skip to content

Commit a516460

Browse files
committed
correctly update goals in the cache
1 parent 6eb9f2d commit a516460

File tree

1 file changed

+8
-5
lines changed
  • compiler/rustc_trait_selection/src/solve/search_graph

1 file changed

+8
-5
lines changed

compiler/rustc_trait_selection/src/solve/search_graph/mod.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use cache::ProvisionalCache;
77
use overflow::OverflowData;
88
use rustc_index::vec::IndexVec;
99
use rustc_middle::ty::TyCtxt;
10-
use std::collections::hash_map::Entry;
10+
use std::{collections::hash_map::Entry, mem};
1111

1212
rustc_index::newtype_index! {
1313
pub struct StackDepth {}
@@ -134,12 +134,15 @@ impl<'tcx> SearchGraph<'tcx> {
134134
let provisional_entry_index = *cache.lookup_table.get(&goal).unwrap();
135135
let provisional_entry = &mut cache.entries[provisional_entry_index];
136136
let depth = provisional_entry.depth;
137+
// We eagerly update the response in the cache here. If we have to reevaluate
138+
// this goal we use the new response when hitting a cycle, and we definitely
139+
// want to access the final response whenever we look at the cache.
140+
let prev_response = mem::replace(&mut provisional_entry.response, response);
141+
137142
// Was the current goal the root of a cycle and was the provisional response
138143
// different from the final one.
139-
if has_been_used && provisional_entry.response != response {
140-
// If so, update the provisional reponse for this goal...
141-
provisional_entry.response = response;
142-
// ...remove all entries whose result depends on this goal
144+
if has_been_used && prev_response != response {
145+
// If so, remove all entries whose result depends on this goal
143146
// from the provisional cache...
144147
//
145148
// That's not completely correct, as a nested goal can also

0 commit comments

Comments
 (0)