Skip to content

Commit 284b614

Browse files
committed
reviews
1 parent 276d628 commit 284b614

File tree

7 files changed

+95
-102
lines changed

7 files changed

+95
-102
lines changed

compiler/rustc_session/src/config.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -746,11 +746,11 @@ pub enum TraitSolver {
746746
}
747747

748748
#[derive(Default, Debug, Copy, Clone, Hash, PartialEq, Eq)]
749-
pub enum SolverProofTreeCondition {
750-
#[default]
751-
OnRequest,
749+
pub enum DumpSolverProofTree {
752750
Always,
753751
OnError,
752+
#[default]
753+
Never,
754754
}
755755

756756
pub enum Input {

compiler/rustc_session/src/options.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,7 @@ mod desc {
418418
"a `,` separated combination of `bti`, `b-key`, `pac-ret`, or `leaf`";
419419
pub const parse_proc_macro_execution_strategy: &str =
420420
"one of supported execution strategies (`same-thread`, or `cross-thread`)";
421-
pub const parse_solver_proof_tree_condition: &str =
422-
"one of: `always`, `on-request`, `on-error`";
421+
pub const parse_dump_solver_proof_tree: &str = "one of: `always`, `on-request`, `on-error`";
423422
}
424423

425424
mod parse {
@@ -1241,14 +1240,14 @@ mod parse {
12411240
true
12421241
}
12431242

1244-
pub(crate) fn parse_solver_proof_tree_condition(
1245-
slot: &mut SolverProofTreeCondition,
1243+
pub(crate) fn parse_dump_solver_proof_tree(
1244+
slot: &mut DumpSolverProofTree,
12461245
v: Option<&str>,
12471246
) -> bool {
12481247
match v {
1249-
None | Some("always") => *slot = SolverProofTreeCondition::Always,
1250-
Some("on-request") => *slot = SolverProofTreeCondition::OnRequest,
1251-
Some("on-error") => *slot = SolverProofTreeCondition::OnError,
1248+
None | Some("always") => *slot = DumpSolverProofTree::Always,
1249+
Some("never") => *slot = DumpSolverProofTree::Never,
1250+
Some("on-error") => *slot = DumpSolverProofTree::OnError,
12521251
_ => return false,
12531252
};
12541253
true
@@ -1478,11 +1477,11 @@ options! {
14781477
"output statistics about monomorphization collection"),
14791478
dump_mono_stats_format: DumpMonoStatsFormat = (DumpMonoStatsFormat::Markdown, parse_dump_mono_stats, [UNTRACKED],
14801479
"the format to use for -Z dump-mono-stats (`markdown` (default) or `json`)"),
1481-
dump_solver_proof_tree: SolverProofTreeCondition = (SolverProofTreeCondition::OnRequest, parse_solver_proof_tree_condition, [UNTRACKED],
1480+
dump_solver_proof_tree: DumpSolverProofTree = (DumpSolverProofTree::Never, parse_dump_solver_proof_tree, [UNTRACKED],
14821481
"dump a proof tree for every goal evaluated by the new trait solver. If the flag is specified without any options after it
14831482
then it defaults to `always`. If the flag is not specified at all it defaults to `on-request`."),
14841483
dump_solver_proof_tree_use_cache: Option<bool> = (None, parse_opt_bool, [UNTRACKED],
1485-
"determines whether proof tree generation uses the global cache"),
1484+
"determines whether dumped proof trees use the global cache"),
14861485
dwarf_version: Option<u32> = (None, parse_opt_number, [TRACKED],
14871486
"version of DWARF debug information to emit (default: 2 or 4, depending on platform)"),
14881487
dylib_lto: bool = (false, parse_bool, [UNTRACKED],

compiler/rustc_trait_selection/src/solve/eval_ctxt.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rustc_middle::ty::{
1919
self, OpaqueTypeKey, Ty, TyCtxt, TypeFoldable, TypeSuperVisitable, TypeVisitable,
2020
TypeVisitableExt, TypeVisitor,
2121
};
22-
use rustc_session::config::SolverProofTreeCondition;
22+
use rustc_session::config::DumpSolverProofTree;
2323
use rustc_span::DUMMY_SP;
2424
use std::io::Write;
2525
use std::ops::ControlFlow;
@@ -115,20 +115,20 @@ impl NestedGoals<'_> {
115115

116116
#[derive(PartialEq, Eq, Debug, Hash, HashStable, Clone, Copy)]
117117
pub enum GenerateProofTree {
118-
Yes(DisableGlobalCache),
118+
Yes(UseGlobalCache),
119119
No,
120120
}
121121

122122
#[derive(PartialEq, Eq, Debug, Hash, HashStable, Clone, Copy)]
123-
pub enum DisableGlobalCache {
123+
pub enum UseGlobalCache {
124124
Yes,
125125
No,
126126
}
127-
impl DisableGlobalCache {
128-
pub fn from_bool(disable_cache: bool) -> Self {
129-
match disable_cache {
130-
true => DisableGlobalCache::Yes,
131-
false => DisableGlobalCache::No,
127+
impl UseGlobalCache {
128+
pub fn from_bool(use_cache: bool) -> Self {
129+
match use_cache {
130+
true => UseGlobalCache::Yes,
131+
false => UseGlobalCache::No,
132132
}
133133
}
134134
}
@@ -198,7 +198,7 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
198198
let result = f(&mut ecx);
199199

200200
let tree = ecx.inspect.finalize();
201-
if let (Some(tree), SolverProofTreeCondition::Always) =
201+
if let (Some(tree), DumpSolverProofTree::Always) =
202202
(&tree, infcx.tcx.sess.opts.unstable_opts.dump_solver_proof_tree)
203203
{
204204
let mut lock = std::io::stdout().lock();

compiler/rustc_trait_selection/src/solve/inspect.rs

Lines changed: 68 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use rustc_middle::traits::solve::{
44
CanonicalInput, Certainty, Goal, IsNormalizesToHack, QueryInput, QueryResult,
55
};
66
use 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;
1010
use super::GenerateProofTree;
1111

1212
#[derive(Eq, PartialEq, Debug, Hash, HashStable)]
@@ -146,33 +146,54 @@ impl<'tcx> From<WipGoalCandidate<'tcx>> for DebugSolver<'tcx> {
146146
}
147147

148148
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,
151155
}
152156

153157
impl<'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,

compiler/rustc_trait_selection/src/solve/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ mod trait_goals;
3434
mod weak_types;
3535

3636
pub use eval_ctxt::{
37-
DisableGlobalCache, EvalCtxt, GenerateProofTree, InferCtxtEvalExt, InferCtxtSelectExt,
37+
EvalCtxt, GenerateProofTree, InferCtxtEvalExt, InferCtxtSelectExt, UseGlobalCache,
3838
};
3939
pub use fulfill::FulfillmentCtxt;
4040
pub(crate) use normalize::deeply_normalize;

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use rustc_middle::traits::solve::{CanonicalInput, Certainty, MaybeCause, QueryRe
1313
use rustc_middle::ty::TyCtxt;
1414
use std::{collections::hash_map::Entry, mem};
1515

16-
use super::eval_ctxt::DisableGlobalCache;
1716
use super::inspect::ProofTreeBuilder;
1817
use super::SolverMode;
1918

@@ -214,9 +213,7 @@ impl<'tcx> SearchGraph<'tcx> {
214213
inspect: &mut ProofTreeBuilder<'tcx>,
215214
mut loop_body: impl FnMut(&mut Self, &mut ProofTreeBuilder<'tcx>) -> QueryResult<'tcx>,
216215
) -> QueryResult<'tcx> {
217-
if self.should_use_global_cache()
218-
&& inspect.disable_global_cache() == DisableGlobalCache::No
219-
{
216+
if self.should_use_global_cache() && inspect.use_global_cache() {
220217
if let Some(result) = tcx.new_solver_evaluation_cache.get(&canonical_input, tcx) {
221218
debug!(?canonical_input, ?result, "cache hit");
222219
inspect.cache_hit(CacheHit::Global);

0 commit comments

Comments
 (0)