introduce new fallback algorithm
We now fallback type variables using the following rules: * Construct a coercion graph `A -> B` where `A` and `B` are unresolved type variables or the `!` type. * Let D be those variables that are reachable from `!`. * Let N be those variables that are reachable from a variable not in D. * All variables in (D \ N) fallback to `!`. * All variables in (D & N) fallback to `()`.
This commit is contained in:
parent
e0c38af27c
commit
2ee89144e2
7 changed files with 347 additions and 55 deletions
|
@ -707,11 +707,17 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
/// No attempt is made to resolve `ty`.
|
||||
pub fn type_var_diverges(&'a self, ty: Ty<'_>) -> Diverging {
|
||||
match *ty.kind() {
|
||||
ty::Infer(ty::TyVar(vid)) => self.inner.borrow_mut().type_variables().var_diverges(vid),
|
||||
ty::Infer(ty::TyVar(vid)) => self.ty_vid_diverges(vid),
|
||||
_ => Diverging::NotDiverging,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns true if the type inference variable `vid` was created
|
||||
/// as a diverging type variable. No attempt is made to resolve `vid`.
|
||||
pub fn ty_vid_diverges(&'a self, vid: ty::TyVid) -> Diverging {
|
||||
self.inner.borrow_mut().type_variables().var_diverges(vid)
|
||||
}
|
||||
|
||||
/// Returns the origin of the type variable identified by `vid`, or `None`
|
||||
/// if this is not a type variable.
|
||||
///
|
||||
|
@ -1070,6 +1076,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
})
|
||||
}
|
||||
|
||||
/// Number of type variables created so far.
|
||||
pub fn num_ty_vars(&self) -> usize {
|
||||
self.inner.borrow_mut().type_variables().num_vars()
|
||||
}
|
||||
|
||||
pub fn next_ty_var_id(&self, diverging: Diverging, origin: TypeVariableOrigin) -> TyVid {
|
||||
self.inner.borrow_mut().type_variables().new_var(self.universe(), diverging, origin)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue