diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-02-28 13:36:44 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-02-28 13:36:44 +0000 |
commit | 803ff2e55eeb6bd1d9028fbbffe34721f0e6d459 (patch) | |
tree | c0df3cba7d22fe49e1ea33dde6ed8d4c9e0f663f /crates/hir_ty/src/op.rs | |
parent | 7f57a01b3d524a5ed85a30265b8aee2c81118f15 (diff) | |
parent | 7c2dd85a32e320fd412a720ea5b847c66bf246ae (diff) |
Merge #7804
7804: Introduce TypeCtor::Scalar r=lnicola a=Veykril
`TypeCtor::Int(..) | TypeCtor::Float(..) | TypeCtor::Char | TypeCtor::Bool` => `TypeCtor::Scalar(..)`, in this case we can actually just straight up use `chalk_ir::Scalar` already since its just a POD without any IDs or anything.
Co-authored-by: Lukas Wirth <[email protected]>
Diffstat (limited to 'crates/hir_ty/src/op.rs')
-rw-r--r-- | crates/hir_ty/src/op.rs | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/crates/hir_ty/src/op.rs b/crates/hir_ty/src/op.rs index 0870874fc..a4999c51d 100644 --- a/crates/hir_ty/src/op.rs +++ b/crates/hir_ty/src/op.rs | |||
@@ -2,15 +2,17 @@ | |||
2 | use hir_def::expr::{ArithOp, BinaryOp, CmpOp}; | 2 | use hir_def::expr::{ArithOp, BinaryOp, CmpOp}; |
3 | 3 | ||
4 | use super::{InferTy, Ty, TypeCtor}; | 4 | use super::{InferTy, Ty, TypeCtor}; |
5 | use crate::ApplicationTy; | 5 | use crate::{ApplicationTy, Scalar}; |
6 | 6 | ||
7 | pub(super) fn binary_op_return_ty(op: BinaryOp, lhs_ty: Ty, rhs_ty: Ty) -> Ty { | 7 | pub(super) fn binary_op_return_ty(op: BinaryOp, lhs_ty: Ty, rhs_ty: Ty) -> Ty { |
8 | match op { | 8 | match op { |
9 | BinaryOp::LogicOp(_) | BinaryOp::CmpOp(_) => Ty::simple(TypeCtor::Bool), | 9 | BinaryOp::LogicOp(_) | BinaryOp::CmpOp(_) => Ty::simple(TypeCtor::Scalar(Scalar::Bool)), |
10 | BinaryOp::Assignment { .. } => Ty::unit(), | 10 | BinaryOp::Assignment { .. } => Ty::unit(), |
11 | BinaryOp::ArithOp(ArithOp::Shl) | BinaryOp::ArithOp(ArithOp::Shr) => match lhs_ty { | 11 | BinaryOp::ArithOp(ArithOp::Shl) | BinaryOp::ArithOp(ArithOp::Shr) => match lhs_ty { |
12 | Ty::Apply(ApplicationTy { ctor, .. }) => match ctor { | 12 | Ty::Apply(ApplicationTy { ctor, .. }) => match ctor { |
13 | TypeCtor::Int(..) | TypeCtor::Float(..) => lhs_ty, | 13 | TypeCtor::Scalar(Scalar::Int(_)) |
14 | | TypeCtor::Scalar(Scalar::Uint(_)) | ||
15 | | TypeCtor::Scalar(Scalar::Float(_)) => lhs_ty, | ||
14 | _ => Ty::Unknown, | 16 | _ => Ty::Unknown, |
15 | }, | 17 | }, |
16 | Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => lhs_ty, | 18 | Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => lhs_ty, |
@@ -18,7 +20,9 @@ pub(super) fn binary_op_return_ty(op: BinaryOp, lhs_ty: Ty, rhs_ty: Ty) -> Ty { | |||
18 | }, | 20 | }, |
19 | BinaryOp::ArithOp(_) => match rhs_ty { | 21 | BinaryOp::ArithOp(_) => match rhs_ty { |
20 | Ty::Apply(ApplicationTy { ctor, .. }) => match ctor { | 22 | Ty::Apply(ApplicationTy { ctor, .. }) => match ctor { |
21 | TypeCtor::Int(..) | TypeCtor::Float(..) => rhs_ty, | 23 | TypeCtor::Scalar(Scalar::Int(_)) |
24 | | TypeCtor::Scalar(Scalar::Uint(_)) | ||
25 | | TypeCtor::Scalar(Scalar::Float(_)) => rhs_ty, | ||
22 | _ => Ty::Unknown, | 26 | _ => Ty::Unknown, |
23 | }, | 27 | }, |
24 | Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => rhs_ty, | 28 | Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => rhs_ty, |
@@ -29,15 +33,11 @@ pub(super) fn binary_op_return_ty(op: BinaryOp, lhs_ty: Ty, rhs_ty: Ty) -> Ty { | |||
29 | 33 | ||
30 | pub(super) fn binary_op_rhs_expectation(op: BinaryOp, lhs_ty: Ty) -> Ty { | 34 | pub(super) fn binary_op_rhs_expectation(op: BinaryOp, lhs_ty: Ty) -> Ty { |
31 | match op { | 35 | match op { |
32 | BinaryOp::LogicOp(..) => Ty::simple(TypeCtor::Bool), | 36 | BinaryOp::LogicOp(..) => Ty::simple(TypeCtor::Scalar(Scalar::Bool)), |
33 | BinaryOp::Assignment { op: None } => lhs_ty, | 37 | BinaryOp::Assignment { op: None } => lhs_ty, |
34 | BinaryOp::CmpOp(CmpOp::Eq { .. }) => match lhs_ty { | 38 | BinaryOp::CmpOp(CmpOp::Eq { .. }) => match lhs_ty { |
35 | Ty::Apply(ApplicationTy { ctor, .. }) => match ctor { | 39 | Ty::Apply(ApplicationTy { ctor, .. }) => match ctor { |
36 | TypeCtor::Int(..) | 40 | TypeCtor::Scalar(_) | TypeCtor::Str => lhs_ty, |
37 | | TypeCtor::Float(..) | ||
38 | | TypeCtor::Str | ||
39 | | TypeCtor::Char | ||
40 | | TypeCtor::Bool => lhs_ty, | ||
41 | _ => Ty::Unknown, | 41 | _ => Ty::Unknown, |
42 | }, | 42 | }, |
43 | Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => lhs_ty, | 43 | Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => lhs_ty, |
@@ -48,7 +48,9 @@ pub(super) fn binary_op_rhs_expectation(op: BinaryOp, lhs_ty: Ty) -> Ty { | |||
48 | | BinaryOp::Assignment { op: Some(_) } | 48 | | BinaryOp::Assignment { op: Some(_) } |
49 | | BinaryOp::ArithOp(_) => match lhs_ty { | 49 | | BinaryOp::ArithOp(_) => match lhs_ty { |
50 | Ty::Apply(ApplicationTy { ctor, .. }) => match ctor { | 50 | Ty::Apply(ApplicationTy { ctor, .. }) => match ctor { |
51 | TypeCtor::Int(..) | TypeCtor::Float(..) => lhs_ty, | 51 | TypeCtor::Scalar(Scalar::Int(_)) |
52 | | TypeCtor::Scalar(Scalar::Uint(_)) | ||
53 | | TypeCtor::Scalar(Scalar::Float(_)) => lhs_ty, | ||
52 | _ => Ty::Unknown, | 54 | _ => Ty::Unknown, |
53 | }, | 55 | }, |
54 | Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => lhs_ty, | 56 | Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => lhs_ty, |