diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-03-15 12:51:27 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-03-15 12:51:27 +0000 |
commit | 6139bd764974318814edfd5427e2a2e8220b211b (patch) | |
tree | 70aa9b1a1b338f0c02545cb544ab37c4547f7ce2 /crates/hir_ty/src/infer/expr.rs | |
parent | a8b319cf28c0985d964ef6624c3ee6e7f09afb2d (diff) | |
parent | 42217738e0b121a8e5d48a9a55cb51ef6c98975f (diff) |
Merge #8018
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 <[email protected]>
Diffstat (limited to 'crates/hir_ty/src/infer/expr.rs')
-rw-r--r-- | crates/hir_ty/src/infer/expr.rs | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs index 1a11b146a..f40dec17f 100644 --- a/crates/hir_ty/src/infer/expr.rs +++ b/crates/hir_ty/src/infer/expr.rs | |||
@@ -503,8 +503,8 @@ impl<'a> InferenceContext<'a> { | |||
503 | }; | 503 | }; |
504 | let inner_ty = self.infer_expr_inner(*expr, &expectation); | 504 | let inner_ty = self.infer_expr_inner(*expr, &expectation); |
505 | match rawness { | 505 | match rawness { |
506 | Rawness::RawPtr => TyKind::Raw(mutability, Substs::single(inner_ty)), | 506 | Rawness::RawPtr => TyKind::Raw(mutability, inner_ty), |
507 | Rawness::Ref => TyKind::Ref(mutability, Substs::single(inner_ty)), | 507 | Rawness::Ref => TyKind::Ref(mutability, inner_ty), |
508 | } | 508 | } |
509 | .intern(&Interner) | 509 | .intern(&Interner) |
510 | } | 510 | } |
@@ -685,7 +685,7 @@ impl<'a> InferenceContext<'a> { | |||
685 | } | 685 | } |
686 | Expr::Array(array) => { | 686 | Expr::Array(array) => { |
687 | let elem_ty = match expected.ty.interned(&Interner) { | 687 | let elem_ty = match expected.ty.interned(&Interner) { |
688 | TyKind::Array(st) | TyKind::Slice(st) => st.as_single().clone(), | 688 | TyKind::Array(st) | TyKind::Slice(st) => st.clone(), |
689 | _ => self.table.new_type_var(), | 689 | _ => self.table.new_type_var(), |
690 | }; | 690 | }; |
691 | 691 | ||
@@ -709,18 +709,17 @@ impl<'a> InferenceContext<'a> { | |||
709 | } | 709 | } |
710 | } | 710 | } |
711 | 711 | ||
712 | TyKind::Array(Substs::single(elem_ty)).intern(&Interner) | 712 | TyKind::Array(elem_ty).intern(&Interner) |
713 | } | 713 | } |
714 | Expr::Literal(lit) => match lit { | 714 | Expr::Literal(lit) => match lit { |
715 | Literal::Bool(..) => TyKind::Scalar(Scalar::Bool).intern(&Interner), | 715 | Literal::Bool(..) => TyKind::Scalar(Scalar::Bool).intern(&Interner), |
716 | Literal::String(..) => { | 716 | Literal::String(..) => { |
717 | TyKind::Ref(Mutability::Not, Substs::single(TyKind::Str.intern(&Interner))) | 717 | TyKind::Ref(Mutability::Not, TyKind::Str.intern(&Interner)).intern(&Interner) |
718 | .intern(&Interner) | ||
719 | } | 718 | } |
720 | Literal::ByteString(..) => { | 719 | Literal::ByteString(..) => { |
721 | let byte_type = TyKind::Scalar(Scalar::Uint(UintTy::U8)).intern(&Interner); | 720 | let byte_type = TyKind::Scalar(Scalar::Uint(UintTy::U8)).intern(&Interner); |
722 | let array_type = TyKind::Array(Substs::single(byte_type)).intern(&Interner); | 721 | let array_type = TyKind::Array(byte_type).intern(&Interner); |
723 | TyKind::Ref(Mutability::Not, Substs::single(array_type)).intern(&Interner) | 722 | TyKind::Ref(Mutability::Not, array_type).intern(&Interner) |
724 | } | 723 | } |
725 | Literal::Char(..) => TyKind::Scalar(Scalar::Char).intern(&Interner), | 724 | Literal::Char(..) => TyKind::Scalar(Scalar::Char).intern(&Interner), |
726 | Literal::Int(_v, ty) => match ty { | 725 | Literal::Int(_v, ty) => match ty { |
@@ -799,7 +798,7 @@ impl<'a> InferenceContext<'a> { | |||
799 | // we don't even make an attempt at coercion | 798 | // we don't even make an attempt at coercion |
800 | self.table.new_maybe_never_var() | 799 | self.table.new_maybe_never_var() |
801 | } else { | 800 | } else { |
802 | self.coerce(&Ty::unit(), expected.coercion_target()); | 801 | self.coerce(&Ty::unit(), &expected.coercion_target()); |
803 | Ty::unit() | 802 | Ty::unit() |
804 | } | 803 | } |
805 | }; | 804 | }; |
@@ -854,9 +853,7 @@ impl<'a> InferenceContext<'a> { | |||
854 | // Apply autoref so the below unification works correctly | 853 | // Apply autoref so the below unification works correctly |
855 | // FIXME: return correct autorefs from lookup_method | 854 | // FIXME: return correct autorefs from lookup_method |
856 | let actual_receiver_ty = match expected_receiver_ty.as_reference() { | 855 | let actual_receiver_ty = match expected_receiver_ty.as_reference() { |
857 | Some((_, mutability)) => { | 856 | Some((_, mutability)) => TyKind::Ref(mutability, derefed_receiver_ty).intern(&Interner), |
858 | TyKind::Ref(mutability, Substs::single(derefed_receiver_ty)).intern(&Interner) | ||
859 | } | ||
860 | _ => derefed_receiver_ty, | 857 | _ => derefed_receiver_ty, |
861 | }; | 858 | }; |
862 | self.unify(&expected_receiver_ty, &actual_receiver_ty); | 859 | self.unify(&expected_receiver_ty, &actual_receiver_ty); |