@@ -4,9 +4,9 @@ use rustc_middle::traits::solve::{
44 CanonicalInput , Certainty , Goal , IsNormalizesToHack , QueryInput , QueryResult ,
55} ;
66use rustc_middle:: ty:: { self , TyCtxt } ;
7- use rustc_session:: config:: SolverProofTreeCondition ;
7+ use rustc_session:: config:: DumpSolverProofTree ;
88
9- use super :: eval_ctxt:: DisableGlobalCache ;
9+ use super :: eval_ctxt:: UseGlobalCache ;
1010use super :: GenerateProofTree ;
1111
1212#[ derive( Eq , PartialEq , Debug , Hash , HashStable ) ]
@@ -146,33 +146,54 @@ impl<'tcx> From<WipGoalCandidate<'tcx>> for DebugSolver<'tcx> {
146146}
147147
148148pub struct ProofTreeBuilder < ' tcx > {
149- state : Option < Box < DebugSolver < ' tcx > > > ,
150- disable_global_cache : DisableGlobalCache ,
149+ state : Option < Box < BuilderData < ' tcx > > > ,
150+ }
151+
152+ struct BuilderData < ' tcx > {
153+ tree : DebugSolver < ' tcx > ,
154+ use_global_cache : UseGlobalCache ,
151155}
152156
153157impl < ' tcx > ProofTreeBuilder < ' tcx > {
154158 fn new (
155159 state : impl Into < DebugSolver < ' tcx > > ,
156- disable_global_cache : DisableGlobalCache ,
160+ use_global_cache : UseGlobalCache ,
157161 ) -> ProofTreeBuilder < ' tcx > {
158- ProofTreeBuilder { state : Some ( Box :: new ( state. into ( ) ) ) , disable_global_cache }
162+ ProofTreeBuilder {
163+ state : Some ( Box :: new ( BuilderData { tree : state. into ( ) , use_global_cache } ) ) ,
164+ }
165+ }
166+
167+ fn nested ( & self , state : impl Into < DebugSolver < ' tcx > > ) -> Self {
168+ match & self . state {
169+ Some ( prev_state) => Self {
170+ state : Some ( Box :: new ( BuilderData {
171+ tree : state. into ( ) ,
172+ use_global_cache : prev_state. use_global_cache ,
173+ } ) ) ,
174+ } ,
175+ None => Self { state : None } ,
176+ }
159177 }
160178
161179 fn as_mut ( & mut self ) -> Option < & mut DebugSolver < ' tcx > > {
162- self . state . as_mut ( ) . map ( |boxed| & mut * * boxed)
180+ self . state . as_mut ( ) . map ( |boxed| & mut boxed. tree )
163181 }
164182
165183 pub fn finalize ( self ) -> Option < inspect:: GoalEvaluation < ' tcx > > {
166- match * ( self . state ?) {
184+ match self . state ?. tree {
167185 DebugSolver :: GoalEvaluation ( wip_goal_evaluation) => {
168186 Some ( wip_goal_evaluation. finalize ( ) )
169187 }
170188 root => unreachable ! ( "unexpected proof tree builder root node: {:?}" , root) ,
171189 }
172190 }
173191
174- pub fn disable_global_cache ( & self ) -> DisableGlobalCache {
175- self . disable_global_cache
192+ pub fn use_global_cache ( & self ) -> bool {
193+ self . state
194+ . as_ref ( )
195+ . map ( |state| matches ! ( state. use_global_cache, UseGlobalCache :: Yes ) )
196+ . unwrap_or ( true )
176197 }
177198
178199 pub fn new_maybe_root (
@@ -185,17 +206,17 @@ impl<'tcx> ProofTreeBuilder<'tcx> {
185206 generate_proof_tree,
186207 ) {
187208 ( _, Some ( use_cache) , GenerateProofTree :: Yes ( _) ) => {
188- GenerateProofTree :: Yes ( DisableGlobalCache :: from_bool ( ! use_cache) )
209+ GenerateProofTree :: Yes ( UseGlobalCache :: from_bool ( use_cache) )
189210 }
190211
191- ( SolverProofTreeCondition :: Always , use_cache, GenerateProofTree :: No ) => {
212+ ( DumpSolverProofTree :: Always , use_cache, GenerateProofTree :: No ) => {
192213 let use_cache = use_cache. unwrap_or ( true ) ;
193- GenerateProofTree :: Yes ( DisableGlobalCache :: from_bool ( ! use_cache) )
214+ GenerateProofTree :: Yes ( UseGlobalCache :: from_bool ( use_cache) )
194215 }
195216
196217 ( _, None , GenerateProofTree :: Yes ( _) ) => generate_proof_tree,
197- ( SolverProofTreeCondition :: OnRequest , _, _) => generate_proof_tree,
198- ( SolverProofTreeCondition :: OnError , _, _) => generate_proof_tree,
218+ ( DumpSolverProofTree :: Never , _, _) => generate_proof_tree,
219+ ( DumpSolverProofTree :: OnError , _, _) => generate_proof_tree,
199220 } ;
200221
201222 match generate_proof_tree {
@@ -206,12 +227,12 @@ impl<'tcx> ProofTreeBuilder<'tcx> {
206227 }
207228 }
208229
209- pub fn new_root ( disable_global_cache : DisableGlobalCache ) -> ProofTreeBuilder < ' tcx > {
210- ProofTreeBuilder :: new ( DebugSolver :: Root , disable_global_cache )
230+ pub fn new_root ( use_global_cache : UseGlobalCache ) -> ProofTreeBuilder < ' tcx > {
231+ ProofTreeBuilder :: new ( DebugSolver :: Root , use_global_cache )
211232 }
212233
213234 pub fn new_noop ( ) -> ProofTreeBuilder < ' tcx > {
214- ProofTreeBuilder { state : None , disable_global_cache : DisableGlobalCache :: No }
235+ ProofTreeBuilder { state : None }
215236 }
216237
217238 pub fn is_noop ( & self ) -> bool {
@@ -224,24 +245,18 @@ impl<'tcx> ProofTreeBuilder<'tcx> {
224245 is_normalizes_to_hack : IsNormalizesToHack ,
225246 ) -> ProofTreeBuilder < ' tcx > {
226247 if self . state . is_none ( ) {
227- return ProofTreeBuilder {
228- state : None ,
229- disable_global_cache : self . disable_global_cache ,
230- } ;
248+ return ProofTreeBuilder { state : None } ;
231249 }
232250
233- ProofTreeBuilder :: new (
234- WipGoalEvaluation {
235- uncanonicalized_goal : goal,
236- canonicalized_goal : None ,
237- evaluation_steps : vec ! [ ] ,
238- is_normalizes_to_hack,
239- cache_hit : None ,
240- returned_goals : vec ! [ ] ,
241- result : None ,
242- } ,
243- self . disable_global_cache ,
244- )
251+ self . nested ( WipGoalEvaluation {
252+ uncanonicalized_goal : goal,
253+ canonicalized_goal : None ,
254+ evaluation_steps : vec ! [ ] ,
255+ is_normalizes_to_hack,
256+ cache_hit : None ,
257+ returned_goals : vec ! [ ] ,
258+ result : None ,
259+ } )
245260 }
246261
247262 pub fn canonicalized_goal ( & mut self , canonical_goal : CanonicalInput < ' tcx > ) {
@@ -279,7 +294,7 @@ impl<'tcx> ProofTreeBuilder<'tcx> {
279294 }
280295 pub fn goal_evaluation ( & mut self , goal_evaluation : ProofTreeBuilder < ' tcx > ) {
281296 if let Some ( this) = self . as_mut ( ) {
282- match ( this, * goal_evaluation. state . unwrap ( ) ) {
297+ match ( this, goal_evaluation. state . unwrap ( ) . tree ) {
283298 (
284299 DebugSolver :: AddedGoalsEvaluation ( WipAddedGoalsEvaluation {
285300 evaluations, ..
@@ -297,25 +312,19 @@ impl<'tcx> ProofTreeBuilder<'tcx> {
297312 instantiated_goal : QueryInput < ' tcx , ty:: Predicate < ' tcx > > ,
298313 ) -> ProofTreeBuilder < ' tcx > {
299314 if self . state . is_none ( ) {
300- return ProofTreeBuilder {
301- state : None ,
302- disable_global_cache : self . disable_global_cache ,
303- } ;
315+ return ProofTreeBuilder { state : None } ;
304316 }
305317
306- ProofTreeBuilder :: new (
307- WipGoalEvaluationStep {
308- instantiated_goal,
309- nested_goal_evaluations : vec ! [ ] ,
310- candidates : vec ! [ ] ,
311- result : None ,
312- } ,
313- self . disable_global_cache ,
314- )
318+ self . nested ( WipGoalEvaluationStep {
319+ instantiated_goal,
320+ nested_goal_evaluations : vec ! [ ] ,
321+ candidates : vec ! [ ] ,
322+ result : None ,
323+ } )
315324 }
316325 pub fn goal_evaluation_step ( & mut self , goal_eval_step : ProofTreeBuilder < ' tcx > ) {
317326 if let Some ( this) = self . as_mut ( ) {
318- match ( this, * goal_eval_step. state . unwrap ( ) ) {
327+ match ( this, goal_eval_step. state . unwrap ( ) . tree ) {
319328 ( DebugSolver :: GoalEvaluation ( goal_eval) , DebugSolver :: GoalEvaluationStep ( step) ) => {
320329 goal_eval. evaluation_steps . push ( step) ;
321330 }
@@ -326,17 +335,14 @@ impl<'tcx> ProofTreeBuilder<'tcx> {
326335
327336 pub fn new_goal_candidate ( & mut self ) -> ProofTreeBuilder < ' tcx > {
328337 if self . state . is_none ( ) {
329- return ProofTreeBuilder {
330- state : None ,
331-
332- disable_global_cache : self . disable_global_cache ,
333- } ;
338+ return ProofTreeBuilder { state : None } ;
334339 }
335340
336- ProofTreeBuilder :: new (
337- WipGoalCandidate { nested_goal_evaluations : vec ! [ ] , candidates : vec ! [ ] , kind : None } ,
338- self . disable_global_cache ,
339- )
341+ self . nested ( WipGoalCandidate {
342+ nested_goal_evaluations : vec ! [ ] ,
343+ candidates : vec ! [ ] ,
344+ kind : None ,
345+ } )
340346 }
341347
342348 pub fn candidate_kind ( & mut self , candidate_kind : CandidateKind < ' tcx > ) {
@@ -352,7 +358,7 @@ impl<'tcx> ProofTreeBuilder<'tcx> {
352358
353359 pub fn goal_candidate ( & mut self , candidate : ProofTreeBuilder < ' tcx > ) {
354360 if let Some ( this) = self . as_mut ( ) {
355- match ( this, * candidate. state . unwrap ( ) ) {
361+ match ( this, candidate. state . unwrap ( ) . tree ) {
356362 (
357363 DebugSolver :: GoalCandidate ( WipGoalCandidate { candidates, .. } )
358364 | DebugSolver :: GoalEvaluationStep ( WipGoalEvaluationStep { candidates, .. } ) ,
@@ -365,17 +371,10 @@ impl<'tcx> ProofTreeBuilder<'tcx> {
365371
366372 pub fn new_evaluate_added_goals ( & mut self ) -> ProofTreeBuilder < ' tcx > {
367373 if self . state . is_none ( ) {
368- return ProofTreeBuilder {
369- state : None ,
370-
371- disable_global_cache : self . disable_global_cache ,
372- } ;
374+ return ProofTreeBuilder { state : None } ;
373375 }
374376
375- ProofTreeBuilder :: new (
376- WipAddedGoalsEvaluation { evaluations : vec ! [ ] , result : None } ,
377- self . disable_global_cache ,
378- )
377+ self . nested ( WipAddedGoalsEvaluation { evaluations : vec ! [ ] , result : None } )
379378 }
380379
381380 pub fn evaluate_added_goals_loop_start ( & mut self ) {
@@ -402,7 +401,7 @@ impl<'tcx> ProofTreeBuilder<'tcx> {
402401
403402 pub fn added_goals_evaluation ( & mut self , goals_evaluation : ProofTreeBuilder < ' tcx > ) {
404403 if let Some ( this) = self . as_mut ( ) {
405- match ( this, * goals_evaluation. state . unwrap ( ) ) {
404+ match ( this, goals_evaluation. state . unwrap ( ) . tree ) {
406405 (
407406 DebugSolver :: GoalEvaluationStep ( WipGoalEvaluationStep {
408407 nested_goal_evaluations,
0 commit comments