8018: Make Ty wrap TyKind in an Arc r=flodiebold a=flodiebold

... to further move towards Chalk.

This is a bit of a slowdown (218ginstr vs 213ginstr for inference on RA), even though it allows us to unwrap the Substs in `TyKind::Ref` etc..

Co-authored-by: Florian Diebold <flodiebold@gmail.com>
This commit is contained in:
bors[bot] 2021-03-15 12:51:27 +00:00 committed by GitHub
commit 6139bd7649
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 155 additions and 142 deletions

View file

@ -503,8 +503,8 @@ impl<'a> InferenceContext<'a> {
};
let inner_ty = self.infer_expr_inner(*expr, &expectation);
match rawness {
Rawness::RawPtr => TyKind::Raw(mutability, Substs::single(inner_ty)),
Rawness::Ref => TyKind::Ref(mutability, Substs::single(inner_ty)),
Rawness::RawPtr => TyKind::Raw(mutability, inner_ty),
Rawness::Ref => TyKind::Ref(mutability, inner_ty),
}
.intern(&Interner)
}
@ -685,7 +685,7 @@ impl<'a> InferenceContext<'a> {
}
Expr::Array(array) => {
let elem_ty = match expected.ty.interned(&Interner) {
TyKind::Array(st) | TyKind::Slice(st) => st.as_single().clone(),
TyKind::Array(st) | TyKind::Slice(st) => st.clone(),
_ => self.table.new_type_var(),
};
@ -709,18 +709,17 @@ impl<'a> InferenceContext<'a> {
}
}
TyKind::Array(Substs::single(elem_ty)).intern(&Interner)
TyKind::Array(elem_ty).intern(&Interner)
}
Expr::Literal(lit) => match lit {
Literal::Bool(..) => TyKind::Scalar(Scalar::Bool).intern(&Interner),
Literal::String(..) => {
TyKind::Ref(Mutability::Not, Substs::single(TyKind::Str.intern(&Interner)))
.intern(&Interner)
TyKind::Ref(Mutability::Not, TyKind::Str.intern(&Interner)).intern(&Interner)
}
Literal::ByteString(..) => {
let byte_type = TyKind::Scalar(Scalar::Uint(UintTy::U8)).intern(&Interner);
let array_type = TyKind::Array(Substs::single(byte_type)).intern(&Interner);
TyKind::Ref(Mutability::Not, Substs::single(array_type)).intern(&Interner)
let array_type = TyKind::Array(byte_type).intern(&Interner);
TyKind::Ref(Mutability::Not, array_type).intern(&Interner)
}
Literal::Char(..) => TyKind::Scalar(Scalar::Char).intern(&Interner),
Literal::Int(_v, ty) => match ty {
@ -799,7 +798,7 @@ impl<'a> InferenceContext<'a> {
// we don't even make an attempt at coercion
self.table.new_maybe_never_var()
} else {
self.coerce(&Ty::unit(), expected.coercion_target());
self.coerce(&Ty::unit(), &expected.coercion_target());
Ty::unit()
}
};
@ -854,9 +853,7 @@ impl<'a> InferenceContext<'a> {
// Apply autoref so the below unification works correctly
// FIXME: return correct autorefs from lookup_method
let actual_receiver_ty = match expected_receiver_ty.as_reference() {
Some((_, mutability)) => {
TyKind::Ref(mutability, Substs::single(derefed_receiver_ty)).intern(&Interner)
}
Some((_, mutability)) => TyKind::Ref(mutability, derefed_receiver_ty).intern(&Interner),
_ => derefed_receiver_ty,
};
self.unify(&expected_receiver_ty, &actual_receiver_ty);