@@ -7,7 +7,7 @@ use cache::ProvisionalCache;
77use overflow:: OverflowData ;
88use rustc_index:: vec:: IndexVec ;
99use rustc_middle:: ty:: TyCtxt ;
10- use std:: collections:: hash_map:: Entry ;
10+ use std:: { collections:: hash_map:: Entry , mem } ;
1111
1212rustc_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