@@ -4,9 +4,9 @@ use rustc_middle::traits::solve::{
4
4
CanonicalInput , Certainty , Goal , IsNormalizesToHack , QueryInput , QueryResult ,
5
5
} ;
6
6
use rustc_middle:: ty:: { self , TyCtxt } ;
7
- use rustc_session:: config:: SolverProofTreeCondition ;
7
+ use rustc_session:: config:: DumpSolverProofTree ;
8
8
9
- use super :: eval_ctxt:: DisableGlobalCache ;
9
+ use super :: eval_ctxt:: UseGlobalCache ;
10
10
use super :: GenerateProofTree ;
11
11
12
12
#[ derive( Eq , PartialEq , Debug , Hash , HashStable ) ]
@@ -146,33 +146,54 @@ impl<'tcx> From<WipGoalCandidate<'tcx>> for DebugSolver<'tcx> {
146
146
}
147
147
148
148
pub 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 ,
151
155
}
152
156
153
157
impl < ' tcx > ProofTreeBuilder < ' tcx > {
154
158
fn new (
155
159
state : impl Into < DebugSolver < ' tcx > > ,
156
- disable_global_cache : DisableGlobalCache ,
160
+ use_global_cache : UseGlobalCache ,
157
161
) -> 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
+ }
159
177
}
160
178
161
179
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 )
163
181
}
164
182
165
183
pub fn finalize ( self ) -> Option < inspect:: GoalEvaluation < ' tcx > > {
166
- match * ( self . state ?) {
184
+ match self . state ?. tree {
167
185
DebugSolver :: GoalEvaluation ( wip_goal_evaluation) => {
168
186
Some ( wip_goal_evaluation. finalize ( ) )
169
187
}
170
188
root => unreachable ! ( "unexpected proof tree builder root node: {:?}" , root) ,
171
189
}
172
190
}
173
191
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 )
176
197
}
177
198
178
199
pub fn new_maybe_root (
@@ -185,17 +206,17 @@ impl<'tcx> ProofTreeBuilder<'tcx> {
185
206
generate_proof_tree,
186
207
) {
187
208
( _, Some ( use_cache) , GenerateProofTree :: Yes ( _) ) => {
188
- GenerateProofTree :: Yes ( DisableGlobalCache :: from_bool ( ! use_cache) )
209
+ GenerateProofTree :: Yes ( UseGlobalCache :: from_bool ( use_cache) )
189
210
}
190
211
191
- ( SolverProofTreeCondition :: Always , use_cache, GenerateProofTree :: No ) => {
212
+ ( DumpSolverProofTree :: Always , use_cache, GenerateProofTree :: No ) => {
192
213
let use_cache = use_cache. unwrap_or ( true ) ;
193
- GenerateProofTree :: Yes ( DisableGlobalCache :: from_bool ( ! use_cache) )
214
+ GenerateProofTree :: Yes ( UseGlobalCache :: from_bool ( use_cache) )
194
215
}
195
216
196
217
( _, 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,
199
220
} ;
200
221
201
222
match generate_proof_tree {
@@ -206,12 +227,12 @@ impl<'tcx> ProofTreeBuilder<'tcx> {
206
227
}
207
228
}
208
229
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 )
211
232
}
212
233
213
234
pub fn new_noop ( ) -> ProofTreeBuilder < ' tcx > {
214
- ProofTreeBuilder { state : None , disable_global_cache : DisableGlobalCache :: No }
235
+ ProofTreeBuilder { state : None }
215
236
}
216
237
217
238
pub fn is_noop ( & self ) -> bool {
@@ -224,24 +245,18 @@ impl<'tcx> ProofTreeBuilder<'tcx> {
224
245
is_normalizes_to_hack : IsNormalizesToHack ,
225
246
) -> ProofTreeBuilder < ' tcx > {
226
247
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 } ;
231
249
}
232
250
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
+ } )
245
260
}
246
261
247
262
pub fn canonicalized_goal ( & mut self , canonical_goal : CanonicalInput < ' tcx > ) {
@@ -279,7 +294,7 @@ impl<'tcx> ProofTreeBuilder<'tcx> {
279
294
}
280
295
pub fn goal_evaluation ( & mut self , goal_evaluation : ProofTreeBuilder < ' tcx > ) {
281
296
if let Some ( this) = self . as_mut ( ) {
282
- match ( this, * goal_evaluation. state . unwrap ( ) ) {
297
+ match ( this, goal_evaluation. state . unwrap ( ) . tree ) {
283
298
(
284
299
DebugSolver :: AddedGoalsEvaluation ( WipAddedGoalsEvaluation {
285
300
evaluations, ..
@@ -297,25 +312,19 @@ impl<'tcx> ProofTreeBuilder<'tcx> {
297
312
instantiated_goal : QueryInput < ' tcx , ty:: Predicate < ' tcx > > ,
298
313
) -> ProofTreeBuilder < ' tcx > {
299
314
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 } ;
304
316
}
305
317
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
+ } )
315
324
}
316
325
pub fn goal_evaluation_step ( & mut self , goal_eval_step : ProofTreeBuilder < ' tcx > ) {
317
326
if let Some ( this) = self . as_mut ( ) {
318
- match ( this, * goal_eval_step. state . unwrap ( ) ) {
327
+ match ( this, goal_eval_step. state . unwrap ( ) . tree ) {
319
328
( DebugSolver :: GoalEvaluation ( goal_eval) , DebugSolver :: GoalEvaluationStep ( step) ) => {
320
329
goal_eval. evaluation_steps . push ( step) ;
321
330
}
@@ -326,17 +335,14 @@ impl<'tcx> ProofTreeBuilder<'tcx> {
326
335
327
336
pub fn new_goal_candidate ( & mut self ) -> ProofTreeBuilder < ' tcx > {
328
337
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 } ;
334
339
}
335
340
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
+ } )
340
346
}
341
347
342
348
pub fn candidate_kind ( & mut self , candidate_kind : CandidateKind < ' tcx > ) {
@@ -352,7 +358,7 @@ impl<'tcx> ProofTreeBuilder<'tcx> {
352
358
353
359
pub fn goal_candidate ( & mut self , candidate : ProofTreeBuilder < ' tcx > ) {
354
360
if let Some ( this) = self . as_mut ( ) {
355
- match ( this, * candidate. state . unwrap ( ) ) {
361
+ match ( this, candidate. state . unwrap ( ) . tree ) {
356
362
(
357
363
DebugSolver :: GoalCandidate ( WipGoalCandidate { candidates, .. } )
358
364
| DebugSolver :: GoalEvaluationStep ( WipGoalEvaluationStep { candidates, .. } ) ,
@@ -365,17 +371,10 @@ impl<'tcx> ProofTreeBuilder<'tcx> {
365
371
366
372
pub fn new_evaluate_added_goals ( & mut self ) -> ProofTreeBuilder < ' tcx > {
367
373
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 } ;
373
375
}
374
376
375
- ProofTreeBuilder :: new (
376
- WipAddedGoalsEvaluation { evaluations : vec ! [ ] , result : None } ,
377
- self . disable_global_cache ,
378
- )
377
+ self . nested ( WipAddedGoalsEvaluation { evaluations : vec ! [ ] , result : None } )
379
378
}
380
379
381
380
pub fn evaluate_added_goals_loop_start ( & mut self ) {
@@ -402,7 +401,7 @@ impl<'tcx> ProofTreeBuilder<'tcx> {
402
401
403
402
pub fn added_goals_evaluation ( & mut self , goals_evaluation : ProofTreeBuilder < ' tcx > ) {
404
403
if let Some ( this) = self . as_mut ( ) {
405
- match ( this, * goals_evaluation. state . unwrap ( ) ) {
404
+ match ( this, goals_evaluation. state . unwrap ( ) . tree ) {
406
405
(
407
406
DebugSolver :: GoalEvaluationStep ( WipGoalEvaluationStep {
408
407
nested_goal_evaluations,
0 commit comments