Skip to content

Commit 5c786a7

Browse files
committed
Auto merge of rust-lang#121516 - RalfJung:platform-intrinsics-begone, r=oli-obk
remove platform-intrinsics ABI; make SIMD intrinsics be regular intrinsics `@Amanieu` `@workingjubilee` I don't think there is any reason these need to be "special"? The [original RFC](https://rust-lang.github.io/rfcs/1199-simd-infrastructure.html) indicated eventually making them stable, but I think that is no longer the plan, so seems to me like we can clean this up a bit. Blocked on rust-lang/stdarch#1538, rust-lang#121542.
2 parents fc3800f + c1d0e48 commit 5c786a7

File tree

114 files changed

+413
-445
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+413
-445
lines changed

compiler/rustc_codegen_cranelift/example/float-minmax-pass.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,14 @@
44

55
// Test that the simd_f{min,max} intrinsics produce the correct results.
66

7-
#![feature(repr_simd, platform_intrinsics)]
7+
#![feature(repr_simd, core_intrinsics)]
88
#![allow(non_camel_case_types)]
99

1010
#[repr(simd)]
1111
#[derive(Copy, Clone, PartialEq, Debug)]
1212
struct f32x4(pub f32, pub f32, pub f32, pub f32);
1313

14-
extern "platform-intrinsic" {
15-
fn simd_fmin<T>(x: T, y: T) -> T;
16-
fn simd_fmax<T>(x: T, y: T) -> T;
17-
}
14+
use std::intrinsics::simd::*;
1815

