Skip to content

Commit 9209c5e

Browse files
authored
Rollup merge of rust-lang#139455 - Skgland:remove_rust-intrinsic_ABI, r=oli-obk
Remove support for `extern "rust-intrinsic"` blocks Part of rust-lang#132735 Looked manageable and there didn't appear to have been progress in the last two weeks, so decided to give it a try.
2 parents ddf099f + 7dd57f0 commit 9209c5e

File tree

92 files changed

+643
-984
lines changed

Some content is hidden

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

92 files changed

+643
-984
lines changed

Diff for: compiler/rustc_abi/src/extern_abi.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ pub enum ExternAbi {
6060
System {
6161
unwind: bool,
6262
},
63-
RustIntrinsic,
6463
RustCall,
6564
/// *Not* a stable ABI, just directly use the Rust types to describe the ABI for LLVM. Even
6665
/// normally ABI-compatible Rust types can become ABI-incompatible with this ABI!
@@ -128,7 +127,6 @@ abi_impls! {
128127
RiscvInterruptS =><= "riscv-interrupt-s",
129128
RustCall =><= "rust-call",
130129
RustCold =><= "rust-cold",
131-
RustIntrinsic =><= "rust-intrinsic",
132130
Stdcall { unwind: false } =><= "stdcall",
133131
Stdcall { unwind: true } =><= "stdcall-unwind",
134132
System { unwind: false } =><= "system",
@@ -199,7 +197,7 @@ impl ExternAbi {
199197
/// - are subject to change between compiler versions
200198
pub fn is_rustic_abi(self) -> bool {
201199
use ExternAbi::*;
202-
matches!(self, Rust | RustCall | RustIntrinsic | RustCold)
200+
matches!(self, Rust | RustCall | RustCold)
203201
}
204202

205203
pub fn supports_varargs(self) -> bool {

Diff for: compiler/rustc_ast_lowering/src/stability.rs

-4
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,6 @@ pub fn extern_abi_stability(abi: ExternAbi) -> Result<(), UnstableAbi> {
7979
| ExternAbi::SysV64 { .. }
8080
| ExternAbi::System { .. }
8181
| ExternAbi::EfiApi => Ok(()),
82-
// implementation details
83-
ExternAbi::RustIntrinsic => {
84-
Err(UnstableAbi { abi, feature: sym::intrinsics, explain: GateReason::ImplDetail })
85-
}
8682
ExternAbi::Unadjusted => {
8783
Err(UnstableAbi { abi, feature: sym::abi_unadjusted, explain: GateReason::ImplDetail })
8884
}

Diff for: compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
//! Codegen of intrinsics. This includes `extern "rust-intrinsic"`,
2-
//! functions marked with the `#[rustc_intrinsic]` attribute
1+
//! Codegen of intrinsics. This includes functions marked with the `#[rustc_intrinsic]` attribute
32
//! and LLVM intrinsics that have symbol names starting with `llvm.`.
43
54
macro_rules! intrinsic_args {

Diff for: compiler/rustc_error_codes/src/error_codes/E0622.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ Erroneous code example:
66
#![feature(intrinsics)]
77
#![allow(internal_features)]
88
9-
extern "rust-intrinsic" {
10-
pub static atomic_singlethreadfence_seqcst: fn();
9+
extern "C" {
10+
#[rustc_intrinsic]
11+
pub static atomic_singlethreadfence_seqcst: unsafe fn();
1112
// error: intrinsic must be a function
1213
}
1314
@@ -22,9 +23,8 @@ error, just declare a function. Example:
2223
#![feature(intrinsics)]
2324
#![allow(internal_features)]
2425
25-
extern "rust-intrinsic" {
26-
pub fn atomic_singlethreadfence_seqcst(); // ok!
27-
}
26+
#[rustc_intrinsic]
27+
pub unsafe fn atomic_singlethreadfence_seqcst(); // ok!
2828
2929
fn main() { unsafe { atomic_singlethreadfence_seqcst(); } }
3030
```

Diff for: compiler/rustc_feature/src/unstable.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ declare_features! (
211211
(internal, custom_mir, "1.65.0", None),
212212
/// Outputs useful `assert!` messages
213213
(unstable, generic_assert, "1.63.0", None),
214-
/// Allows using the `rust-intrinsic`'s "ABI".
214+
/// Allows using the #[rustc_intrinsic] attribute.
215215
(internal, intrinsics, "1.0.0", None),
216216
/// Allows using `#[lang = ".."]` attribute for linking items to special compiler logic.
217217
(internal, lang_items, "1.0.0", None),

Diff for: compiler/rustc_hir_analysis/src/check/check.rs

+49-59
Original file line numberDiff line numberDiff line change
@@ -741,10 +741,6 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
741741

742742
for &assoc_item in assoc_items.in_definition_order() {
743743
match assoc_item.kind {
744-
ty::AssocKind::Fn => {
745-
let abi = tcx.fn_sig(assoc_item.def_id).skip_binder().abi();
746-
forbid_intrinsic_abi(tcx, assoc_item.ident(tcx).span, abi);
747-
}
748744
ty::AssocKind::Type if assoc_item.defaultness(tcx).has_value() => {
749745
let trait_args = GenericArgs::identity_for_item(tcx, def_id);
750746
let _: Result<_, rustc_errors::ErrorGuaranteed> = check_type_bounds(
@@ -788,65 +784,59 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
788784
};
789785
check_abi(tcx, it.span, abi);
790786

791-
match abi {
792-
ExternAbi::RustIntrinsic => {
793-
for item in items {
794-
intrinsic::check_intrinsic_type(
795-
tcx,
796-
item.id.owner_id.def_id,
797-
item.span,
798-
item.ident.name,
799-
abi,
800-
);
801-
}
787+
for item in items {
788+
let def_id = item.id.owner_id.def_id;
789+
790+
if tcx.has_attr(def_id, sym::rustc_intrinsic) {
791+
intrinsic::check_intrinsic_type(
792+
tcx,
793+
item.id.owner_id.def_id,
794+
item.span,
795+
item.ident.name,
796+
abi,
797+
);
802798
}
803799

804-
_ => {
805-
for item in items {
806-
let def_id = item.id.owner_id.def_id;
807-
let generics = tcx.generics_of(def_id);
808-
let own_counts = generics.own_counts();
809-
if generics.own_params.len() - own_counts.lifetimes != 0 {
810-
let (kinds, kinds_pl, egs) = match (own_counts.types, own_counts.consts)
811-
{
812-
(_, 0) => ("type", "types", Some("u32")),
813-
// We don't specify an example value, because we can't generate
814-
// a valid value for any type.
815-
(0, _) => ("const", "consts", None),
816-
_ => ("type or const", "types or consts", None),
817-
};
818-
struct_span_code_err!(
819-
tcx.dcx(),
820-
item.span,
821-
E0044,
822-
"foreign items may not have {kinds} parameters",
823-
)
824-
.with_span_label(item.span, format!("can't have {kinds} parameters"))
825-
.with_help(
826-
// FIXME: once we start storing spans for type arguments, turn this
827-
// into a suggestion.
828-
format!(
829-
"replace the {} parameters with concrete {}{}",
830-
kinds,
831-
kinds_pl,
832-
egs.map(|egs| format!(" like `{egs}`")).unwrap_or_default(),
833-
),
834-
)
835-
.emit();
836-
}
800+
let generics = tcx.generics_of(def_id);
801+
let own_counts = generics.own_counts();
802+
if generics.own_params.len() - own_counts.lifetimes != 0 {
803+
let (kinds, kinds_pl, egs) = match (own_counts.types, own_counts.consts) {
804+
(_, 0) => ("type", "types", Some("u32")),
805+
// We don't specify an example value, because we can't generate
806+
// a valid value for any type.
807+
(0, _) => ("const", "consts", None),
808+
_ => ("type or const", "types or consts", None),
809+
};
810+
struct_span_code_err!(
811+
tcx.dcx(),
812+
item.span,
813+
E0044,
814+
"foreign items may not have {kinds} parameters",
815+
)
816+
.with_span_label(item.span, format!("can't have {kinds} parameters"))
817+
.with_help(
818+
// FIXME: once we start storing spans for type arguments, turn this
819+
// into a suggestion.
820+
format!(
821+
"replace the {} parameters with concrete {}{}",
822+
kinds,
823+
kinds_pl,
824+
egs.map(|egs| format!(" like `{egs}`")).unwrap_or_default(),
825+
),
826+
)
827+
.emit();
828+
}
837829

838-
let item = tcx.hir_foreign_item(item.id);
839-
match &item.kind {
840-
hir::ForeignItemKind::Fn(sig, _, _) => {
841-
require_c_abi_if_c_variadic(tcx, sig.decl, abi, item.span);
842-
}
843-
hir::ForeignItemKind::Static(..) => {
844-
check_static_inhabited(tcx, def_id);
845-
check_static_linkage(tcx, def_id);
846-
}
847-
_ => {}
848-
}
830+
let item = tcx.hir_foreign_item(item.id);
831+
match &item.kind {
832+
hir::ForeignItemKind::Fn(sig, _, _) => {
833+
require_c_abi_if_c_variadic(tcx, sig.decl, abi, item.span);
834+
}
835+
hir::ForeignItemKind::Static(..) => {
836+
check_static_inhabited(tcx, def_id);
837+
check_static_linkage(tcx, def_id);
849838
}
839+
_ => {}
850840
}
851841
}
852842
}

Diff for: compiler/rustc_hir_analysis/src/check/intrinsic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Type-checking for the rust-intrinsic intrinsics that the compiler exposes.
1+
//! Type-checking for the `#[rustc_intrinsic]` intrinsics that the compiler exposes.
22
33
use rustc_abi::ExternAbi;
44
use rustc_errors::codes::*;

Diff for: compiler/rustc_hir_analysis/src/check/mod.rs

-9
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,6 @@ fn get_owner_return_paths(
137137
})
138138
}
139139

140-
/// Forbid defining intrinsics in Rust code,
141-
/// as they must always be defined by the compiler.
142-
// FIXME: Move this to a more appropriate place.
143-
pub fn forbid_intrinsic_abi(tcx: TyCtxt<'_>, sp: Span, abi: ExternAbi) {
144-
if let ExternAbi::RustIntrinsic = abi {
145-
tcx.dcx().span_err(sp, "intrinsic must be in `extern \"rust-intrinsic\" { ... }` block");
146-
}
147-
}
148-
149140
pub(super) fn maybe_check_static_with_link_section(tcx: TyCtxt<'_>, id: LocalDefId) {
150141
// Only restricted on wasm target for now
151142
if !tcx.sess.target.is_like_wasm {

Diff for: compiler/rustc_hir_analysis/src/collect.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ use rustc_trait_selection::infer::InferCtxtExt;
4242
use rustc_trait_selection::traits::ObligationCtxt;
4343
use tracing::{debug, instrument};
4444

45-
use crate::check::intrinsic::intrinsic_operation_unsafety;
4645
use crate::errors;
4746
use crate::hir_ty_lowering::errors::assoc_kind_str;
4847
use crate::hir_ty_lowering::{FeedConstTy, HirTyLowerer, RegionInferReason};
@@ -1704,18 +1703,13 @@ fn compute_sig_of_foreign_fn_decl<'tcx>(
17041703
abi: ExternAbi,
17051704
safety: hir::Safety,
17061705
) -> ty::PolyFnSig<'tcx> {
1707-
let safety = if abi == ExternAbi::RustIntrinsic {
1708-
intrinsic_operation_unsafety(tcx, def_id)
1709-
} else {
1710-
safety
1711-
};
17121706
let hir_id = tcx.local_def_id_to_hir_id(def_id);
17131707
let fty =
17141708
ItemCtxt::new(tcx, def_id).lowerer().lower_fn_ty(hir_id, safety, abi, decl, None, None);
17151709

17161710
// Feature gate SIMD types in FFI, since I am not sure that the
17171711
// ABIs are handled at all correctly. -huonw
1718-
if abi != ExternAbi::RustIntrinsic && !tcx.features().simd_ffi() {
1712+
if !tcx.features().simd_ffi() {
17191713
let check = |hir_ty: &hir::Ty<'_>, ty: Ty<'_>| {
17201714
if ty.is_simd() {
17211715
let snip = tcx

Diff for: compiler/rustc_hir_typeck/src/check.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_hir as hir;
55
use rustc_hir::def::DefKind;
66
use rustc_hir::intravisit::Visitor;
77
use rustc_hir::lang_items::LangItem;
8-
use rustc_hir_analysis::check::{check_function_signature, forbid_intrinsic_abi};
8+
use rustc_hir_analysis::check::check_function_signature;
99
use rustc_infer::infer::RegionVariableOrigin;
1010
use rustc_infer::traits::WellFormedLoc;
1111
use rustc_middle::ty::{self, Binder, Ty, TyCtxt};
@@ -50,8 +50,6 @@ pub(super) fn check_fn<'a, 'tcx>(
5050

5151
let span = body.value.span;
5252

53-
forbid_intrinsic_abi(tcx, span, fn_sig.abi);
54-
5553
GatherLocalsVisitor::new(fcx).visit_body(body);
5654

5755
// C-variadic fns also have a `VaList` input that's not listed in `fn_sig`

Diff for: compiler/rustc_hir_typeck/src/coercion.rs

-5
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
3838
use std::ops::Deref;
3939

40-
use rustc_abi::ExternAbi;
4140
use rustc_attr_parsing::InlineAttr;
4241
use rustc_errors::codes::*;
4342
use rustc_errors::{Applicability, Diag, struct_span_code_err};
@@ -1240,10 +1239,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12401239
}
12411240
};
12421241
if let (Some(a_sig), Some(b_sig)) = (a_sig, b_sig) {
1243-
// Intrinsics are not coercible to function pointers.
1244-
if a_sig.abi() == ExternAbi::RustIntrinsic || b_sig.abi() == ExternAbi::RustIntrinsic {
1245-
return Err(TypeError::IntrinsicCast);
1246-
}
12471242
// The signature must match.
12481243
let (a_sig, b_sig) = self.normalize(new.span, (a_sig, b_sig));
12491244
let sig = self

Diff for: compiler/rustc_metadata/src/native_libs.rs

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

208208
let sess = self.tcx.sess;
209209

210-
if matches!(abi, ExternAbi::Rust | ExternAbi::RustIntrinsic) {
210+
if matches!(abi, ExternAbi::Rust) {
211211
return;
212212
}
213213

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub enum InstanceKind<'tcx> {
7171
/// - coroutines
7272
Item(DefId),
7373

74-
/// An intrinsic `fn` item (with `"rust-intrinsic"` ABI).
74+
/// An intrinsic `fn` item (with`#[rustc_instrinsic]`).
7575
///
7676
/// Alongside `Virtual`, this is the only `InstanceKind` that does not have its own callable MIR.
7777
/// Instead, codegen and const eval "magically" evaluate calls to intrinsics purely in the

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -1265,9 +1265,7 @@ pub fn fn_can_unwind(tcx: TyCtxt<'_>, fn_def_id: Option<DefId>, abi: ExternAbi)
12651265
| CCmseNonSecureCall
12661266
| CCmseNonSecureEntry
12671267
| Unadjusted => false,
1268-
Rust | RustCall | RustCold | RustIntrinsic => {
1269-
tcx.sess.panic_strategy() == PanicStrategy::Unwind
1270-
}
1268+
Rust | RustCall | RustCold => tcx.sess.panic_strategy() == PanicStrategy::Unwind,
12711269
}
12721270
}
12731271

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

+2-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use std::{fmt, iter};
44

5-
use rustc_abi::{ExternAbi, Float, Integer, IntegerType, Size};
5+
use rustc_abi::{Float, Integer, IntegerType, Size};
66
use rustc_apfloat::Float as _;
77
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
88
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
@@ -1719,10 +1719,7 @@ pub fn is_doc_notable_trait(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
17191719
/// the compiler to make some assumptions about its shape; if the user doesn't use a feature gate, they may
17201720
/// cause an ICE that we otherwise may want to prevent.
17211721
pub fn intrinsic_raw(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<ty::IntrinsicDef> {
1722-
if tcx.features().intrinsics()
1723-
&& (matches!(tcx.fn_sig(def_id).skip_binder().abi(), ExternAbi::RustIntrinsic)
1724-
|| tcx.has_attr(def_id, sym::rustc_intrinsic))
1725-
{
1722+
if tcx.features().intrinsics() && tcx.has_attr(def_id, sym::rustc_intrinsic) {
17261723
let must_be_overridden = match tcx.hir_node_by_def_id(def_id) {
17271724
hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn { has_body, .. }, .. }) => {
17281725
!has_body

Diff for: compiler/rustc_passes/src/check_attr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1598,7 +1598,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
15981598
if target == Target::ForeignMod
15991599
&& let hir::Node::Item(item) = self.tcx.hir_node(hir_id)
16001600
&& let Item { kind: ItemKind::ForeignMod { abi, .. }, .. } = item
1601-
&& !matches!(abi, ExternAbi::Rust | ExternAbi::RustIntrinsic)
1601+
&& !matches!(abi, ExternAbi::Rust)
16021602
{
16031603
return;
16041604
}

Diff for: compiler/rustc_smir/src/rustc_internal/internal.rs

-1
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,6 @@ impl RustcInternal for Abi {
491491
Abi::CCmseNonSecureCall => rustc_abi::ExternAbi::CCmseNonSecureCall,
492492
Abi::CCmseNonSecureEntry => rustc_abi::ExternAbi::CCmseNonSecureEntry,
493493
Abi::System { unwind } => rustc_abi::ExternAbi::System { unwind },
494-
Abi::RustIntrinsic => rustc_abi::ExternAbi::RustIntrinsic,
495494
Abi::RustCall => rustc_abi::ExternAbi::RustCall,
496495
Abi::Unadjusted => rustc_abi::ExternAbi::Unadjusted,
497496
Abi::RustCold => rustc_abi::ExternAbi::RustCold,

Diff for: compiler/rustc_smir/src/rustc_smir/convert/ty.rs

-1
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,6 @@ impl<'tcx> Stable<'tcx> for rustc_abi::ExternAbi {
871871
ExternAbi::CCmseNonSecureCall => Abi::CCmseNonSecureCall,
872872
ExternAbi::CCmseNonSecureEntry => Abi::CCmseNonSecureEntry,
873873
ExternAbi::System { unwind } => Abi::System { unwind },
874-
ExternAbi::RustIntrinsic => Abi::RustIntrinsic,
875874
ExternAbi::RustCall => Abi::RustCall,
876875
ExternAbi::Unadjusted => Abi::Unadjusted,
877876
ExternAbi::RustCold => Abi::RustCold,

Diff for: compiler/rustc_smir/src/stable_mir/ty.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1093,7 +1093,6 @@ pub enum Abi {
10931093
CCmseNonSecureCall,
10941094
CCmseNonSecureEntry,
10951095
System { unwind: bool },
1096-
RustIntrinsic,
10971096
RustCall,
10981097
Unadjusted,
10991098
RustCold,

Diff for: compiler/rustc_target/src/callconv/loongarch.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc_abi::{
2-
BackendRepr, ExternAbi, FieldsShape, HasDataLayout, Primitive, Reg, RegKind, Size,
3-
TyAbiInterface, TyAndLayout, Variants,
2+
BackendRepr, FieldsShape, HasDataLayout, Primitive, Reg, RegKind, Size, TyAbiInterface,
3+
TyAndLayout, Variants,
44
};
55

66
use crate::callconv::{ArgAbi, ArgExtension, CastTarget, FnAbi, PassMode, Uniform};
@@ -364,15 +364,11 @@ where
364364
}
365365
}
366366

367-
pub(crate) fn compute_rust_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>, abi: ExternAbi)
367+
pub(crate) fn compute_rust_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>)
368368
where
369369
Ty: TyAbiInterface<'a, C> + Copy,
370370
C: HasDataLayout + HasTargetSpec,
371371
{
372-
if abi == ExternAbi::RustIntrinsic {
373-
return;
374-
}
375-
376372
let grlen = cx.data_layout().pointer_size.bits();
377373

378374
for arg in fn_abi.args.iter_mut() {

0 commit comments

Comments
 (0)