Skip to content

Commit 61d3b6d

Browse files
authored
Rollup merge of #69280 - ecstatic-morse:promote-shuffle-no-special-case, r=petrochenkov
Remove special case for `simd_shuffle` arg promotion After rust-lang/stdarch#825, these intrinsics are now defined with `#[rustc_args_required_const(2)]`, so the special-case is no longer necessary.
2 parents c6ad1e2 + b43dc80 commit 61d3b6d

9 files changed

+39
-41
lines changed

src/librustc_mir/const_eval/eval_queries.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ fn eval_body_using_ecx<'mir, 'tcx>(
7272
Ok(ret)
7373
}
7474

75-
/// The `InterpCx` is only meant to be used to do field and index projections into constants for
76-
/// `simd_shuffle` and const patterns in match arms.
75+
/// The `InterpCx` is only meant to be used to do field and index projections into promoteds
76+
/// and const patterns in match arms.
7777
///
7878
/// The function containing the `match` that is currently being analyzed may have generic bounds
7979
/// that inform us about the generic bounds of the constant. E.g., using an associated constant

src/librustc_mir/transform/promote_consts.rs

+5-19
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use rustc_span::{Span, DUMMY_SP};
2424
use syntax::ast::LitKind;
2525

2626
use rustc_index::vec::{Idx, IndexVec};
27-
use rustc_target::spec::abi::Abi;
2827

2928
use std::cell::Cell;
3029
use std::{cmp, iter, mem, usize};
@@ -106,11 +105,10 @@ pub enum Candidate {
106105
/// Promotion of the `x` in `[x; 32]`.
107106
Repeat(Location),
108107

109-
/// Currently applied to function calls where the callee has the unstable
110-
/// `#[rustc_args_required_const]` attribute as well as the SIMD shuffle
111-
/// intrinsic. The intrinsic requires the arguments are indeed constant and
112-
/// the attribute currently provides the semantic requirement that arguments
113-
/// must be constant.
108+
/// Function calls where the callee has the unstable
109+
/// `#[rustc_args_required_const]` attribute. The attribute requires that
110+
/// the arguments be constant, usually because they are encoded as an
111+
/// immediate operand in a platform intrinsic.
114112
Argument { bb: BasicBlock, index: usize },
115113
}
116114

