about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCelina G. Val <celinval@amazon.com>2023-12-11 19:02:54 -0800
committerCelina G. Val <celinval@amazon.com>2023-12-11 19:02:54 -0800
commit638b08ebdfde428a54efce2fd896da8d3332f403 (patch)
tree7a94d568dca820a553fcb8c9108aafd66cae763d
parent3b97b5130ab360f525209b1c5f973a9aa1c6dc97 (diff)
downloadrust-638b08ebdfde428a54efce2fd896da8d3332f403.tar.gz
rust-638b08ebdfde428a54efce2fd896da8d3332f403.zip
Remove scalar fn and tighten the BiOp Ty assertions
-rw-r--r--compiler/stable_mir/src/mir/body.rs16
-rw-r--r--compiler/stable_mir/src/ty.rs20
2 files changed, 12 insertions, 24 deletions
diff --git a/compiler/stable_mir/src/mir/body.rs b/compiler/stable_mir/src/mir/body.rs
index 883baeb9f71..3dfe7096399 100644
--- a/compiler/stable_mir/src/mir/body.rs
+++ b/compiler/stable_mir/src/mir/body.rs
@@ -278,10 +278,6 @@ impl BinOp {
     /// Return the type of this operation for the given input Ty.
     /// This function does not perform type checking, and it currently doesn't handle SIMD.
     pub fn ty(&self, lhs_ty: Ty, rhs_ty: Ty) -> Ty {
-        let lhs_kind = lhs_ty.kind();
-        let rhs_kind = rhs_ty.kind();
-        assert!(lhs_kind.is_primitive() || lhs_kind.is_any_ptr());
-        assert!(rhs_kind.is_primitive() || rhs_kind.is_any_ptr());
         match self {
             BinOp::Add
             | BinOp::AddUnchecked
@@ -295,13 +291,23 @@ impl BinOp {
             | BinOp::BitAnd
             | BinOp::BitOr => {
                 assert_eq!(lhs_ty, rhs_ty);
+                assert!(lhs_ty.kind().is_primitive());
                 lhs_ty
             }
-            BinOp::Shl | BinOp::ShlUnchecked | BinOp::Shr | BinOp::ShrUnchecked | BinOp::Offset => {
+            BinOp::Shl | BinOp::ShlUnchecked | BinOp::Shr | BinOp::ShrUnchecked => {
+                assert!(lhs_ty.kind().is_primitive());
+                assert!(rhs_ty.kind().is_primitive());
+                lhs_ty
+            }
+            BinOp::Offset => {
+                assert!(lhs_ty.kind().is_raw_ptr());
+                assert!(rhs_ty.kind().is_integral());
                 lhs_ty
             }
             BinOp::Eq | BinOp::Lt | BinOp::Le | BinOp::Ne | BinOp::Ge | BinOp::Gt => {
                 assert_eq!(lhs_ty, rhs_ty);
+                let lhs_kind = lhs_ty.kind();
+                assert!(lhs_kind.is_primitive() || lhs_kind.is_raw_ptr() || lhs_kind.is_fn_ptr());
                 Ty::bool_ty()
             }
         }
diff --git a/compiler/stable_mir/src/ty.rs b/compiler/stable_mir/src/ty.rs
index 6734ecb2f9b..f473fd8dbb7 100644
--- a/compiler/stable_mir/src/ty.rs
+++ b/compiler/stable_mir/src/ty.rs
@@ -283,24 +283,6 @@ impl TyKind {
         )
     }
 
-    /// A scalar type is one that denotes an atomic datum, with no sub-components.
-    /// (A RawPtr is scalar because it represents a non-managed pointer, so its
-    /// contents are abstract to rustc.)
-    #[inline]
-    pub fn is_scalar(&self) -> bool {
-        matches!(
-            self,
-            TyKind::RigidTy(RigidTy::Bool)
-                | TyKind::RigidTy(RigidTy::Char)
-                | TyKind::RigidTy(RigidTy::Int(_))
-                | TyKind::RigidTy(RigidTy::Float(_))
-                | TyKind::RigidTy(RigidTy::Uint(_))
-                | TyKind::RigidTy(RigidTy::FnDef(..))
-                | TyKind::RigidTy(RigidTy::FnPtr(_))
-                | TyKind::RigidTy(RigidTy::RawPtr(..))
-        )
-    }
-
     #[inline]
     pub fn is_float(&self) -> bool {
         matches!(self, TyKind::RigidTy(RigidTy::Float(_)))
@@ -871,7 +853,7 @@ pub struct Binder<T> {
 
 impl<T> Binder<T> {
     /// Create a new binder with the given bound vars.
-    pub fn new(value: T, bound_vars: Vec<BoundVariableKind>) -> Self {
+    pub fn bind_with_vars(value: T, bound_vars: Vec<BoundVariableKind>) -> Self {
         Binder { value, bound_vars }
     }