Skip to content

Commit f686953

Browse files
committed
Use NormalizesTo instead of AliasRelate for normalization
1 parent 39602ee commit f686953

28 files changed

Lines changed: 96 additions & 109 deletions

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2292,9 +2292,11 @@ pub(super) fn check_potentially_region_dependent_goals<'tcx>(
22922292
let infcx = tcx.infer_ctxt().ignoring_regions().build(typing_mode);
22932293
let ocx = ObligationCtxt::new_with_diagnostics(&infcx);
22942294
for (predicate, cause) in &typeck_results.potentially_region_dependent_goals {
2295+
tracing::debug!("PREDA {predicate:?}");
22952296
let predicate = fold_regions(tcx, *predicate, |_, _| {
22962297
infcx.next_region_var(RegionVariableOrigin::Misc(cause.span))
22972298
});
2299+
tracing::debug!("PREDB {predicate:?}");
22982300
ocx.register_obligation(Obligation::new(tcx, cause.clone(), param_env, predicate));
22992301
}
23002302

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

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,13 +1219,12 @@ where
12191219

12201220
fn fold_ty(&mut self, ty: Ty<I>) -> Ty<I> {
12211221
match ty.kind() {
1222-
ty::Alias(..) if !ty.has_escaping_bound_vars() => {
1222+
ty::Alias(_, alias) if !ty.has_escaping_bound_vars() => {
12231223
let infer_ty = self.ecx.next_ty_infer();
1224-
let normalizes_to = ty::PredicateKind::AliasRelate(
1225-
ty.into(),
1226-
infer_ty.into(),
1227-
ty::AliasRelationDirection::Equate,
1228-
);
1224+
let normalizes_to = ty::PredicateKind::NormalizesTo(ty::NormalizesTo {
1225+
alias: ty::AliasTerm::new_from_args(self.cx(), alias.def_id, alias.args),
1226+
term: infer_ty.into(),
1227+
});
12291228
self.ecx.add_goal(
12301229
self.normalization_goal_source,
12311230
Goal::new(self.cx(), self.param_env, normalizes_to),
@@ -1248,13 +1247,12 @@ where
12481247

12491248
fn fold_const(&mut self, ct: I::Const) -> I::Const {
12501249
match ct.kind() {
1251-
ty::ConstKind::Unevaluated(..) if !ct.has_escaping_bound_vars() => {
1250+
ty::ConstKind::Unevaluated(uc) if !ct.has_escaping_bound_vars() => {
12521251
let infer_ct = self.ecx.next_const_infer();
1253-
let normalizes_to = ty::PredicateKind::AliasRelate(
1254-
ct.into(),
1255-
infer_ct.into(),
1256-
ty::AliasRelationDirection::Equate,
1257-
);
1252+
let normalizes_to = ty::PredicateKind::NormalizesTo(ty::NormalizesTo {
1253+
alias: ty::AliasTerm::new_from_args(self.cx(), uc.def.into(), uc.args),
1254+
term: infer_ct.into(),
1255+
});
12581256
self.ecx.add_goal(
12591257
self.normalization_goal_source,
12601258
Goal::new(self.cx(), self.param_env, normalizes_to),

compiler/rustc_next_trait_solver/src/solve/mod.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -344,20 +344,16 @@ where
344344
param_env: I::ParamEnv,
345345
term: I::Term,
346346
) -> Result<I::Term, NoSolution> {
347-
if let Some(_) = term.to_alias_term() {
347+
if let Some(alias) = term.to_alias_term() {
348348
let normalized_term = self.next_term_infer_of_kind(term);
349-
let alias_relate_goal = Goal::new(
349+
let normalizes_to_goal = Goal::new(
350350
self.cx(),
351351
param_env,
352-
ty::PredicateKind::AliasRelate(
353-
term,
354-
normalized_term,
355-
ty::AliasRelationDirection::Equate,
356-
),
352+
ty::PredicateKind::NormalizesTo(ty::NormalizesTo { alias, term: normalized_term }),
357353
);
358354
// We normalize the self type to be able to relate it with
359355
// types from candidates.
360-
self.add_goal(GoalSource::TypeRelating, alias_relate_goal);
356+
self.add_goal(GoalSource::TypeRelating, normalizes_to_goal);
361357
self.try_evaluate_added_goals()?;
362358
Ok(self.resolve_vars_if_possible(normalized_term))
363359
} else {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ where
3232
goal.predicate.alias.args,
3333
),
3434
) {
35-
self.instantiate_normalizes_to_term(goal, normalized_const.into());
35+
self.eq(goal.param_env, goal.predicate.term, normalized_const.into())?;
3636
self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
3737
} else {
3838
self.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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.eq(goal.param_env, goal.predicate.term, actual)?;
3939
self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
4040
}
4141
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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.eq(goal.param_env, goal.predicate.term, normalized)?;
6060
self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
6161
}
6262
}

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,14 @@ where
113113
/// We know `term` to always be a fully unconstrained inference variable, so
114114
/// `eq` should never fail here. However, in case `term` contains aliases, we
115115
/// emit nested `AliasRelate` goals to structurally normalize the alias.
116-
pub fn instantiate_normalizes_to_term(
117-
&mut self,
118-
goal: Goal<I, NormalizesTo<I>>,
119-
term: I::Term,
120-
) {
116+
fn instantiate_normalizes_to_term(&mut self, goal: Goal<I, NormalizesTo<I>>, term: I::Term) {
121117
self.eq(goal.param_env, goal.predicate.term, term)
122118
.expect("expected goal term to be fully unconstrained");
123119
}
124120

125121
/// Unlike `instantiate_normalizes_to_term` this instantiates the expected term
126122
/// with a rigid alias. Using this is pretty much always wrong.
127-
pub fn structurally_instantiate_normalizes_to_term(
123+
fn structurally_instantiate_normalizes_to_term(
128124
&mut self,
129125
goal: Goal<I, NormalizesTo<I>>,
130126
term: ty::AliasTerm<I>,

compiler/rustc_next_trait_solver/src/solve/normalizes_to/opaque_types.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,12 @@ where
4848
.filter(|&def_id| defining_opaque_types.contains(&def_id))
4949
else {
5050
// If we're not in the defining scope, treat the alias as rigid.
51-
self.structurally_instantiate_normalizes_to_term(goal, goal.predicate.alias);
51+
self.relate_rigid_alias_non_alias(
52+
goal.param_env,
53+
goal.predicate.alias,
54+
ty::Invariant,
55+
goal.predicate.term,
56+
)?;
5257
return self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes);
5358
};
5459

@@ -111,7 +116,12 @@ where
111116
.as_local()
112117
.filter(|&def_id| defined_opaque_types.contains(&def_id))
113118
else {
114-
self.structurally_instantiate_normalizes_to_term(goal, goal.predicate.alias);
119+
self.relate_rigid_alias_non_alias(
120+
goal.param_env,
121+
goal.predicate.alias,
122+
ty::Invariant,
123+
goal.predicate.term,
124+
)?;
115125
return self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes);
116126
};
117127

compiler/rustc_trait_selection/src/solve/fulfill.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ where
185185
loop {
186186
let mut any_changed = false;
187187
for (mut obligation, stalled_on) in self.obligations.drain_pending(|_| true) {
188+
let orig = obligation.clone();
188189
if !infcx.tcx.recursion_limit().value_within_limit(obligation.recursion_depth) {
189190
self.obligations.on_fulfillment_overflow(infcx);
190191
// Only return true errors that we have accumulated while processing.
@@ -255,6 +256,7 @@ where
255256
if infcx.in_hir_typeck
256257
&& (obligation.has_non_region_infer() || obligation.has_free_regions())
257258
{
259+
tracing::debug!("REGISTERED {orig:?} - {obligation:?}");
258260
infcx.push_hir_typeck_potentially_region_dependent_goal(obligation);
259261
}
260262
}

compiler/rustc_trait_selection/src/solve/fulfill/derive_errors.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,13 +292,13 @@ impl<'tcx> BestObligation<'tcx> {
292292
) -> ControlFlow<PredicateObligation<'tcx>> {
293293
assert!(!self.consider_ambiguities);
294294
let tcx = goal.infcx().tcx;
295-
if let ty::Alias(..) = self_ty.kind() {
295+
let term: ty::Term<'tcx> = self_ty.into();
296+
if let Some(alias) = term.to_alias_term() {
296297
let infer_term = goal.infcx().next_ty_var(self.obligation.cause.span);
297-
let pred = ty::PredicateKind::AliasRelate(
298-
self_ty.into(),
299-
infer_term.into(),
300-
ty::AliasRelationDirection::Equate,
301-
);
298+
let pred = ty::PredicateKind::NormalizesTo(ty::NormalizesTo {
299+
alias,
300+
term: infer_term.into(),
301+
});
302302
let obligation =
303303
Obligation::new(tcx, self.obligation.cause.clone(), goal.goal().param_env, pred);
304304
self.with_derived_obligation(obligation, |this| {

0 commit comments

Comments
 (0)