Skip to content

Commit

Permalink
Auto merge of #121516 - RalfJung:platform-intrinsics-begone, r=oli-obk
Browse files Browse the repository at this point in the history
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, #121542.
  • Loading branch information
bors committed Feb 26, 2024
2 parents fc3800f + c1d0e48 commit 5c786a7
Show file tree
Hide file tree
Showing 114 changed files with 413 additions and 445 deletions.
7 changes: 2 additions & 5 deletions compiler/rustc_codegen_cranelift/example/float-minmax-pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@

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

#![feature(repr_simd, platform_intrinsics)]
#![feature(repr_simd, core_intrinsics)]
#![allow(non_camel_case_types)]

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

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

fn main() {
let x = f32x4(1.0, 2.0, 3.0, 4.0);
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_error_codes/src/error_codes/E0511.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ Invalid monomorphization of an intrinsic function was used.
Erroneous code example:

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

```
#![feature(repr_simd)]
#![feature(platform_intrinsics)]
#![feature(intrinsics)]
#[repr(simd)]
#[derive(Copy, Clone)]
struct i32x2(i32, i32);
extern "platform-intrinsic" {
extern "rust-intrinsic" {
fn simd_add<T>(a: T, b: T) -> T;
}
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_feature/src/removed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ declare_features! (
Some("removed in favor of `#![feature(marker_trait_attr)]`")),
(removed, panic_implementation, "1.28.0", Some(44489),
Some("subsumed by `#[panic_handler]`")),
/// Allows `extern "platform-intrinsic" { ... }`.
(removed, platform_intrinsics, "1.4.0", Some(27731),
Some("SIMD intrinsics use the regular intrinsics ABI now")),
/// Allows using `#![plugin(myplugin)]`.
(removed, plugin, "1.75.0", Some(29597),
Some("plugins are no longer supported")),
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,6 @@ declare_features! (
(internal, needs_panic_runtime, "1.10.0", Some(32837)),
/// Allows using the `#![panic_runtime]` attribute.
(internal, panic_runtime, "1.10.0", Some(32837)),
/// Allows `extern "platform-intrinsic" { ... }`.
(internal, platform_intrinsics, "1.4.0", Some(27731)),
/// Allows using `#[rustc_allow_const_fn_unstable]`.
/// This is an attribute on `const fn` for the same
/// purpose as `#[allow_internal_unstable]`.
Expand Down
11 changes: 0 additions & 11 deletions compiler/rustc_hir_analysis/src/check/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,17 +612,6 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
}
}

Abi::PlatformIntrinsic => {
for item in items {
intrinsic::check_platform_intrinsic_type(
tcx,
item.id.owner_id.def_id,
item.span,
item.ident.name,
);
}
}

