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

compiler/rustc_abi/src/extern_abi.rs

Lines changed: 1 addition & 3 deletions
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 {

compiler/rustc_ast_lowering/src/stability.rs

Lines changed: 0 additions & 4 deletions
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
}

compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs

Lines changed: 1 addition & 2 deletions
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 {

compiler/rustc_error_codes/src/error_codes/E0622.md

Lines changed: 5 additions & 5 deletions
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
```

compiler/rustc_feature/src/unstable.rs

Lines changed: 1 addition & 1 deletion
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),

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 49 additions & 59 deletions
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
}

compiler/rustc_hir_analysis/src/check/intrinsic.rs

Lines changed: 1 addition & 1 deletion
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::*;

compiler/rustc_hir_analysis/src/check/mod.rs

Lines changed: 0 additions & 9 deletions
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 {

compiler/rustc_hir_analysis/src/collect.rs

Lines changed: 1 addition & 7 deletions
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

compiler/rustc_hir_typeck/src/check.rs

Lines changed: 1 addition & 3 deletions
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`

0 commit comments

Comments
 (0)