This commit is contained in:
lcnr
2025-09-08 11:41:43 +02:00
parent f514586408
commit b51a3a565a
12 changed files with 57 additions and 40 deletions

View File

@@ -67,6 +67,12 @@ pub struct Canonicalizer<'a, D: SolverDelegate<Interner = I>, I: Interner> {
variables: &'a mut Vec<I::GenericArg>,
var_kinds: Vec<CanonicalVarKind<I>>,
variable_lookup_table: HashMap<I::GenericArg, usize>,
/// Maps each `sub_unification_table_root_var` to the index of the first
/// variable which used it.
///
/// This means in case two type variables have the same sub relations root,
/// we set the `sub_root` of the second variable to the position of the first.
/// Otherwise the `sub_root` of each type variable is just its own position.
sub_root_lookup_table: HashMap<ty::TyVid, usize>,
binder_index: ty::DebruijnIndex,
@@ -273,7 +279,7 @@ impl<'a, D: SolverDelegate<Interner = I>, I: Interner> Canonicalizer<'a, D, I> {
}
fn get_or_insert_sub_root(&mut self, vid: ty::TyVid) -> ty::BoundVar {
let root_vid = self.delegate.sub_root_ty_var(vid);
let root_vid = self.delegate.sub_unification_table_root_var(vid);
let idx =
*self.sub_root_lookup_table.entry(root_vid).or_insert_with(|| self.variables.len());
ty::BoundVar::from(idx)

View File

@@ -900,8 +900,8 @@ where
&& goal.param_env.visit_with(&mut visitor).is_continue()
}
pub(super) fn sub_ty_vids_raw(&self, a: ty::TyVid, b: ty::TyVid) {
self.delegate.sub_ty_vids_raw(a, b)
pub(super) fn sub_unify_ty_vids_raw(&self, a: ty::TyVid, b: ty::TyVid) {
self.delegate.sub_unify_ty_vids_raw(a, b)
}
#[instrument(level = "trace", skip(self, param_env), ret)]

View File

@@ -121,7 +121,7 @@ where
fn compute_subtype_goal(&mut self, goal: Goal<I, ty::SubtypePredicate<I>>) -> QueryResult<I> {
match (goal.predicate.a.kind(), goal.predicate.b.kind()) {
(ty::Infer(ty::TyVar(a_vid)), ty::Infer(ty::TyVar(b_vid))) => {
self.sub_ty_vids_raw(a_vid, b_vid);
self.sub_unify_ty_vids_raw(a_vid, b_vid);
self.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
}
_ => {