Skip to content

Commit 638b08e

Browse files
committed
Remove scalar fn and tighten the BiOp Ty assertions
1 parent 3b97b51 commit 638b08e

File tree

2 files changed

+12
-24
lines changed

2 files changed

+12
-24
lines changed

compiler/stable_mir/src/mir/body.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,6 @@ impl BinOp {
278278
/// Return the type of this operation for the given input Ty.
279279
/// This function does not perform type checking, and it currently doesn't handle SIMD.
280280
pub fn ty(&self, lhs_ty: Ty, rhs_ty: Ty) -> Ty {
281-
let lhs_kind = lhs_ty.kind();
282-
let rhs_kind = rhs_ty.kind();
283-
assert!(lhs_kind.is_primitive() || lhs_kind.is_any_ptr());
284-
assert!(rhs_kind.is_primitive() || rhs_kind.is_any_ptr());
285281
match self {
286282
BinOp::Add
287283
| BinOp::AddUnchecked
@@ -295,13 +291,23 @@ impl BinOp {
295291
| BinOp::BitAnd
296292
| BinOp::BitOr => {
297293
assert_eq!(lhs_ty, rhs_ty);
294+
assert!(lhs_ty.kind().is_primitive());
298295
lhs_ty
299296
}
300-
BinOp::Shl | BinOp::ShlUnchecked | BinOp::Shr | BinOp::ShrUnchecked | BinOp::Offset => {
297+
BinOp::Shl | BinOp::ShlUnchecked | BinOp::Shr | BinOp::ShrUnchecked => {
298+
assert!(lhs_ty.kind().is_primitive());
299+
assert!(rhs_ty.kind().is_primitive());
300+
lhs_ty
301+
}
302+
BinOp::Offset => {
303+
assert!(lhs_ty.kind().is_raw_ptr());
304+
assert!(rhs_ty.kind().is_integral());
301305
lhs_ty
302306
}
303307
BinOp::Eq | BinOp::Lt | BinOp::Le | BinOp::Ne | BinOp::Ge | BinOp::Gt => {
304308
assert_eq!(lhs_ty, rhs_ty);
309+
let lhs_kind = lhs_ty.kind();
310+
assert!(lhs_kind.is_primitive() || lhs_kind.is_raw_ptr() || lhs_kind.is_fn_ptr());
305311
Ty::bool_ty()
306312
}
307313
}

compiler/stable_mir/src/ty.rs

+1-19
Original file line numberDiff line numberDiff line change
@@ -283,24 +283,6 @@ impl TyKind {
283283
)
284284
}
285285

286-
/// A scalar type is one that denotes an atomic datum, with no sub-components.
287-
/// (A RawPtr is scalar because it represents a non-managed pointer, so its
288-
/// contents are abstract to rustc.)
289-
#[inline]
290-
pub fn is_scalar(&self) -> bool {
291-
matches!(
292-
self,
293-
TyKind::RigidTy(RigidTy::Bool)
294-
| TyKind::RigidTy(RigidTy::Char)
295-
| TyKind::RigidTy(RigidTy::Int(_))
296-
| TyKind::RigidTy(RigidTy::Float(_))
297-
| TyKind::RigidTy(RigidTy::Uint(_))
298-
| TyKind::RigidTy(RigidTy::FnDef(..))
299-
| TyKind::RigidTy(RigidTy::FnPtr(_))
300-
| TyKind::RigidTy(RigidTy::RawPtr(..))
301-
)
302-
}
303-
304286
#[inline]
305287
pub fn is_float(&self) -> bool {
306288
matches!(self, TyKind::RigidTy(RigidTy::Float(_)))
@@ -871,7 +853,7 @@ pub struct Binder<T> {
871853

872854
impl<T> Binder<T> {
873855
/// Create a new binder with the given bound vars.
874-
pub fn new(value: T, bound_vars: Vec<BoundVariableKind>) -> Self {
856+
pub fn bind_with_vars(value: T, bound_vars: Vec<BoundVariableKind>) -> Self {
875857
Binder { value, bound_vars }
876858
}
877859

0 commit comments

Comments
 (0)