Skip to content

Commit a371ac9

Browse files
committed
Fix up style review comments.
Add some comments explaining some not so obvious things. Mark code as unreachable on architectures that don't currently have scalable vectors. Remove some unused (and incorrect) checks that were being performed. Refactor some code to improve it's readability.
1 parent 351bec3 commit a371ac9

File tree

8 files changed

+30
-27
lines changed

8 files changed

+30
-27
lines changed

compiler/rustc_codegen_llvm/src/abi.rs

+4
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ impl LlvmType for Reg {
123123
_ => bug!("unsupported float: {:?}", self),
124124
},
125125
RegKind::Vector => cx.type_vector(cx.type_i8(), self.size.bytes()),
126+
// Generate a LLVM type such as <vscale x 16 x i8>, like above for a non scalable
127+
// vector. The use of 16 here is chosen as that will generate a valid type with both
128+
// Arm SVE and RISC-V RVV. In the future with other architectures this might not be
129+
// valid and might have to be configured by the target.
126130
RegKind::ScalableVector => cx.type_scalable_vector(cx.type_i8(), 16),
127131
}
128132
}

compiler/rustc_codegen_llvm/src/intrinsic.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1316,6 +1316,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
13161316
InvalidMonomorphization::MismatchedLengths { span, name, m_len, v_len }
13171317
);
13181318
match m_elem_ty.kind() {
1319+
// Arm SVE has a svbool type and we need to represent that as a bool in the type system.
13191320
ty::Int(_) | ty::Bool => {}
13201321
_ => return_error!(InvalidMonomorphization::MaskType { span, name, ty: m_elem_ty }),
13211322
}

compiler/rustc_middle/src/ty/sty.rs

+20-17
Original file line numberDiff line numberDiff line change
@@ -1964,25 +1964,28 @@ impl<'tcx> Ty<'tcx> {
19641964
let variant = def.non_enum_variant();
19651965
let f0_ty = variant.fields[FieldIdx::from_u32(0)].ty(tcx, args);
19661966

1967-
match f0_ty.kind() {
1968-
Array(_, _) if def.repr().scalable() => {
1969-
bug!("Scalable SIMD should be using a slice, not array");
1967+
if def.repr().scalable() {
1968+
match f0_ty.kind() {
1969+
Slice(f0_elem_ty) => (def.repr().scalable.unwrap_or(0) as u64, *f0_elem_ty),
1970+
_ => {
1971+
bug!("Scalable SIMD should be using a slice");
1972+
}
19701973
}
1971-
Slice(f0_elem_ty) if def.repr().scalable() => {
1972-
(def.repr().scalable.unwrap_or(0) as u64, *f0_elem_ty)
1973-
}
1974-
// If the first field is an array, we assume it is the only field and its
1975-
// elements are the SIMD components.
1976-
Array(f0_elem_ty, f0_len) => {
1977-
// FIXME(repr_simd): https://github.com/rust-lang/rust/pull/78863#discussion_r522784112
1978-
// The way we evaluate the `N` in `[T; N]` here only works since we use
1979-
// `simd_size_and_type` post-monomorphization. It will probably start to ICE
1980-
// if we use it in generic code. See the `simd-array-trait` ui test.
1981-
(f0_len.eval_target_usize(tcx, ParamEnv::empty()), *f0_elem_ty)
1974+
} else {
1975+
match f0_ty.kind() {
1976+
// If the first field is an array, we assume it is the only field and its
1977+
// elements are the SIMD components.
1978+
Array(f0_elem_ty, f0_len) => {
1979+
// FIXME(repr_simd): https://github.com/rust-lang/rust/pull/78863#discussion_r522784112
1980+
// The way we evaluate the `N` in `[T; N]` here only works since we use
1981+
// `simd_size_and_type` post-monomorphization. It will probably start to ICE
1982+
// if we use it in generic code. See the `simd-array-trait` ui test.
1983+
(f0_len.eval_target_usize(tcx, ParamEnv::empty()), *f0_elem_ty)
1984+
}
1985+
// Otherwise, the fields of this Adt are the SIMD components (and we assume they
1986+
// all have the same type).
1987+
_ => (variant.fields.len() as u64, f0_ty),
19821988
}
1983-
// Otherwise, the fields of this Adt are the SIMD components (and we assume they
1984-
// all have the same type).
1985-
_ => (variant.fields.len() as u64, f0_ty),
19861989
}
19871990
}
19881991
_ => bug!("`simd_size_and_type` called on invalid type"),

compiler/rustc_target/src/abi/call/arm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ where
1919
RegKind::Integer => false,
2020
RegKind::Float => true,
2121
RegKind::Vector => size.bits() == 64 || size.bits() == 128,
22-
RegKind::ScalableVector => true,
22+
RegKind::ScalableVector => unreachable!(),
2323
};
2424

2525
valid_unit.then_some(Uniform { unit, total: size })

compiler/rustc_target/src/abi/call/loongarch.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,10 @@ where
7676
}
7777
}
7878
},
79-
Abi::Vector { .. } | Abi::ScalableVector { .. } | Abi::Uninhabited => {
79+
Abi::Vector { .. } | Abi::Uninhabited => {
8080
return Err(CannotUseFpConv);
8181
}
82+
Abi::ScalableVector { .. } => unreachable!(),
8283
Abi::ScalarPair(..) | Abi::Aggregate { .. } => match arg_layout.fields {
8384
FieldsShape::Primitive => {
8485
unreachable!("aggregates can't have `FieldsShape::Primitive`")

compiler/rustc_target/src/abi/call/powerpc64.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ where
3535
RegKind::Integer => false,
3636
RegKind::Float => true,
3737
RegKind::Vector => arg.layout.size.bits() == 128,
38-
RegKind::ScalableVector => true,
38+
RegKind::ScalableVector => unreachable!(),
3939
};
4040

4141
valid_unit.then_some(Uniform { unit, total: arg.layout.size })

compiler/rustc_target/src/abi/call/x86_win64.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub fn compute_abi_info<Ty>(fn_abi: &mut FnAbi<'_, Ty>) {
1818
// FIXME(eddyb) there should be a size cap here
1919
// (probably what clang calls "illegal vectors").
2020
}
21-
Abi::ScalableVector { .. } => {}
21+
Abi::ScalableVector { .. } => unreachable!(),
2222
Abi::Scalar(_) => {
2323
if a.layout.size.bytes() > 8 {
2424
a.make_indirect();

compiler/rustc_ty_utils/src/layout.rs

-6
Original file line numberDiff line numberDiff line change
@@ -516,12 +516,6 @@ fn layout_of_uncached<'tcx>(
516516
return Err(error(cx, LayoutError::Unknown(ty)));
517517
}
518518

519-
if def.repr().scalable()
520-
&& variants[FIRST_VARIANT].iter().all(|field| !field.0.is_zst())
521-
{
522-
bug!("Fields for a Scalable vector should be a ZST");
523-
}
524-
525519
return Ok(tcx.mk_layout(
526520
cx.layout_of_union(&def.repr(), &variants)
527521
.ok_or_else(|| error(cx, LayoutError::Unknown(ty)))?,

0 commit comments

Comments
 (0)