Skip to content

Commit e23a944

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 e237c35 commit e23a944

File tree

8 files changed

+30
-27
lines changed

8 files changed

+30
-27
lines changed

Diff for: compiler/rustc_codegen_llvm/src/abi.rs

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

Diff for: compiler/rustc_codegen_llvm/src/intrinsic.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1388,6 +1388,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
13881388
InvalidMonomorphization::MismatchedLengths { span, name, m_len, v_len }
13891389
);
13901390
match m_elem_ty.kind() {
1391+
// Arm SVE has a svbool type and we need to represent that as a bool in the type system.
13911392
ty::Int(_) | ty::Bool => {}
13921393
_ => return_error!(InvalidMonomorphization::MaskType { span, name, ty: m_elem_ty }),
13931394
}

Diff for: compiler/rustc_middle/src/ty/sty.rs

+20-17
Original file line numberDiff line numberDiff line change
@@ -1102,25 +1102,28 @@ impl<'tcx> Ty<'tcx> {
11021102
let variant = def.non_enum_variant();
11031103
let f0_ty = variant.fields[FieldIdx::ZERO].ty(tcx, args);
11041104

1105-
match f0_ty.kind() {
1106-
Array(_, _) if def.repr().scalable() => {
1107-
bug!("Scalable SIMD should be using a slice, not array");
1105+
if def.repr().scalable() {
1106+
match f0_ty.kind() {
1107+
Slice(f0_elem_ty) => (def.repr().scalable.unwrap_or(0) as u64, *f0_elem_ty),
1108+
_ => {
1109+
bug!("Scalable SIMD should be using a slice");
1110+
}
11081111
}
1109-
Slice(f0_elem_ty) if def.repr().scalable() => {
1110-
(def.repr().scalable.unwrap_or(0) as u64, *f0_elem_ty)
1111-
}
1112-
// If the first field is an array, we assume it is the only field and its
1113-
// elements are the SIMD components.
1114-
Array(f0_elem_ty, f0_len) => {
1115-
// FIXME(repr_simd): https://github.com/rust-lang/rust/pull/78863#discussion_r522784112
1116-
// The way we evaluate the `N` in `[T; N]` here only works since we use
1117-
// `simd_size_and_type` post-monomorphization. It will probably start to ICE
1118-
// if we use it in generic code. See the `simd-array-trait` ui test.
1119-
(f0_len.eval_target_usize(tcx, ParamEnv::empty()), *f0_elem_ty)
1112+
} else {
1113+
match f0_ty.kind() {
1114+
// If the first field is an array, we assume it is the only field and its
1115+
// elements are the SIMD components.
1116+
Array(f0_elem_ty, f0_len) => {
1117+
// FIXME(repr_simd): https://github.com/rust-lang/rust/pull/78863#discussion_r522784112
1118+
// The way we evaluate the `N` in `[T; N]` here only works since we use
1119+
// `simd_size_and_type` post-monomorphization. It will probably start to ICE
1120+
// if we use it in generic code. See the `simd-array-trait` ui test.
1121+
(f0_len.eval_target_usize(tcx, ParamEnv::empty()), *f0_elem_ty)
1122+
}
1123+
// Otherwise, the fields of this Adt are the SIMD components (and we assume they
1124+
// all have the same type).
1125+
_ => (variant.fields.len() as u64, f0_ty),
11201126
}
1121-
// Otherwise, the fields of this Adt are the SIMD components (and we assume they
1122-
// all have the same type).
1123-
_ => (variant.fields.len() as u64, f0_ty),
11241127
}
11251128
}
11261129
_ => bug!("`simd_size_and_type` called on invalid type"),

Diff for: 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::consecutive(unit, size))

Diff for: 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`")

Diff for: 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::consecutive(unit, arg.layout.size))

Diff for: 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();

Diff for: compiler/rustc_ty_utils/src/layout.rs

-6
Original file line numberDiff line numberDiff line change
@@ -553,12 +553,6 @@ fn layout_of_uncached<'tcx>(
553553
return Err(error(cx, LayoutError::Unknown(ty)));
554554
}
555555

556-
if def.repr().scalable()
557-
&& variants[FIRST_VARIANT].iter().all(|field| !field.0.is_zst())
558-
{
559-
bug!("Fields for a Scalable vector should be a ZST");
560-
}
561-
562556
return Ok(tcx.mk_layout(
563557
cx.layout_of_union(&def.repr(), &variants)
564558
.ok_or_else(|| error(cx, LayoutError::Unknown(ty)))?,

0 commit comments

Comments
 (0)