Skip to content

Commit cfbd86e

Browse files
committed
Very coarse draft
1 parent 82bbd45 commit cfbd86e

File tree

12 files changed

+258
-139
lines changed

12 files changed

+258
-139
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/inspect_obligations.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
3939
self.type_matches_expected_vid(expected_vid, data.self_ty())
4040
}
4141
ty::PredicateKind::Clause(ty::ClauseKind::Projection(data)) => {
42+
if !matches!(
43+
data.projection_term.kind(self.tcx),
44+
ty::AliasTermKind::ProjectionTy
45+
| ty::AliasTermKind::ProjectionConst
46+
| ty::AliasTermKind::InherentTy
47+
| ty::AliasTermKind::InherentConst
48+
) {
49+
return false;
50+
}
51+
4252
self.type_matches_expected_vid(expected_vid, data.projection_term.self_ty())
4353
}
4454
ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(..))

compiler/rustc_next_trait_solver/src/canonical/mod.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,19 @@ pub(super) fn instantiate_and_apply_query_response<D, I>(
9797
original_values: &[I::GenericArg],
9898
response: CanonicalResponse<I>,
9999
span: I::Span,
100+
prev_universe: ty::UniverseIndex,
100101
) -> (NestedNormalizationGoals<I>, Certainty)
101102
where
102103
D: SolverDelegate<Interner = I>,
103104
I: Interner,
104105
{
105-
let instantiation =
106-
compute_query_response_instantiation_values(delegate, &original_values, &response, span);
106+
let instantiation = compute_query_response_instantiation_values(
107+
delegate,
108+
&original_values,
109+
&response,
110+
span,
111+
prev_universe,
112+
);
107113

108114
let Response { var_values, external_constraints, certainty } =
109115
delegate.instantiate_canonical(response, instantiation);
@@ -127,6 +133,7 @@ fn compute_query_response_instantiation_values<D, I, T>(
127133
original_values: &[I::GenericArg],
128134
response: &Canonical<I, T>,
129135
span: I::Span,
136+
prev_universe: ty::UniverseIndex,
130137
) -> CanonicalVarValues<I>
131138
where
132139
D: SolverDelegate<Interner = I>,
@@ -136,7 +143,6 @@ where
136143
// FIXME: Longterm canonical queries should deal with all placeholders
137144
// created inside of the query directly instead of returning them to the
138145
// caller.
139-
let prev_universe = delegate.universe();
140146
let universes_created_in_query = response.max_universe.index();
141147
for _ in 0..universes_created_in_query {
142148
delegate.create_next_universe();
@@ -328,8 +334,13 @@ where
328334
.map(|&arg| delegate.fresh_var_for_kind_with_span(arg, span)),
329335
);
330336

331-
let instantiation =
332-
compute_query_response_instantiation_values(delegate, orig_values, &state, span);
337+
let instantiation = compute_query_response_instantiation_values(
338+
delegate,
339+
orig_values,
340+
&state,
341+
span,
342+
delegate.universe(),
343+
);
333344

334345
let inspect::State { var_values, data } = delegate.instantiate_canonical(state, instantiation);
335346

compiler/rustc_next_trait_solver/src/solve/alias_relate.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,13 @@ where
5252
let term = self.next_term_infer_of_kind(lhs);
5353
self.add_goal(
5454
GoalSource::TypeRelating,
55-
goal.with(cx, ty::NormalizesTo { alias, term }),
55+
goal.with(
56+
cx,
57+
ty::ClauseKind::Projection(ty::ProjectionPredicate {
58+
projection_term: alias,
59+
term,
60+
}),
61+
),
5662
);
5763
term
5864
} else {
@@ -64,7 +70,13 @@ where
6470
let term = self.next_term_infer_of_kind(rhs);
6571
self.add_goal(
6672
GoalSource::TypeRelating,
67-
goal.with(cx, ty::NormalizesTo { alias, term }),
73+
goal.with(
74+
cx,
75+
ty::ClauseKind::Projection(ty::ProjectionPredicate {
76+
projection_term: alias,
77+
term,
78+
}),
79+
),
6880
);
6981
term
7082
} else {

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

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ mod probe;
4040
/// This has effects on cycle handling handling and on how we compute
4141
/// query responses, see the variant descriptions for more info.
4242
#[derive(Debug, Copy, Clone)]
43-
enum CurrentGoalKind {
43+
pub(super) enum CurrentGoalKind {
4444
Misc,
4545
/// We're proving an trait goal for a coinductive trait, either an auto trait or `Sized`.
4646
///
@@ -93,15 +93,15 @@ where
9393
/// If some `InferCtxt` method is missing, please first think defensively about
9494
/// the method's compatibility with this solver, or if an existing one does
9595
/// the job already.
96-
delegate: &'a D,
96+
pub(super) delegate: &'a D,
9797

9898
/// The variable info for the `var_values`, only used to make an ambiguous response
9999
/// with no constraints.
100-
var_kinds: I::CanonicalVarKinds,
100+
pub(super) var_kinds: I::CanonicalVarKinds,
101101

102102
/// What kind of goal we're currently computing, see the enum definition
103103
/// for more info.
104-
current_goal_kind: CurrentGoalKind,
104+
pub(super) current_goal_kind: CurrentGoalKind,
105105
pub(super) var_values: CanonicalVarValues<I>,
106106

107107
/// The highest universe index nameable by the caller.
@@ -486,6 +486,7 @@ where
486486
&orig_values,
487487
response,
488488
self.origin_span,
489+
self.delegate.universe(),
489490
);
490491

491492
// FIXME: We previously had an assert here that checked that recomputing
@@ -564,7 +565,7 @@ where
564565
pub(super) fn compute_goal(&mut self, goal: Goal<I, I::Predicate>) -> QueryResult<I> {
565566
let Goal { param_env, predicate } = goal;
566567
let kind = predicate.kind();
567-
self.enter_forall(kind, |ecx, kind| match kind {
568+
let resp = self.enter_forall(kind, |ecx, kind| match kind {
568569
ty::PredicateKind::Clause(ty::ClauseKind::Trait(predicate)) => {
569570
ecx.compute_trait_goal(Goal { param_env, predicate }).map(|(r, _via)| r)
570571
}
@@ -604,16 +605,18 @@ where
604605
ty::PredicateKind::ConstEquate(_, _) => {
605606
panic!("ConstEquate should not be emitted when `-Znext-solver` is active")
606607
}
607-
ty::PredicateKind::NormalizesTo(predicate) => {
608-
ecx.compute_normalizes_to_goal(Goal { param_env, predicate })
608+
ty::PredicateKind::NormalizesTo(_) => {
609+
unreachable!()
609610
}
610611
ty::PredicateKind::AliasRelate(lhs, rhs, direction) => {
611612
ecx.compute_alias_relate_goal(Goal { param_env, predicate: (lhs, rhs, direction) })
612613
}
613614
ty::PredicateKind::Ambiguous => {
614615
ecx.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
615616
}
616-
})
617+
})?;
618+
debug_assert!(resp.value.external_constraints.normalization_nested_goals.is_empty());
619+
Ok(resp)
617620
}
618621

619622
// Recursively evaluates all the goals added to this `EvalCtxt` to completion, returning
@@ -806,6 +809,7 @@ where
806809
///
807810
/// This is the case if the `term` does not occur in any other part of the predicate
808811
/// and is able to name all other placeholder and inference variables.
812+
#[allow(unused)]
809813
#[instrument(level = "trace", skip(self), ret)]
810814
pub(super) fn term_is_fully_unconstrained(&self, goal: Goal<I, ty::NormalizesTo<I>>) -> bool {
811815
let universe_of_term = match goal.predicate.term.kind() {
@@ -832,6 +836,7 @@ where
832836
cache: HashSet<I::Ty>,
833837
}
834838

839+
#[allow(unused)]
835840
impl<D: SolverDelegate<Interner = I>, I: Interner> ContainsTermOrNotNameable<'_, D, I> {
836841
fn check_nameable(&self, universe: ty::UniverseIndex) -> ControlFlow<()> {
837842
if self.universe_of_term.can_name(universe) {
@@ -1423,16 +1428,15 @@ where
14231428

14241429
fn fold_ty(&mut self, ty: I::Ty) -> I::Ty {
14251430
match ty.kind() {
1426-
ty::Alias(..) if !ty.has_escaping_bound_vars() => {
1431+
ty::Alias(_, alias) if !ty.has_escaping_bound_vars() => {
14271432
let infer_ty = self.ecx.next_ty_infer();
1428-
let normalizes_to = ty::PredicateKind::AliasRelate(
1429-
ty.into(),
1430-
infer_ty.into(),
1431-
ty::AliasRelationDirection::Equate,
1432-
);
1433+
let projection = ty::ClauseKind::Projection(ty::ProjectionPredicate {
1434+
projection_term: alias.into(),
1435+
term: infer_ty.into(),
1436+
});
14331437
self.ecx.add_goal(
14341438
self.normalization_goal_source,
1435-
Goal::new(self.cx(), self.param_env, normalizes_to),
1439+
Goal::new(self.cx(), self.param_env, projection),
14361440
);
14371441
infer_ty
14381442
}
@@ -1452,16 +1456,15 @@ where
14521456

14531457
fn fold_const(&mut self, ct: I::Const) -> I::Const {
14541458
match ct.kind() {
1455-
ty::ConstKind::Unevaluated(..) if !ct.has_escaping_bound_vars() => {
1459+
ty::ConstKind::Unevaluated(uc) if !ct.has_escaping_bound_vars() => {
14561460
let infer_ct = self.ecx.next_const_infer();
1457-
let normalizes_to = ty::PredicateKind::AliasRelate(
1458-
ct.into(),
1459-
infer_ct.into(),
1460-
ty::AliasRelationDirection::Equate,
1461-
);
1461+
let projection = ty::ClauseKind::Projection(ty::ProjectionPredicate {
1462+
projection_term: uc.into(),
1463+
term: infer_ct.into(),
1464+
});
14621465
self.ecx.add_goal(
14631466
self.normalization_goal_source,
1464-
Goal::new(self.cx(), self.param_env, normalizes_to),
1467+
Goal::new(self.cx(), self.param_env, projection),
14651468
);
14661469
infer_ct
14671470
}
@@ -1528,6 +1531,7 @@ pub(super) fn evaluate_root_goal_for_proof_tree<D: SolverDelegate<Interner = I>,
15281531
&proof_tree.orig_values,
15291532
response,
15301533
origin_span,
1534+
delegate.universe(),
15311535
);
15321536

15331537
(Ok(normalization_nested_goals), proof_tree)

compiler/rustc_next_trait_solver/src/solve/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ mod assembly;
1616
mod effect_goals;
1717
mod eval_ctxt;
1818
pub mod inspect;
19-
mod normalizes_to;
2019
mod project_goals;
2120
mod search_graph;
2221
mod trait_goals;

compiler/rustc_next_trait_solver/src/solve/project_goals/anon_const.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ where
1212
#[instrument(level = "trace", skip(self), ret)]
1313
pub(super) fn normalize_anon_const(
1414
&mut self,
15-
goal: Goal<I, ty::NormalizesTo<I>>,
15+
goal: Goal<I, ty::ProjectionPredicate<I>>,
1616
) -> QueryResult<I> {
1717
if self.typing_mode() == TypingMode::Coherence
18-
&& self.cx().anon_const_kind(goal.predicate.alias.def_id) == ty::AnonConstKind::OGCA
18+
&& self.cx().anon_const_kind(goal.predicate.projection_term.def_id)
19+
== ty::AnonConstKind::OGCA
1920
{
2021
// During coherence, OGCA consts should be normalized ambiguously
2122
// because they are opaque but eventually resolved to a real value.
@@ -28,11 +29,11 @@ where
2829
} else if let Some(normalized_const) = self.evaluate_const(
2930
goal.param_env,
3031
ty::UnevaluatedConst::new(
31-
goal.predicate.alias.def_id.try_into().unwrap(),
32-
goal.predicate.alias.args,
32+
goal.predicate.projection_term.def_id.try_into().unwrap(),
33+
goal.predicate.projection_term.args,
3334
),
3435
) {
35-
self.instantiate_normalizes_to_term(goal, normalized_const.into());
36+
self.instantiate_projection_term(goal, normalized_const.into())?;
3637
self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
3738
} else {
3839
self.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)

compiler/rustc_next_trait_solver/src/solve/project_goals/free_alias.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ where
1616
{
1717
pub(super) fn normalize_free_alias(
1818
&mut self,
19-
goal: Goal<I, ty::NormalizesTo<I>>,
19+
goal: Goal<I, ty::ProjectionPredicate<I>>,
2020
) -> QueryResult<I> {
2121
let cx = self.cx();
22-
let free_alias = goal.predicate.alias;
22+
let free_alias = goal.predicate.projection_term;
2323

2424
// Check where clauses
2525
self.add_goals(
@@ -35,7 +35,7 @@ where
3535
cx.const_of_item(free_alias.def_id).instantiate(cx, free_alias.args).into()
3636
};
3737

38-
self.instantiate_normalizes_to_term(goal, actual);
38+
self.instantiate_projection_term(goal, actual)?;
3939
self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
4040
}
4141
}

compiler/rustc_next_trait_solver/src/solve/project_goals/inherent.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ where
1717
{
1818
pub(super) fn normalize_inherent_associated_term(
1919
&mut self,
20-
goal: Goal<I, ty::NormalizesTo<I>>,
20+
goal: Goal<I, ty::ProjectionPredicate<I>>,
2121
) -> QueryResult<I> {
2222
let cx = self.cx();
23-
let inherent = goal.predicate.alias;
23+
let inherent = goal.predicate.projection_term;
2424

2525
let impl_def_id = cx.parent(inherent.def_id);
2626
let impl_args = self.fresh_args_for_item(impl_def_id);
@@ -56,7 +56,7 @@ where
5656
} else {
5757
cx.const_of_item(inherent.def_id).instantiate(cx, inherent_args).into()
5858
};
59-
self.instantiate_normalizes_to_term(goal, normalized);
59+
self.instantiate_projection_term(goal, normalized)?;
6060
self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
6161
}
6262
}

0 commit comments

Comments
 (0)