Skip to content

Commit

Permalink
Inline is_machine into check_simd
Browse files Browse the repository at this point in the history
  • Loading branch information
workingjubilee committed Jun 2, 2021
1 parent d03683c commit 3d738b0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
8 changes: 0 additions & 8 deletions compiler/rustc_middle/src/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1888,14 +1888,6 @@ impl<'tcx> TyS<'tcx> {
matches!(self.kind(), Int(ty::IntTy::Isize) | Uint(ty::UintTy::Usize))
}

#[inline]
pub fn is_machine(&self) -> bool {
// Yes, RawPtr is a "machine" type for these purposes.
// LLVM uses a vector-of-pointers model for scatter/gather ops,
// which typically use a base pointer and vector of signed integers.
matches!(self.kind(), Int(..) | Uint(..) | Float(..) | RawPtr(..))
}

#[inline]
pub fn has_concrete_skeleton(&self) -> bool {
!matches!(self.kind(), Param(_) | Infer(_) | Error(_))
Expand Down
15 changes: 12 additions & 3 deletions compiler/rustc_typeck/src/check/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1214,10 +1214,19 @@ pub fn check_simd(tcx: TyCtxt<'_>, sp: Span, def_id: LocalDefId) {
}
}

// Check that we use types valid for use in the lanes of a SIMD "vector register"
// These are scalar types which directly match a "machine" type
// Yes: Integers, floats, "thin" pointers
// No: char, "fat" pointers, compound types
match e.kind() {
ty::Param(_) => { /* struct<T>(T, T, T, T) is ok */ }
_ if e.is_machine() => { /* struct(u8, u8, u8, u8) is ok */ }
ty::Array(ty, _c) if ty.is_machine() => { /* struct([f32; 4]) */ }
ty::Param(_) => (), // pass struct<T>(T, T, T, T) through, let monomorphization catch errors
ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::RawPtr(_) => (), // struct(u8, u8, u8, u8) is ok
ty::Array(t, _clen)
if matches!(
t.kind(),
ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::RawPtr(_)
) =>
{ /* struct([f32; 4]) is ok */ }
_ => {
struct_span_err!(
tcx.sess,
Expand Down

0 comments on commit 3d738b0

Please sign in to comment.