From e2dcc66854e080cbd6be2dd4e1983f4200c100d7 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Sun, 11 Dec 2022 22:03:01 -0800 Subject: [PATCH] Experimental feature gate proposal `crabi` --- compiler/rustc_feature/src/active.rs | 2 ++ compiler/rustc_middle/src/ty/layout.rs | 1 + .../src/ffi_unwind_calls.rs | 1 + compiler/rustc_span/src/symbol.rs | 1 + compiler/rustc_target/src/spec/abi.rs | 7 ++++++ compiler/rustc_target/src/spec/mod.rs | 2 ++ compiler/rustc_ty_utils/src/abi.rs | 1 + tests/ui/feature-gates/feature-gate-crabi.rs | 12 ++++++++++ .../feature-gates/feature-gate-crabi.stderr | 23 +++++++++++++++++++ 9 files changed, 50 insertions(+) create mode 100644 tests/ui/feature-gates/feature-gate-crabi.rs create mode 100644 tests/ui/feature-gates/feature-gate-crabi.stderr diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs index 48f5bd1cb5048..50b0d843b5f02 100644 --- a/compiler/rustc_feature/src/active.rs +++ b/compiler/rustc_feature/src/active.rs @@ -359,6 +359,8 @@ declare_features! ( (active, const_trait_impl, "1.42.0", Some(67792), None), /// Allows the `?` operator in const contexts. (active, const_try, "1.56.0", Some(74935), None), + /// Allows using `extern "crabi"` and `repr(crabi)` + (incomplete, crabi, "CURRENT_RUSTC_VERSION", Some(111423), None), /// Allows non-builtin attributes in inner attribute position. (active, custom_inner_attributes, "1.30.0", Some(54726), None), /// Allows custom test frameworks with `#![test_runner]` and `#[test_case]`. diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index 2328a1324fc3c..d7fed1fac1338 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -1228,6 +1228,7 @@ pub fn fn_can_unwind(tcx: TyCtxt<'_>, fn_def_id: Option, abi: SpecAbi) -> | Wasm | RustIntrinsic | PlatformIntrinsic + | Crabi | Unadjusted => false, Rust | RustCall | RustCold => tcx.sess.panic_strategy() == PanicStrategy::Unwind, } diff --git a/compiler/rustc_mir_transform/src/ffi_unwind_calls.rs b/compiler/rustc_mir_transform/src/ffi_unwind_calls.rs index c9b24adba0ca8..c4fe2729b7313 100644 --- a/compiler/rustc_mir_transform/src/ffi_unwind_calls.rs +++ b/compiler/rustc_mir_transform/src/ffi_unwind_calls.rs @@ -32,6 +32,7 @@ fn abi_can_unwind(abi: Abi) -> bool { | Wasm | RustIntrinsic | PlatformIntrinsic + | Crabi | Unadjusted => false, Rust | RustCall | RustCold => true, } diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index b619e5877ad7b..22125172358b3 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -555,6 +555,7 @@ symbols! { cosf64, count, cr, + crabi, crate_id, crate_in_paths, crate_local, diff --git a/compiler/rustc_target/src/spec/abi.rs b/compiler/rustc_target/src/spec/abi.rs index 5582d909f6b10..a8d685def1702 100644 --- a/compiler/rustc_target/src/spec/abi.rs +++ b/compiler/rustc_target/src/spec/abi.rs @@ -38,6 +38,7 @@ pub enum Abi { PlatformIntrinsic, Unadjusted, RustCold, + Crabi, } impl Abi { @@ -107,6 +108,7 @@ const AbiDatas: &[AbiData] = &[ AbiData { abi: Abi::PlatformIntrinsic, name: "platform-intrinsic" }, AbiData { abi: Abi::Unadjusted, name: "unadjusted" }, AbiData { abi: Abi::RustCold, name: "rust-cold" }, + AbiData { abi: Abi::Crabi, name: "crabi" }, ]; /// Returns the ABI with the given name (if any). @@ -246,6 +248,10 @@ pub fn is_stable(name: &str) -> Result<(), AbiDisabled> { feature: sym::wasm_abi, explain: "wasm ABI is experimental and subject to change", }), + "crabi" => Err(AbiDisabled::Unstable { + feature: sym::crabi, + explain: "crABI is experimental and subject to change", + }), _ => Err(AbiDisabled::Unrecognized), } } @@ -298,6 +304,7 @@ impl Abi { PlatformIntrinsic => 32, Unadjusted => 33, RustCold => 34, + Crabi => 35, }; debug_assert!( AbiDatas diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index 4e5a821f0f6ab..15ec921b6cb96 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -2075,6 +2075,8 @@ impl Target { Vectorcall { .. } if ["x86", "x86_64"].contains(&&self.arch[..]) => true, // Return a `None` for other cases so that we know to emit a future compat lint. Stdcall { .. } | Fastcall { .. } | Vectorcall { .. } => return None, + // Not yet implemented + Crabi => false, }) } diff --git a/compiler/rustc_ty_utils/src/abi.rs b/compiler/rustc_ty_utils/src/abi.rs index 271284b2d8115..205ab2aa43d25 100644 --- a/compiler/rustc_ty_utils/src/abi.rs +++ b/compiler/rustc_ty_utils/src/abi.rs @@ -192,6 +192,7 @@ fn conv_from_spec_abi(tcx: TyCtxt<'_>, abi: SpecAbi) -> Conv { AvrInterrupt => Conv::AvrInterrupt, AvrNonBlockingInterrupt => Conv::AvrNonBlockingInterrupt, Wasm => Conv::C, + Crabi => bug!("crABI is not yet implemented"), // These API constants ought to be more specific... Cdecl { .. } => Conv::C, diff --git a/tests/ui/feature-gates/feature-gate-crabi.rs b/tests/ui/feature-gates/feature-gate-crabi.rs new file mode 100644 index 0000000000000..8d3ec1fb58cda --- /dev/null +++ b/tests/ui/feature-gates/feature-gate-crabi.rs @@ -0,0 +1,12 @@ +// Test that the `crabi` ABI is feature-gated, and cannot be used when the `crabi` feature gate is +// not used. + +extern "crabi" { +//~^ ERROR crABI is experimental and subject to change [E0658] +//~| ERROR `"crabi"` is not a supported ABI for the current target [E0570] + fn f(); +} + +fn main() { + f(); +} diff --git a/tests/ui/feature-gates/feature-gate-crabi.stderr b/tests/ui/feature-gates/feature-gate-crabi.stderr new file mode 100644 index 0000000000000..a91fd29ce124f --- /dev/null +++ b/tests/ui/feature-gates/feature-gate-crabi.stderr @@ -0,0 +1,23 @@ +error[E0658]: crABI is experimental and subject to change + --> $DIR/feature-gate-crabi.rs:4:8 + | +LL | extern "crabi" { + | ^^^^^^^ + | + = note: see issue #111423 for more information + = help: add `#![feature(crabi)]` to the crate attributes to enable + +error[E0570]: `"crabi"` is not a supported ABI for the current target + --> $DIR/feature-gate-crabi.rs:4:1 + | +LL | / extern "crabi" { +LL | | +LL | | +LL | | fn f(); +LL | | } + | |_^ + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0570, E0658. +For more information about an error, try `rustc --explain E0570`.