@@ -218,17 +216,6 @@ impl<'tcx> Visitor<'tcx> for Collector<'_, 'tcx> {
218216

219217
if let TerminatorKind::Call { ref func, .. } = *kind {
220218
if let ty::FnDef(def_id, _) = func.ty(self.body, self.tcx).kind {
221-
let fn_sig = self.tcx.fn_sig(def_id);
222-
if let Abi::RustIntrinsic | Abi::PlatformIntrinsic = fn_sig.abi() {
223-
let name = self.tcx.item_name(def_id);
224-
// FIXME(eddyb) use `#[rustc_args_required_const(2)]` for shuffles.
225-
if name.as_str().starts_with("simd_shuffle") {
226-
self.candidates.push(Candidate::Argument { bb: location.block, index: 2 });
227-
228-
return; // Don't double count `simd_shuffle` candidates
229-
}
230-
}
231-
232219
if let Some(constant_args) = args_required_const(self.tcx, def_id) {
233220
for index in constant_args {
234221
self.candidates.push(Candidate::Argument { bb: location.block, index });
@@ -730,8 +717,7 @@ pub fn validate_candidates(
730717
.filter(|&candidate| {
731718
validator.explicit = candidate.forces_explicit_promotion();
732719

733-
// FIXME(eddyb) also emit the errors for shuffle indices
734-
// and `#[rustc_args_required_const]` arguments here.
720+
// FIXME(eddyb) also emit the errors for `#[rustc_args_required_const]` arguments here.
735721

736722
let is_promotable = validator.validate_candidate(candidate).is_ok();
737723
match candidate {

src/test/incremental/issue-61530.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
#![feature(repr_simd, platform_intrinsics)]
1+
#![feature(repr_simd, platform_intrinsics, rustc_attrs)]
22

33
// revisions:rpass1 rpass2
44

55
#[repr(simd)]
66
struct I32x2(i32, i32);
77

88
extern "platform-intrinsic" {
9+
#[rustc_args_required_const(2)]
910
fn simd_shuffle2<T, U>(x: T, y: T, idx: [u32; 2]) -> U;
1011
}
1112

src/test/ui/issues/issue-38074.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
// run-pass
22
// ignore-emscripten FIXME(#45351)
33

4-
#![feature(platform_intrinsics, repr_simd)]
4+
#![feature(platform_intrinsics, repr_simd, rustc_attrs)]
55

66
extern "platform-intrinsic" {
7+
#[rustc_args_required_const(2)]
78
fn simd_shuffle2<T, U>(x: T, y: T, idx: [u32; 2]) -> U;
89
}
910

src/test/ui/simd-intrinsic/simd-intrinsic-generic-elements.rs

+4
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,13 @@ extern "platform-intrinsic" {
4242
fn simd_insert<T, E>(x: T, idx: u32, y: E) -> T;
4343
fn simd_extract<T, E>(x: T, idx: u32) -> E;
4444

45+
#[rustc_args_required_const(2)]
4546
fn simd_shuffle2<T, U>(x: T, y: T, idx: [u32; 2]) -> U;
47+
#[rustc_args_required_const(2)]
4648
fn simd_shuffle3<T, U>(x: T, y: T, idx: [u32; 3]) -> U;
49+
#[rustc_args_required_const(2)]
4750
fn simd_shuffle4<T, U>(x: T, y: T, idx: [u32; 4]) -> U;
51+
#[rustc_args_required_const(2)]
4852
fn simd_shuffle8<T, U>(x: T, y: T, idx: [u32; 8]) -> U;
4953
}
5054

src/test/ui/simd-intrinsic/simd-intrinsic-generic-elements.stderr

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,89 @@
11
error[E0511]: invalid monomorphization of `simd_insert` intrinsic: expected SIMD input type, found non-SIMD `i32`
2-
--> $DIR/simd-intrinsic-generic-elements.rs:55:9
2+
--> $DIR/simd-intrinsic-generic-elements.rs:59:9
33
|
44
LL | simd_insert(0, 0, 0);
55
| ^^^^^^^^^^^^^^^^^^^^
66

77
error[E0511]: invalid monomorphization of `simd_insert` intrinsic: expected inserted type `i32` (element of input `i32x4`), found `f64`
8-
--> $DIR/simd-intrinsic-generic-elements.rs:57:9
8+
--> $DIR/simd-intrinsic-generic-elements.rs:61:9
99
|
1010
LL | simd_insert(x, 0, 1.0);
1111
| ^^^^^^^^^^^^^^^^^^^^^^
1212

1313
error[E0511]: invalid monomorphization of `simd_extract` intrinsic: expected return type `i32` (element of input `i32x4`), found `f32`
14-
--> $DIR/simd-intrinsic-generic-elements.rs:59:9
14+
--> $DIR/simd-intrinsic-generic-elements.rs:63:9
1515
|
1616
LL | simd_extract::<_, f32>(x, 0);
1717
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1818

1919
error[E0511]: invalid monomorphization of `simd_shuffle2` intrinsic: expected SIMD input type, found non-SIMD `i32`
20-
--> $DIR/simd-intrinsic-generic-elements.rs:62:9
20+
--> $DIR/simd-intrinsic-generic-elements.rs:66:9
2121
|
2222
LL | simd_shuffle2::<i32, i32>(0, 0, [0; 2]);
2323
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2424

2525
error[E0511]: invalid monomorphization of `simd_shuffle3` intrinsic: expected SIMD input type, found non-SIMD `i32`
26-
--> $DIR/simd-intrinsic-generic-elements.rs:64:9
26+
--> $DIR/simd-intrinsic-generic-elements.rs:68:9
2727
|
2828
LL | simd_shuffle3::<i32, i32>(0, 0, [0; 3]);
2929
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3030

3131
error[E0511]: invalid monomorphization of `simd_shuffle4` intrinsic: expected SIMD input type, found non-SIMD `i32`
32-
--> $DIR/simd-intrinsic-generic-elements.rs:66:9
32+
--> $DIR/simd-intrinsic-generic-elements.rs:70:9
3333
|
3434
LL | simd_shuffle4::<i32, i32>(0, 0, [0; 4]);
3535
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3636

3737
error[E0511]: invalid monomorphization of `simd_shuffle8` intrinsic: expected SIMD input type, found non-SIMD `i32`
38-
--> $DIR/simd-intrinsic-generic-elements.rs:68:9
38+
--> $DIR/simd-intrinsic-generic-elements.rs:72:9
3939
|
4040
LL | simd_shuffle8::<i32, i32>(0, 0, [0; 8]);
4141
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4242

4343
error[E0511]: invalid monomorphization of `simd_shuffle2` intrinsic: expected return element type `i32` (element of input `i32x4`), found `f32x2` with element type `f32`
44-
--> $DIR/simd-intrinsic-generic-elements.rs:71:9
44+
--> $DIR/simd-intrinsic-generic-elements.rs:75:9
4545
|
4646
LL | simd_shuffle2::<_, f32x2>(x, x, [0; 2]);
4747
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4848

4949
error[E0511]: invalid monomorphization of `simd_shuffle3` intrinsic: expected return element type `i32` (element of input `i32x4`), found `f32x3` with element type `f32`
50-
--> $DIR/simd-intrinsic-generic-elements.rs:73:9
50+
--> $DIR/simd-intrinsic-generic-elements.rs:77:9
5151
|
5252
LL | simd_shuffle3::<_, f32x3>(x, x, [0; 3]);
5353
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5454

5555
error[E0511]: invalid monomorphization of `simd_shuffle4` intrinsic: expected return element type `i32` (element of input `i32x4`), found `f32x4` with element type `f32`
56-
--> $DIR/simd-intrinsic-generic-elements.rs:75:9
56+
--> $DIR/simd-intrinsic-generic-elements.rs:79:9
5757
|
5858
LL | simd_shuffle4::<_, f32x4>(x, x, [0; 4]);
5959
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6060

6161
error[E0511]: invalid monomorphization of `simd_shuffle8` intrinsic: expected return element type `i32` (element of input `i32x4`), found `f32x8` with element type `f32`
62-
--> $DIR/simd-intrinsic-generic-elements.rs:77:9
62+
--> $DIR/simd-intrinsic-generic-elements.rs:81:9
6363
|
6464
LL | simd_shuffle8::<_, f32x8>(x, x, [0; 8]);
6565
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6666

6767
error[E0511]: invalid monomorphization of `simd_shuffle2` intrinsic: expected return type of length 2, found `i32x8` with length 8
68-
--> $DIR/simd-intrinsic-generic-elements.rs:80:9
68+
--> $DIR/simd-intrinsic-generic-elements.rs:84:9
6969
|
7070
LL | simd_shuffle2::<_, i32x8>(x, x, [0; 2]);
7171
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7272

7373
error[E0511]: invalid monomorphization of `simd_shuffle3` intrinsic: expected return type of length 3, found `i32x4` with length 4
74-
--> $DIR/simd-intrinsic-generic-elements.rs:82:9
74+
--> $DIR/simd-intrinsic-generic-elements.rs:86:9
7575
|
7676
LL | simd_shuffle3::<_, i32x4>(x, x, [0; 3]);
7777
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7878

7979
error[E0511]: invalid monomorphization of `simd_shuffle4` intrinsic: expected return type of length 4, found `i32x3` with length 3
80-
--> $DIR/simd-intrinsic-generic-elements.rs:84:9
80+
--> $DIR/simd-intrinsic-generic-elements.rs:88:9
8181
|
8282
LL | simd_shuffle4::<_, i32x3>(x, x, [0; 4]);
8383
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8484

8585
error[E0511]: invalid monomorphization of `simd_shuffle8` intrinsic: expected return type of length 8, found `i32x2` with length 2
86-
--> $DIR/simd-intrinsic-generic-elements.rs:86:9
86+
--> $DIR/simd-intrinsic-generic-elements.rs:90:9
8787
|
8888
LL | simd_shuffle8::<_, i32x2>(x, x, [0; 8]);
8989
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

src/test/ui/simd-intrinsic/simd-intrinsic-inlining-issue67557-ice.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
//
44
// run-pass
55
// compile-flags: -Zmir-opt-level=3
6-
#![feature(platform_intrinsics, repr_simd)]
6+
#![feature(platform_intrinsics, repr_simd, rustc_attrs)]
77

88
extern "platform-intrinsic" {
9+
#[rustc_args_required_const(2)]
910
fn simd_shuffle2<T, U>(x: T, y: T, idx: [u32; 2]) -> U;
1011
}
1112

src/test/ui/simd-intrinsic/simd-intrinsic-inlining-issue67557.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
//
44
// run-pass
55
// compile-flags: -Zmir-opt-level=3
6-
#![feature(platform_intrinsics, repr_simd)]
6+
#![feature(platform_intrinsics, repr_simd, rustc_attrs)]
77

88
extern "platform-intrinsic" {
9+
#[rustc_args_required_const(2)]
910
fn simd_shuffle2<T, U>(x: T, y: T, idx: [u32; 2]) -> U;
1011
}
1112

src/test/ui/simd/simd-intrinsic-generic-elements.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// run-pass
22
// ignore-emscripten FIXME(#45351) hits an LLVM assert
33

4-
#![feature(repr_simd, platform_intrinsics)]
4+
#![feature(repr_simd, platform_intrinsics, rustc_attrs)]
55

66
#[repr(simd)]
77
#[derive(Copy, Clone, Debug, PartialEq)]
@@ -25,9 +25,13 @@ extern "platform-intrinsic" {
2525
fn simd_insert<T, E>(x: T, idx: u32, y: E) -> T;
2626
fn simd_extract<T, E>(x: T, idx: u32) -> E;
2727

28+
#[rustc_args_required_const(2)]
2829
fn simd_shuffle2<T, U>(x: T, y: T, idx: [u32; 2]) -> U;
30+
#[rustc_args_required_const(2)]
2931
fn simd_shuffle3<T, U>(x: T, y: T, idx: [u32; 3]) -> U;
32+
#[rustc_args_required_const(2)]
3033
fn simd_shuffle4<T, U>(x: T, y: T, idx: [u32; 4]) -> U;
34+
#[rustc_args_required_const(2)]
3135
fn simd_shuffle8<T, U>(x: T, y: T, idx: [u32; 8]) -> U;
3236
}
3337

0 commit comments

Comments
 (0)