_ => {
for item in items {
let def_id = item.id.owner_id.def_id;
Expand Down
170 changes: 71 additions & 99 deletions compiler/rustc_hir_analysis/src/check/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,77 @@ pub fn check_intrinsic_type(

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

sym::simd_eq
| sym::simd_ne
| sym::simd_lt
| sym::simd_le
| sym::simd_gt
| sym::simd_ge => (2, 0, vec![param(0), param(0)], param(1)),
sym::simd_add
| sym::simd_sub
| sym::simd_mul
| sym::simd_rem
| sym::simd_div
| sym::simd_shl
| sym::simd_shr
| sym::simd_and
| sym::simd_or
| sym::simd_xor
| sym::simd_fmin
| sym::simd_fmax
| sym::simd_fpow
| sym::simd_saturating_add
| sym::simd_saturating_sub => (1, 0, vec![param(0), param(0)], param(0)),
sym::simd_arith_offset => (2, 0, vec![param(0), param(1)], param(0)),
sym::simd_neg
| sym::simd_bswap
| sym::simd_bitreverse
| sym::simd_ctlz
| sym::simd_cttz
| sym::simd_fsqrt
| sym::simd_fsin
| sym::simd_fcos
| sym::simd_fexp
| sym::simd_fexp2
| sym::simd_flog2
| sym::simd_flog10
| sym::simd_flog
| sym::simd_fabs
| sym::simd_ceil
| sym::simd_floor
| sym::simd_round
| sym::simd_trunc => (1, 0, vec![param(0)], param(0)),
sym::simd_fpowi => (1, 0, vec![param(0), tcx.types.i32], param(0)),
sym::simd_fma => (1, 0, vec![param(0), param(0), param(0)], param(0)),
sym::simd_gather => (3, 0, vec![param(0), param(1), param(2)], param(0)),
sym::simd_masked_load => (3, 0, vec![param(0), param(1), param(2)], param(2)),
sym::simd_masked_store => (3, 0, vec![param(0), param(1), param(2)], Ty::new_unit(tcx)),
sym::simd_scatter => (3, 0, vec![param(0), param(1), param(2)], Ty::new_unit(tcx)),
sym::simd_insert => (2, 0, vec![param(0), tcx.types.u32, param(1)], param(0)),
sym::simd_extract => (2, 0, vec![param(0), tcx.types.u32], param(1)),
sym::simd_cast
| sym::simd_as
| sym::simd_cast_ptr
| sym::simd_expose_addr
| sym::simd_from_exposed_addr => (2, 0, vec![param(0)], param(1)),
sym::simd_bitmask => (2, 0, vec![param(0)], param(1)),
sym::simd_select | sym::simd_select_bitmask => {
(2, 0, vec![param(0), param(1), param(1)], param(1))
}
sym::simd_reduce_all | sym::simd_reduce_any => (1, 0, vec![param(0)], tcx.types.bool),
sym::simd_reduce_add_ordered | sym::simd_reduce_mul_ordered => {
(2, 0, vec![param(0), param(1)], param(1))
}
sym::simd_reduce_add_unordered
| sym::simd_reduce_mul_unordered
| sym::simd_reduce_and
| sym::simd_reduce_or
| sym::simd_reduce_xor
| sym::simd_reduce_min
| sym::simd_reduce_max => (2, 0, vec![param(0)], param(1)),
sym::simd_shuffle => (3, 0, vec![param(0), param(0), param(1)], param(2)),
sym::simd_shuffle_generic => (2, 1, vec![param(0), param(0)], param(1)),

other => {
tcx.dcx().emit_err(UnrecognizedIntrinsicFunction { span, name: other });
return;
Expand All @@ -521,102 +592,3 @@ pub fn check_intrinsic_type(
let sig = ty::Binder::bind_with_vars(sig, bound_vars);
equate_intrinsic_type(tcx, span, intrinsic_id, n_tps, n_lts, n_cts, sig)
}

/// Type-check `extern "platform-intrinsic" { ... }` functions.
pub fn check_platform_intrinsic_type(
tcx: TyCtxt<'_>,
intrinsic_id: LocalDefId,
span: Span,
name: Symbol,
) {
let generics = tcx.generics_of(intrinsic_id);
let param = |n| {
if let Some(&ty::GenericParamDef {
name, kind: ty::GenericParamDefKind::Type { .. }, ..
}) = generics.opt_param_at(n as usize, tcx)
{
Ty::new_param(tcx, n, name)
} else {
Ty::new_error_with_message(tcx, span, "expected param")
}
};

let (n_tps, n_cts, inputs, output) = match name {
sym::simd_eq | sym::simd_ne | sym::simd_lt | sym::simd_le | sym::simd_gt | sym::simd_ge => {
(2, 0, vec![param(0), param(0)], param(1))
}
sym::simd_add
| sym::simd_sub
| sym::simd_mul
| sym::simd_rem
| sym::simd_div
| sym::simd_shl
| sym::simd_shr
| sym::simd_and
| sym::simd_or
| sym::simd_xor
| sym::simd_fmin
| sym::simd_fmax
| sym::simd_fpow
| sym::simd_saturating_add
| sym::simd_saturating_sub => (1, 0, vec![param(0), param(0)], param(0)),
sym::simd_arith_offset => (2, 0, vec![param(0), param(1)], param(0)),
sym::simd_neg
| sym::simd_bswap
| sym::simd_bitreverse
| sym::simd_ctlz
| sym::simd_cttz
| sym::simd_fsqrt
| sym::simd_fsin
| sym::simd_fcos
| sym::simd_fexp
| sym::simd_fexp2
| sym::simd_flog2
| sym::simd_flog10
| sym::simd_flog
| sym::simd_fabs
| sym::simd_ceil
| sym::simd_floor
| sym::simd_round
| sym::simd_trunc => (1, 0, vec![param(0)], param(0)),
sym::simd_fpowi => (1, 0, vec![param(0), tcx.types.i32], param(0)),
sym::simd_fma => (1, 0, vec![param(0), param(0), param(0)], param(0)),
sym::simd_gather => (3, 0, vec![param(0), param(1), param(2)], param(0)),
sym::simd_masked_load => (3, 0, vec![param(0), param(1), param(2)], param(2)),
sym::simd_masked_store => (3, 0, vec![param(0), param(1), param(2)], Ty::new_unit(tcx)),
sym::simd_scatter => (3, 0, vec![param(0), param(1), param(2)], Ty::new_unit(tcx)),
sym::simd_insert => (2, 0, vec![param(0), tcx.types.u32, param(1)], param(0)),
sym::simd_extract => (2, 0, vec![param(0), tcx.types.u32], param(1)),
sym::simd_cast
| sym::simd_as
| sym::simd_cast_ptr
| sym::simd_expose_addr
| sym::simd_from_exposed_addr => (2, 0, vec![param(0)], param(1)),
sym::simd_bitmask => (2, 0, vec![param(0)], param(1)),
sym::simd_select | sym::simd_select_bitmask => {
(2, 0, vec![param(0), param(1), param(1)], param(1))
}
sym::simd_reduce_all | sym::simd_reduce_any => (1, 0, vec![param(0)], tcx.types.bool),
sym::simd_reduce_add_ordered | sym::simd_reduce_mul_ordered => {
(2, 0, vec![param(0), param(1)], param(1))
}
sym::simd_reduce_add_unordered
| sym::simd_reduce_mul_unordered
| sym::simd_reduce_and
| sym::simd_reduce_or
| sym::simd_reduce_xor
| sym::simd_reduce_min
| sym::simd_reduce_max => (2, 0, vec![param(0)], param(1)),
sym::simd_shuffle => (3, 0, vec![param(0), param(0), param(1)], param(2)),
sym::simd_shuffle_generic => (2, 1, vec![param(0), param(0)], param(1)),
_ => {
let msg = format!("unrecognized platform-specific intrinsic function: `{name}`");
tcx.dcx().span_err(span, msg);
return;
}
};

let sig = tcx.mk_fn_sig(inputs, output, false, hir::Unsafety::Unsafe, Abi::PlatformIntrinsic);
let sig = ty::Binder::dummy(sig);
equate_intrinsic_type(tcx, span, intrinsic_id, n_tps, 0, n_cts, sig)
}
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ fn get_owner_return_paths(
/// as they must always be defined by the compiler.
// FIXME: Move this to a more appropriate place.
pub fn forbid_intrinsic_abi(tcx: TyCtxt<'_>, sp: Span, abi: Abi) {
if let Abi::RustIntrinsic | Abi::PlatformIntrinsic = abi {
if let Abi::RustIntrinsic = abi {
tcx.dcx().span_err(sp, "intrinsic must be in `extern \"rust-intrinsic\" { ... }` block");
}
}
Expand Down
5 changes: 1 addition & 4 deletions compiler/rustc_hir_analysis/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1677,10 +1677,7 @@ fn compute_sig_of_foreign_fn_decl<'tcx>(

// Feature gate SIMD types in FFI, since I am not sure that the
// ABIs are handled at all correctly. -huonw
if abi != abi::Abi::RustIntrinsic
&& abi != abi::Abi::PlatformIntrinsic
&& !tcx.features().simd_ffi
{
if abi != abi::Abi::RustIntrinsic && !tcx.features().simd_ffi {
let check = |ast_ty: &hir::Ty<'_>, ty: Ty<'_>| {
if ty.is_simd() {
let snip = tcx
Expand Down
6 changes: 1 addition & 5 deletions compiler/rustc_hir_typeck/src/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1177,11 +1177,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
};
if let (Some(a_sig), Some(b_sig)) = (a_sig, b_sig) {
// Intrinsics are not coercible to function pointers.
if a_sig.abi() == Abi::RustIntrinsic
|| a_sig.abi() == Abi::PlatformIntrinsic
|| b_sig.abi() == Abi::RustIntrinsic
|| b_sig.abi() == Abi::PlatformIntrinsic
{
if a_sig.abi() == Abi::RustIntrinsic || b_sig.abi() == Abi::RustIntrinsic {
return Err(TypeError::IntrinsicCast);
}
// The signature must match.
Expand Down
5 changes: 1 addition & 4 deletions compiler/rustc_lint/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1587,10 +1587,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
}

fn is_internal_abi(&self, abi: SpecAbi) -> bool {
matches!(
abi,
SpecAbi::Rust | SpecAbi::RustCall | SpecAbi::RustIntrinsic | SpecAbi::PlatformIntrinsic
)
matches!(abi, SpecAbi::Rust | SpecAbi::RustCall | SpecAbi::RustIntrinsic)
}

/// Find any fn-ptr types with external ABIs in `ty`.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_metadata/src/native_libs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl<'tcx> Collector<'tcx> {

let sess = self.tcx.sess;

if matches!(abi, Abi::Rust | Abi::RustIntrinsic | Abi::PlatformIntrinsic) {
if matches!(abi, Abi::Rust | Abi::RustIntrinsic) {
return;
}

Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_middle/src/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1244,7 +1244,6 @@ pub fn fn_can_unwind(tcx: TyCtxt<'_>, fn_def_id: Option<DefId>, abi: SpecAbi) ->
| RiscvInterruptS
| CCmseNonSecureCall
| Wasm
| PlatformIntrinsic
| Unadjusted => false,
Rust | RustCall | RustCold | RustIntrinsic => {
tcx.sess.panic_strategy() == PanicStrategy::Unwind
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1643,7 +1643,7 @@ pub fn is_doc_notable_trait(tcx: TyCtxt<'_>, def_id: DefId) -> bool {

/// Determines whether an item is an intrinsic by Abi. or by whether it has a `rustc_intrinsic` attribute
pub fn intrinsic(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<Symbol> {
if matches!(tcx.fn_sig(def_id).skip_binder().abi(), Abi::RustIntrinsic | Abi::PlatformIntrinsic)
if matches!(tcx.fn_sig(def_id).skip_binder().abi(), Abi::RustIntrinsic)
|| tcx.has_attr(def_id, sym::rustc_intrinsic)
{
Some(tcx.item_name(def_id.into()))
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_mir_transform/src/ffi_unwind_calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ fn abi_can_unwind(abi: Abi) -> bool {
| CCmseNonSecureCall
| Wasm
| RustIntrinsic
| PlatformIntrinsic
| Unadjusted => false,
Rust | RustCall | RustCold => true,
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1389,7 +1389,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
if target == Target::ForeignMod
&& let hir::Node::Item(item) = self.tcx.hir_node(hir_id)
&& let Item { kind: ItemKind::ForeignMod { abi, .. }, .. } = item
&& !matches!(abi, Abi::Rust | Abi::RustIntrinsic | Abi::PlatformIntrinsic)
&& !matches!(abi, Abi::Rust | Abi::RustIntrinsic)
{
return;
}
Expand Down Expand Up @@ -2071,7 +2071,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
) -> bool {
if let Target::ForeignFn = target
&& let hir::Node::Item(Item {
kind: ItemKind::ForeignMod { abi: Abi::RustIntrinsic | Abi::PlatformIntrinsic, .. },
kind: ItemKind::ForeignMod { abi: Abi::RustIntrinsic, .. },
..
}) = self.tcx.parent_hir_node(hir_id)
{
Expand Down
5 changes: 1 addition & 4 deletions compiler/rustc_passes/src/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
// If the current node is a function, has const stability attributes and if it doesn not have an intrinsic ABI,
// check if the function/method is const or the parent impl block is const
if let (Some(const_span), Some(fn_sig)) = (const_span, fn_sig) {
if fn_sig.header.abi != Abi::RustIntrinsic
&& fn_sig.header.abi != Abi::PlatformIntrinsic
&& !fn_sig.header.is_const()
{
if fn_sig.header.abi != Abi::RustIntrinsic && !fn_sig.header.is_const() {
if !self.in_trait_impl
|| (self.in_trait_impl && !self.tcx.is_const_fn_raw(def_id.to_def_id()))
{
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_smir/src/rustc_internal/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,6 @@ impl RustcInternal for Abi {
Abi::System { unwind } => rustc_target::spec::abi::Abi::System { unwind },
Abi::RustIntrinsic => rustc_target::spec::abi::Abi::RustIntrinsic,
Abi::RustCall => rustc_target::spec::abi::Abi::RustCall,
Abi::PlatformIntrinsic => rustc_target::spec::abi::Abi::PlatformIntrinsic,
Abi::Unadjusted => rustc_target::spec::abi::Abi::Unadjusted,
Abi::RustCold => rustc_target::spec::abi::Abi::RustCold,
Abi::RiscvInterruptM => rustc_target::spec::abi::Abi::RiscvInterruptM,
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_smir/src/rustc_smir/convert/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,6 @@ impl<'tcx> Stable<'tcx> for rustc_target::spec::abi::Abi {
abi::Abi::System { unwind } => Abi::System { unwind },
abi::Abi::RustIntrinsic => Abi::RustIntrinsic,
abi::Abi::RustCall => Abi::RustCall,
abi::Abi::PlatformIntrinsic => Abi::PlatformIntrinsic,
abi::Abi::Unadjusted => Abi::Unadjusted,
abi::Abi::RustCold => Abi::RustCold,
abi::Abi::RiscvInterruptM => Abi::RiscvInterruptM,
Expand Down
Loading

0 comments on commit 5c786a7

Please sign in to comment.