Skip to content

Commit

Permalink
Inline fold_infer_ty
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed May 31, 2024
1 parent 8179ee5 commit c623ae1
Showing 1 changed file with 34 additions and 34 deletions.
68 changes: 34 additions & 34 deletions compiler/rustc_infer/src/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1248,44 +1248,44 @@ impl<'tcx> InferCtxt<'tcx> {
}

pub fn shallow_resolve(&self, ty: Ty<'tcx>) -> Ty<'tcx> {
if let ty::Infer(v) = ty.kind() { self.fold_infer_ty(*v).unwrap_or(ty) } else { ty }
}

// This is separate from `shallow_resolve` to keep that method small and inlinable.
#[inline(never)]
fn fold_infer_ty(&self, v: InferTy) -> Option<Ty<'tcx>> {
match v {
ty::TyVar(v) => {
// Not entirely obvious: if `typ` is a type variable,
// it can be resolved to an int/float variable, which
// can then be recursively resolved, hence the
// recursion. Note though that we prevent type
// variables from unifying to other type variables
// directly (though they may be embedded
// structurally), and we prevent cycles in any case,
// so this recursion should always be of very limited
// depth.
//
// Note: if these two lines are combined into one we get
// dynamic borrow errors on `self.inner`.
let known = self.inner.borrow_mut().type_variables().probe(v).known();
known.map(|t| self.shallow_resolve(t))
}
if let ty::Infer(v) = *ty.kind() {
match v {
ty::TyVar(v) => {
// Not entirely obvious: if `typ` is a type variable,
// it can be resolved to an int/float variable, which
// can then be recursively resolved, hence the
// recursion. Note though that we prevent type
// variables from unifying to other type variables
// directly (though they may be embedded
// structurally), and we prevent cycles in any case,
// so this recursion should always be of very limited
// depth.
//
// Note: if these two lines are combined into one we get
// dynamic borrow errors on `self.inner`.
let known = self.inner.borrow_mut().type_variables().probe(v).known();
known.map_or(ty, |t| self.shallow_resolve(t))
}

ty::IntVar(v) => match self.inner.borrow_mut().int_unification_table().probe_value(v) {
ty::IntVarValue::Unknown => None,
ty::IntVarValue::IntType(ty) => Some(Ty::new_int(self.tcx, ty)),
ty::IntVarValue::UintType(ty) => Some(Ty::new_uint(self.tcx, ty)),
},
ty::IntVar(v) => {
match self.inner.borrow_mut().int_unification_table().probe_value(v) {
ty::IntVarValue::Unknown => ty,
ty::IntVarValue::IntType(ty) => Ty::new_int(self.tcx, ty),
ty::IntVarValue::UintType(ty) => Ty::new_uint(self.tcx, ty),
}
}

ty::FloatVar(v) => {
match self.inner.borrow_mut().float_unification_table().probe_value(v) {
ty::FloatVarValue::Unknown => None,
ty::FloatVarValue::Known(ty) => Some(Ty::new_float(self.tcx, ty)),
ty::FloatVar(v) => {
match self.inner.borrow_mut().float_unification_table().probe_value(v) {
ty::FloatVarValue::Unknown => ty,
ty::FloatVarValue::Known(ty) => Ty::new_float(self.tcx, ty),
}
}
}

ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_) => None,
ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_) => ty,
}
} else {
ty
}
}

Expand Down

0 comments on commit c623ae1

Please sign in to comment.