Skip to content

Commit 0b29b71

Browse files
committed
cleanup + review
1 parent 7c5a99b commit 0b29b71

File tree

7 files changed

+31
-35
lines changed

7 files changed

+31
-35
lines changed

compiler/rustc_middle/src/traits/solve.rs

-6
Original file line numberDiff line numberDiff line change
@@ -275,12 +275,6 @@ pub enum GoalSource {
275275
ImplWhereBound,
276276
}
277277

278-
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, HashStable)]
279-
pub enum IsNormalizesToHack {
280-
Yes,
281-
No,
282-
}
283-
284278
/// Possible ways the given goal can be proven.
285279
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
286280
pub enum CandidateSource {

compiler/rustc_middle/src/traits/solve/inspect.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
//! [canonicalized]: https://rustc-dev-guide.rust-lang.org/solve/canonicalization.html
2020
2121
use super::{
22-
CandidateSource, Canonical, CanonicalInput, Certainty, Goal, GoalSource, IsNormalizesToHack,
23-
NoSolution, QueryInput, QueryResult,
22+
CandidateSource, Canonical, CanonicalInput, Certainty, Goal, GoalSource, NoSolution,
23+
QueryInput, QueryResult,
2424
};
2525
use crate::{infer::canonical::CanonicalVarValues, ty};
2626
use format::ProofTreeFormatter;
@@ -50,7 +50,7 @@ pub type CanonicalState<'tcx, T> = Canonical<'tcx, State<'tcx, T>>;
5050
#[derive(Eq, PartialEq)]
5151
pub enum GoalEvaluationKind<'tcx> {
5252
Root { orig_values: Vec<ty::GenericArg<'tcx>> },
53-
Nested { is_normalizes_to_hack: IsNormalizesToHack },
53+
Nested,
5454
}
5555

5656
#[derive(Eq, PartialEq)]

compiler/rustc_middle/src/traits/solve/inspect/format.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,7 @@ impl<'a, 'b> ProofTreeFormatter<'a, 'b> {
5555
pub(super) fn format_goal_evaluation(&mut self, eval: &GoalEvaluation<'_>) -> std::fmt::Result {
5656
let goal_text = match eval.kind {
5757
GoalEvaluationKind::Root { orig_values: _ } => "ROOT GOAL",
58-
GoalEvaluationKind::Nested { is_normalizes_to_hack } => match is_normalizes_to_hack {
59-
IsNormalizesToHack::No => "GOAL",
60-
IsNormalizesToHack::Yes => "NORMALIZES-TO HACK GOAL",
61-
},
58+
GoalEvaluationKind::Nested => "GOAL",
6259
};
6360
write!(self.f, "{}: {:?}", goal_text, eval.uncanonicalized_goal)?;
6461
self.nested(|this| this.format_canonical_goal_evaluation(&eval.evaluation))

compiler/rustc_trait_selection/src/solve/eval_ctxt/canonical.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use rustc_middle::traits::ObligationCause;
3030
use rustc_middle::ty::{self, BoundVar, GenericArgKind, Ty, TyCtxt, TypeFoldable};
3131
use rustc_next_trait_solver::canonicalizer::{CanonicalizeMode, Canonicalizer};
3232
use rustc_span::DUMMY_SP;
33+
use std::assert_matches::assert_matches;
3334
use std::iter;
3435
use std::ops::Deref;
3536

@@ -104,7 +105,12 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
104105
// by `try_evaluate_added_goals()`.
105106
let (certainty, normalization_nested_goals) = if self.is_normalizes_to_goal {
106107
let NestedGoals { normalizes_to_goals, goals } = std::mem::take(&mut self.nested_goals);
107-
assert!(normalizes_to_goals.is_empty());
108+
if cfg!(debug_assertions) {
109+
assert!(normalizes_to_goals.is_empty());
110+
if goals.is_empty() {
111+
assert_matches!(goals_certainty, Certainty::Yes);
112+
}
113+
}
108114
(certainty, NestedNormalizationGoals(goals))
109115
} else {
110116
let certainty = certainty.unify_with(goals_certainty);

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

+14-10
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ use rustc_middle::infer::canonical::CanonicalVarInfos;
1313
use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind};
1414
use rustc_middle::traits::solve::inspect;
1515
use rustc_middle::traits::solve::{
16-
CanonicalInput, CanonicalResponse, Certainty, IsNormalizesToHack, PredefinedOpaques,
17-
PredefinedOpaquesData, QueryResult,
16+
CanonicalInput, CanonicalResponse, Certainty, PredefinedOpaques, PredefinedOpaquesData,
17+
QueryResult,
1818
};
1919
use rustc_middle::traits::specialization_graph;
2020
use rustc_middle::ty::{
@@ -337,8 +337,15 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
337337
Ok((has_changed, certainty))
338338
}
339339

340-
/// FIXME(-Znext-solver=coinduction): `_source` is currently unused but will
341-
/// be necessary once we implement the new coinduction approach.
340+
/// Recursively evaluates `goal`, returning the nested goals in case
341+
/// the nested goal is a `NormalizesTo` goal.
342+
///
343+
/// As all other goal kinds do not return any nested goals and
344+
/// `NormalizesTo` is only used by `AliasRelate`, all other callsites
345+
/// should use [`EvalCtxt::evaluate_goal`] which discards that empty
346+
/// storage.
347+
// FIXME(-Znext-solver=coinduction): `_source` is currently unused but will
348+
// be necessary once we implement the new coinduction approach.
342349
fn evaluate_goal_raw(
343350
&mut self,
344351
goal_evaluation_kind: GoalEvaluationKind,
@@ -522,7 +529,7 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
522529
);
523530

524531
let (NestedNormalizationGoals(nested_goals), _, certainty) = self.evaluate_goal_raw(
525-
GoalEvaluationKind::Nested { is_normalizes_to_hack: IsNormalizesToHack::Yes },
532+
GoalEvaluationKind::Nested,
526533
GoalSource::Misc,
527534
unconstrained_goal,
528535
)?;
@@ -557,11 +564,8 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
557564
}
558565

559566
for (source, goal) in goals.goals {
560-
let (has_changed, certainty) = self.evaluate_goal(
561-
GoalEvaluationKind::Nested { is_normalizes_to_hack: IsNormalizesToHack::No },
562-
source,
563-
goal,
564-
)?;
567+
let (has_changed, certainty) =
568+
self.evaluate_goal(GoalEvaluationKind::Nested, source, goal)?;
565569
if has_changed {
566570
unchanged_certainty = None;
567571
}

compiler/rustc_trait_selection/src/solve/inspect/build.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::mem;
77

88
use rustc_middle::traits::query::NoSolution;
99
use rustc_middle::traits::solve::{
10-
CanonicalInput, Certainty, Goal, GoalSource, IsNormalizesToHack, QueryInput, QueryResult,
10+
CanonicalInput, Certainty, Goal, GoalSource, QueryInput, QueryResult,
1111
};
1212
use rustc_middle::ty::{self, TyCtxt};
1313
use rustc_session::config::DumpSolverProofTree;
@@ -97,9 +97,7 @@ impl<'tcx> WipGoalEvaluation<'tcx> {
9797
WipGoalEvaluationKind::Root { orig_values } => {
9898
inspect::GoalEvaluationKind::Root { orig_values }
9999
}
100-
WipGoalEvaluationKind::Nested { is_normalizes_to_hack } => {
101-
inspect::GoalEvaluationKind::Nested { is_normalizes_to_hack }
102-
}
100+
WipGoalEvaluationKind::Nested => inspect::GoalEvaluationKind::Nested,
103101
},
104102
evaluation: self.evaluation.unwrap().finalize(),
105103
}
@@ -109,7 +107,7 @@ impl<'tcx> WipGoalEvaluation<'tcx> {
109107
#[derive(Eq, PartialEq, Debug)]
110108
pub(in crate::solve) enum WipGoalEvaluationKind<'tcx> {
111109
Root { orig_values: Vec<ty::GenericArg<'tcx>> },
112-
Nested { is_normalizes_to_hack: IsNormalizesToHack },
110+
Nested,
113111
}
114112

115113
#[derive(Eq, PartialEq)]
@@ -305,9 +303,7 @@ impl<'tcx> ProofTreeBuilder<'tcx> {
305303
solve::GoalEvaluationKind::Root => {
306304
WipGoalEvaluationKind::Root { orig_values: orig_values.to_vec() }
307305
}
308-
solve::GoalEvaluationKind::Nested { is_normalizes_to_hack } => {
309-
WipGoalEvaluationKind::Nested { is_normalizes_to_hack }
310-
}
306+
solve::GoalEvaluationKind::Nested => WipGoalEvaluationKind::Nested,
311307
},
312308
evaluation: None,
313309
})

compiler/rustc_trait_selection/src/solve/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ use rustc_infer::infer::canonical::{Canonical, CanonicalVarValues};
1818
use rustc_infer::traits::query::NoSolution;
1919
use rustc_middle::infer::canonical::CanonicalVarInfos;
2020
use rustc_middle::traits::solve::{
21-
CanonicalResponse, Certainty, ExternalConstraintsData, Goal, GoalSource, IsNormalizesToHack,
22-
QueryResult, Response,
21+
CanonicalResponse, Certainty, ExternalConstraintsData, Goal, GoalSource, QueryResult, Response,
2322
};
2423
use rustc_middle::ty::{self, AliasRelationDirection, Ty, TyCtxt, UniverseIndex};
2524
use rustc_middle::ty::{
@@ -69,7 +68,7 @@ enum SolverMode {
6968
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
7069
enum GoalEvaluationKind {
7170
Root,
72-
Nested { is_normalizes_to_hack: IsNormalizesToHack },
71+
Nested,
7372
}
7473

7574
#[extension(trait CanonicalResponseExt)]

0 commit comments

Comments
 (0)