1916
fn main() {
2017
let x = f32x4(1.0, 2.0, 3.0, 4.0);

compiler/rustc_error_codes/src/error_codes/E0511.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ Invalid monomorphization of an intrinsic function was used.
33
Erroneous code example:
44

55
```compile_fail,E0511
6-
#![feature(platform_intrinsics)]
6+
#![feature(intrinsics)]
77
8-
extern "platform-intrinsic" {
8+
extern "rust-intrinsic" {
99
fn simd_add<T>(a: T, b: T) -> T;
1010
}
1111
@@ -19,13 +19,13 @@ The generic type has to be a SIMD type. Example:
1919

2020
```
2121
#![feature(repr_simd)]
22-
#![feature(platform_intrinsics)]
22+
#![feature(intrinsics)]
2323
2424
#[repr(simd)]
2525
#[derive(Copy, Clone)]
2626
struct i32x2(i32, i32);
2727
28-
extern "platform-intrinsic" {
28+
extern "rust-intrinsic" {
2929
fn simd_add<T>(a: T, b: T) -> T;
3030
}
3131

compiler/rustc_feature/src/removed.rs

+3
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ declare_features! (
156156
Some("removed in favor of `#![feature(marker_trait_attr)]`")),
157157
(removed, panic_implementation, "1.28.0", Some(44489),
158158
Some("subsumed by `#[panic_handler]`")),
159+
/// Allows `extern "platform-intrinsic" { ... }`.
160+
(removed, platform_intrinsics, "1.4.0", Some(27731),
161+
Some("SIMD intrinsics use the regular intrinsics ABI now")),
159162
/// Allows using `#![plugin(myplugin)]`.
160163
(removed, plugin, "1.75.0", Some(29597),
161164
Some("plugins are no longer supported")),

compiler/rustc_feature/src/unstable.rs

-2
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,6 @@ declare_features! (
259259
(internal, needs_panic_runtime, "1.10.0", Some(32837)),
260260
/// Allows using the `#![panic_runtime]` attribute.
261261
(internal, panic_runtime, "1.10.0", Some(32837)),
262-
/// Allows `extern "platform-intrinsic" { ... }`.
263-
(internal, platform_intrinsics, "1.4.0", Some(27731)),
264262
/// Allows using `#[rustc_allow_const_fn_unstable]`.
265263
/// This is an attribute on `const fn` for the same
266264
/// purpose as `#[allow_internal_unstable]`.

compiler/rustc_hir_analysis/src/check/check.rs

-11
Original file line numberDiff line numberDiff line change
@@ -612,17 +612,6 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
612612
}
613613
}
614614

615-
Abi::PlatformIntrinsic => {
616-
for item in items {
617-
intrinsic::check_platform_intrinsic_type(
618-
tcx,
619-
item.id.owner_id.def_id,
620-
item.span,
621-
item.ident.name,
622-
);
623-
}
624-
}
625-
626615
_ => {
627616
for item in items {
628617
let def_id = item.id.owner_id.def_id;

compiler/rustc_hir_analysis/src/check/intrinsic.rs

+71-99
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,77 @@ pub fn check_intrinsic_type(
510510

511511
sym::debug_assertions => (0, 1, Vec::new(), tcx.types.bool),
512512

513+
sym::simd_eq
514+
| sym::simd_ne
515+
| sym::simd_lt
516+
| sym::simd_le
517+
| sym::simd_gt
518+
| sym::simd_ge => (2, 0, vec![param(0), param(0)], param(1)),
519+
sym::simd_add
520+
| sym::simd_sub
521+
| sym::simd_mul
522+
| sym::simd_rem
523+
| sym::simd_div
524+
| sym::simd_shl
525+
| sym::simd_shr
526+
| sym::simd_and
527+
| sym::simd_or
528+
| sym::simd_xor
529+
| sym::simd_fmin
530+
| sym::simd_fmax
531+
| sym::simd_fpow
532+
| sym::simd_saturating_add
533+
| sym::simd_saturating_sub => (1, 0, vec![param(0), param(0)], param(0)),
534+
sym::simd_arith_offset => (2, 0, vec![param(0), param(1)], param(0)),
535+
sym::simd_neg
536+
| sym::simd_bswap
537+
| sym::simd_bitreverse
538+
| sym::simd_ctlz
539+
| sym::simd_cttz
540+
| sym::simd_fsqrt
541+
| sym::simd_fsin
542+
| sym::simd_fcos
543+
| sym::simd_fexp
544+
| sym::simd_fexp2
545+
| sym::simd_flog2
546+
| sym::simd_flog10
547+
| sym::simd_flog
548+
| sym::simd_fabs
549+
| sym::simd_ceil
550+
| sym::simd_floor
551+
| sym::simd_round
552+
| sym::simd_trunc => (1, 0, vec![param(0)], param(0)),
553+
sym::simd_fpowi => (1, 0, vec![param(0), tcx.types.i32], param(0)),
554+
sym::simd_fma => (1, 0, vec![param(0), param(0), param(0)], param(0)),
555+
sym::simd_gather => (3, 0, vec![param(0), param(1), param(2)], param(0)),
556+
sym::simd_masked_load => (3, 0, vec![param(0), param(1), param(2)], param(2)),
557+
sym::simd_masked_store => (3, 0, vec![param(0), param(1), param(2)], Ty::new_unit(tcx)),
558+
sym::simd_scatter => (3, 0, vec![param(0), param(1), param(2)], Ty::new_unit(tcx)),
559+
sym::simd_insert => (2, 0, vec![param(0), tcx.types.u32, param(1)], param(0)),
560+
sym::simd_extract => (2, 0, vec![param(0), tcx.types.u32], param(1)),
561+
sym::simd_cast
562+
| sym::simd_as
563+
| sym::simd_cast_ptr
564+
| sym::simd_expose_addr
565+
| sym::simd_from_exposed_addr => (2, 0, vec![param(0)], param(1)),
566+
sym::simd_bitmask => (2, 0, vec![param(0)], param(1)),
567+
sym::simd_select | sym::simd_select_bitmask => {
568+
(2, 0, vec![param(0), param(1), param(1)], param(1))
569+
}
570+
sym::simd_reduce_all | sym::simd_reduce_any => (1, 0, vec![param(0)], tcx.types.bool),
571+
sym::simd_reduce_add_ordered | sym::simd_reduce_mul_ordered => {
572+
(2, 0, vec![param(0), param(1)], param(1))
573+
}
574+
sym::simd_reduce_add_unordered
575+
| sym::simd_reduce_mul_unordered
576+
| sym::simd_reduce_and
577+
| sym::simd_reduce_or
578+
| sym::simd_reduce_xor
579+
| sym::simd_reduce_min
580+
| sym::simd_reduce_max => (2, 0, vec![param(0)], param(1)),
581+
sym::simd_shuffle => (3, 0, vec![param(0), param(0), param(1)], param(2)),
582+
sym::simd_shuffle_generic => (2, 1, vec![param(0), param(0)], param(1)),
583+
513584
other => {
514585
tcx.dcx().emit_err(UnrecognizedIntrinsicFunction { span, name: other });
515586
return;
@@ -521,102 +592,3 @@ pub fn check_intrinsic_type(
521592
let sig = ty::Binder::bind_with_vars(sig, bound_vars);
522593
equate_intrinsic_type(tcx, span, intrinsic_id, n_tps, n_lts, n_cts, sig)
523594
}
524-
525-
/// Type-check `extern "platform-intrinsic" { ... }` functions.
526-
pub fn check_platform_intrinsic_type(
527-
tcx: TyCtxt<'_>,
528-
intrinsic_id: LocalDefId,
529-
span: Span,
530-
name: Symbol,
531-
) {
532-
let generics = tcx.generics_of(intrinsic_id);
533-
let param = |n| {
534-
if let Some(&ty::GenericParamDef {
535-
name, kind: ty::GenericParamDefKind::Type { .. }, ..
536-
}) = generics.opt_param_at(n as usize, tcx)
537-
{
538-
Ty::new_param(tcx, n, name)
539-
} else {
540-
Ty::new_error_with_message(tcx, span, "expected param")
541-
}
542-
};
543-
544-
let (n_tps, n_cts, inputs, output) = match name {
545-
sym::simd_eq | sym::simd_ne | sym::simd_lt | sym::simd_le | sym::simd_gt | sym::simd_ge => {
546-
(2, 0, vec![param(0), param(0)], param(1))
547-
}
548-
sym::simd_add
549-
| sym::simd_sub
550-
| sym::simd_mul
551-
| sym::simd_rem
552-
| sym::simd_div
553-
| sym::simd_shl
554-
| sym::simd_shr
555-
| sym::simd_and
556-
| sym::simd_or
557-
| sym::simd_xor
558-
| sym::simd_fmin
559-
| sym::simd_fmax
560-
| sym::simd_fpow
561-
| sym::simd_saturating_add
562-
| sym::simd_saturating_sub => (1, 0, vec![param(0), param(0)], param(0)),
563-
sym::simd_arith_offset => (2, 0, vec![param(0), param(1)], param(0)),
564-
sym::simd_neg
565-
| sym::simd_bswap
566-
| sym::simd_bitreverse
567-
| sym::simd_ctlz
568-
| sym::simd_cttz
569-
| sym::simd_fsqrt
570-
| sym::simd_fsin
571-
| sym::simd_fcos
572-
| sym::simd_fexp
573-
| sym::simd_fexp2
574-
| sym::simd_flog2
575-
| sym::simd_flog10
576-
| sym::simd_flog
577-
| sym::simd_fabs
578-
| sym::simd_ceil
579-
| sym::simd_floor
580-
| sym::simd_round
581-
| sym::simd_trunc => (1, 0, vec![param(0)], param(0)),
582-
sym::simd_fpowi => (1, 0, vec![param(0), tcx.types.i32], param(0)),
583-
sym::simd_fma => (1, 0, vec![param(0), param(0), param(0)], param(0)),
584-
sym::simd_gather => (3, 0, vec![param(0), param(1), param(2)], param(0)),
585-
sym::simd_masked_load => (3, 0, vec![param(0), param(1), param(2)], param(2)),
586-
sym::simd_masked_store => (3, 0, vec![param(0), param(1), param(2)], Ty::new_unit(tcx)),
587-
sym::simd_scatter => (3, 0, vec![param(0), param(1), param(2)], Ty::new_unit(tcx)),
588-
sym::simd_insert => (2, 0, vec![param(0), tcx.types.u32, param(1)], param(0)),
589-
sym::simd_extract => (2, 0, vec![param(0), tcx.types.u32], param(1)),
590-
sym::simd_cast
591-
| sym::simd_as
592-
| sym::simd_cast_ptr
593-
| sym::simd_expose_addr
594-
| sym::simd_from_exposed_addr => (2, 0, vec![param(0)], param(1)),
595-
sym::simd_bitmask => (2, 0, vec![param(0)], param(1)),
596-
sym::simd_select | sym::simd_select_bitmask => {
597-
(2, 0, vec![param(0), param(1), param(1)], param(1))
598-
}
599-
sym::simd_reduce_all | sym::simd_reduce_any => (1, 0, vec![param(0)], tcx.types.bool),
600-
sym::simd_reduce_add_ordered | sym::simd_reduce_mul_ordered => {
601-
(2, 0, vec![param(0), param(1)], param(1))
602-
}
603-
sym::simd_reduce_add_unordered
604-
| sym::simd_reduce_mul_unordered
605-
| sym::simd_reduce_and
606-
| sym::simd_reduce_or
607-
| sym::simd_reduce_xor
608-
| sym::simd_reduce_min
609-
| sym::simd_reduce_max => (2, 0, vec![param(0)], param(1)),
610-
sym::simd_shuffle => (3, 0, vec![param(0), param(0), param(1)], param(2)),
611-
sym::simd_shuffle_generic => (2, 1, vec![param(0), param(0)], param(1)),
612-
_ => {
613-
let msg = format!("unrecognized platform-specific intrinsic function: `{name}`");
614-
tcx.dcx().span_err(span, msg);
615-
return;
616-
}
617-
};
618-
619-
let sig = tcx.mk_fn_sig(inputs, output, false, hir::Unsafety::Unsafe, Abi::PlatformIntrinsic);
620-
let sig = ty::Binder::dummy(sig);
621-
equate_intrinsic_type(tcx, span, intrinsic_id, n_tps, 0, n_cts, sig)
622-
}

compiler/rustc_hir_analysis/src/check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ fn get_owner_return_paths(
142142
/// as they must always be defined by the compiler.
143143
// FIXME: Move this to a more appropriate place.
144144
pub fn forbid_intrinsic_abi(tcx: TyCtxt<'_>, sp: Span, abi: Abi) {
145-
if let Abi::RustIntrinsic | Abi::PlatformIntrinsic = abi {
145+
if let Abi::RustIntrinsic = abi {
146146
tcx.dcx().span_err(sp, "intrinsic must be in `extern \"rust-intrinsic\" { ... }` block");
147147
}
148148
}

compiler/rustc_hir_analysis/src/collect.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1677,10 +1677,7 @@ fn compute_sig_of_foreign_fn_decl<'tcx>(
16771677

16781678
// Feature gate SIMD types in FFI, since I am not sure that the
16791679
// ABIs are handled at all correctly. -huonw
1680-
if abi != abi::Abi::RustIntrinsic
1681-
&& abi != abi::Abi::PlatformIntrinsic
1682-
&& !tcx.features().simd_ffi
1683-
{
1680+
if abi != abi::Abi::RustIntrinsic && !tcx.features().simd_ffi {
16841681
let check = |ast_ty: &hir::Ty<'_>, ty: Ty<'_>| {
16851682
if ty.is_simd() {
16861683
let snip = tcx

compiler/rustc_hir_typeck/src/coercion.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -1177,11 +1177,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11771177
};
11781178
if let (Some(a_sig), Some(b_sig)) = (a_sig, b_sig) {
11791179
// Intrinsics are not coercible to function pointers.
1180-
if a_sig.abi() == Abi::RustIntrinsic
1181-
|| a_sig.abi() == Abi::PlatformIntrinsic
1182-
|| b_sig.abi() == Abi::RustIntrinsic
1183-
|| b_sig.abi() == Abi::PlatformIntrinsic
1184-
{
1180+
if a_sig.abi() == Abi::RustIntrinsic || b_sig.abi() == Abi::RustIntrinsic {
11851181
return Err(TypeError::IntrinsicCast);
11861182
}
11871183
// The signature must match.

compiler/rustc_lint/src/types.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1587,10 +1587,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
15871587
}
15881588

15891589
fn is_internal_abi(&self, abi: SpecAbi) -> bool {
1590-
matches!(
1591-
abi,
1592-
SpecAbi::Rust | SpecAbi::RustCall | SpecAbi::RustIntrinsic | SpecAbi::PlatformIntrinsic
1593-
)
1590+
matches!(abi, SpecAbi::Rust | SpecAbi::RustCall | SpecAbi::RustIntrinsic)
15941591
}
15951592

15961593
/// Find any fn-ptr types with external ABIs in `ty`.

compiler/rustc_metadata/src/native_libs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl<'tcx> Collector<'tcx> {
9999

100100
let sess = self.tcx.sess;
101101

102-
if matches!(abi, Abi::Rust | Abi::RustIntrinsic | Abi::PlatformIntrinsic) {
102+
if matches!(abi, Abi::Rust | Abi::RustIntrinsic) {
103103
return;
104104
}
105105

compiler/rustc_middle/src/ty/layout.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1244,7 +1244,6 @@ pub fn fn_can_unwind(tcx: TyCtxt<'_>, fn_def_id: Option<DefId>, abi: SpecAbi) ->
12441244
| RiscvInterruptS
12451245
| CCmseNonSecureCall
12461246
| Wasm
1247-
| PlatformIntrinsic
12481247
| Unadjusted => false,
12491248
Rust | RustCall | RustCold | RustIntrinsic => {
12501249
tcx.sess.panic_strategy() == PanicStrategy::Unwind

compiler/rustc_middle/src/ty/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1643,7 +1643,7 @@ pub fn is_doc_notable_trait(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
16431643

16441644
/// Determines whether an item is an intrinsic by Abi. or by whether it has a `rustc_intrinsic` attribute
16451645
pub fn intrinsic(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<Symbol> {
1646-
if matches!(tcx.fn_sig(def_id).skip_binder().abi(), Abi::RustIntrinsic | Abi::PlatformIntrinsic)
1646+
if matches!(tcx.fn_sig(def_id).skip_binder().abi(), Abi::RustIntrinsic)
16471647
|| tcx.has_attr(def_id, sym::rustc_intrinsic)
16481648
{
16491649
Some(tcx.item_name(def_id.into()))

compiler/rustc_mir_transform/src/ffi_unwind_calls.rs

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ fn abi_can_unwind(abi: Abi) -> bool {
3434
| CCmseNonSecureCall
3535
| Wasm
3636
| RustIntrinsic
37-
| PlatformIntrinsic
3837
| Unadjusted => false,
3938
Rust | RustCall | RustCold => true,
4039
}

compiler/rustc_passes/src/check_attr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1389,7 +1389,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
13891389
if target == Target::ForeignMod
13901390
&& let hir::Node::Item(item) = self.tcx.hir_node(hir_id)
13911391
&& let Item { kind: ItemKind::ForeignMod { abi, .. }, .. } = item
1392-
&& !matches!(abi, Abi::Rust | Abi::RustIntrinsic | Abi::PlatformIntrinsic)
1392+
&& !matches!(abi, Abi::Rust | Abi::RustIntrinsic)
13931393
{
13941394
return;
13951395
}
@@ -2071,7 +2071,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
20712071
) -> bool {
20722072
if let Target::ForeignFn = target
20732073
&& let hir::Node::Item(Item {
2074-
kind: ItemKind::ForeignMod { abi: Abi::RustIntrinsic | Abi::PlatformIntrinsic, .. },
2074+
kind: ItemKind::ForeignMod { abi: Abi::RustIntrinsic, .. },
20752075
..
20762076
}) = self.tcx.parent_hir_node(hir_id)
20772077
{

compiler/rustc_passes/src/stability.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
173173
// If the current node is a function, has const stability attributes and if it doesn not have an intrinsic ABI,
174174
// check if the function/method is const or the parent impl block is const
175175
if let (Some(const_span), Some(fn_sig)) = (const_span, fn_sig) {
176-
if fn_sig.header.abi != Abi::RustIntrinsic
177-
&& fn_sig.header.abi != Abi::PlatformIntrinsic
178-
&& !fn_sig.header.is_const()
179-
{
176+
if fn_sig.header.abi != Abi::RustIntrinsic && !fn_sig.header.is_const() {
180177
if !self.in_trait_impl
181178
|| (self.in_trait_impl && !self.tcx.is_const_fn_raw(def_id.to_def_id()))
182179
{

compiler/rustc_smir/src/rustc_internal/internal.rs

-1
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,6 @@ impl RustcInternal for Abi {
457457
Abi::System { unwind } => rustc_target::spec::abi::Abi::System { unwind },
458458
Abi::RustIntrinsic => rustc_target::spec::abi::Abi::RustIntrinsic,
459459
Abi::RustCall => rustc_target::spec::abi::Abi::RustCall,
460-
Abi::PlatformIntrinsic => rustc_target::spec::abi::Abi::PlatformIntrinsic,
461460
Abi::Unadjusted => rustc_target::spec::abi::Abi::Unadjusted,
462461
Abi::RustCold => rustc_target::spec::abi::Abi::RustCold,
463462
Abi::RiscvInterruptM => rustc_target::spec::abi::Abi::RiscvInterruptM,

compiler/rustc_smir/src/rustc_smir/convert/ty.rs

-1
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,6 @@ impl<'tcx> Stable<'tcx> for rustc_target::spec::abi::Abi {
833833
abi::Abi::System { unwind } => Abi::System { unwind },
834834
abi::Abi::RustIntrinsic => Abi::RustIntrinsic,
835835
abi::Abi::RustCall => Abi::RustCall,
836-
abi::Abi::PlatformIntrinsic => Abi::PlatformIntrinsic,
837836
abi::Abi::Unadjusted => Abi::Unadjusted,
838837
abi::Abi::RustCold => Abi::RustCold,
839838
abi::Abi::RiscvInterruptM => Abi::RiscvInterruptM,

0 commit comments

Comments
 (0)