1
Fork 0

Rework var resolution in InferCtxtLike, uplift EagerResolver

This commit is contained in:
Michael Goulet 2024-05-19 13:04:44 -04:00
parent 569fb43aa0
commit b0f1afd1fc
12 changed files with 204 additions and 165 deletions

View file

@ -268,7 +268,7 @@ impl<Infcx: InferCtxtLike<Interner = I>, I: Interner> TypeFolder<I>
ty::ReVar(vid) => {
assert_eq!(
self.infcx.opportunistic_resolve_lt_var(vid),
None,
r,
"region vid should have been resolved fully before canonicalization"
);
match self.canonicalize_mode {
@ -302,13 +302,8 @@ impl<Infcx: InferCtxtLike<Interner = I>, I: Interner> TypeFolder<I>
ty::Infer(i) => match i {
ty::TyVar(vid) => {
assert_eq!(
self.infcx.root_ty_var(vid),
vid,
"ty vid should have been resolved fully before canonicalization"
);
assert_eq!(
self.infcx.probe_ty_var(vid),
None,
self.infcx.opportunistic_resolve_ty_var(vid),
t,
"ty vid should have been resolved fully before canonicalization"
);
@ -318,10 +313,24 @@ impl<Infcx: InferCtxtLike<Interner = I>, I: Interner> TypeFolder<I>
.unwrap_or_else(|| panic!("ty var should have been resolved: {t:?}")),
))
}
ty::IntVar(_) => CanonicalVarKind::Ty(CanonicalTyVarKind::Int),
ty::FloatVar(_) => CanonicalVarKind::Ty(CanonicalTyVarKind::Float),
ty::IntVar(vid) => {
assert_eq!(
self.infcx.opportunistic_resolve_int_var(vid),
t,
"ty vid should have been resolved fully before canonicalization"
);
CanonicalVarKind::Ty(CanonicalTyVarKind::Int)
}
ty::FloatVar(vid) => {
assert_eq!(
self.infcx.opportunistic_resolve_float_var(vid),
t,
"ty vid should have been resolved fully before canonicalization"
);
CanonicalVarKind::Ty(CanonicalTyVarKind::Float)
}
ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_) => {
todo!()
panic!("fresh vars not expected in canonicalization")
}
},
ty::Placeholder(placeholder) => match self.canonicalize_mode {
@ -387,14 +396,11 @@ impl<Infcx: InferCtxtLike<Interner = I>, I: Interner> TypeFolder<I>
let kind = match c.kind() {
ty::ConstKind::Infer(i) => match i {
ty::InferConst::Var(vid) => {
// We compare `kind`s here because we've folded the `ty` with `RegionsToStatic`
// so we'll get a mismatch in types if it actually changed any regions.
assert_eq!(
self.infcx.root_ct_var(vid),
vid,
"region vid should have been resolved fully before canonicalization"
);
assert_eq!(
self.infcx.probe_ct_var(vid),
None,
self.infcx.opportunistic_resolve_ct_var(vid, ty).kind(),
c.kind(),
"region vid should have been resolved fully before canonicalization"
);
CanonicalVarKind::Const(self.infcx.universe_of_ct(vid).unwrap(), ty)