Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Swift function call ABI #64582

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/librustc/ich/impls_syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ impl_stable_hash_for!(enum ::rustc_target::spec::abi::Abi {
AmdGpuKernel,
Rust,
C,
Swift,
System,
RustIntrinsic,
RustCall,
Expand Down
1 change: 1 addition & 0 deletions src/librustc/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2599,6 +2599,7 @@ where
Vectorcall => Conv::X86VectorCall,
Thiscall => Conv::X86ThisCall,
C => Conv::C,
Swift => Conv::Swift,
Unadjusted => Conv::C,
Win64 => Conv::X86_64Win64,
SysV64 => Conv::X86_64SysV,
Expand Down
1 change: 1 addition & 0 deletions src/librustc_codegen_llvm/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ impl<'tcx> FnTypeLlvmExt<'tcx> for FnType<'tcx, Ty<'tcx>> {
fn llvm_cconv(&self) -> llvm::CallConv {
match self.conv {
Conv::C => llvm::CCallConv,
Conv::Swift => llvm::SwiftCallConv,
Conv::AmdGpuKernel => llvm::AmdGpuKernel,
Conv::ArmAapcs => llvm::ArmAapcsCallConv,
Conv::Msp430Intr => llvm::Msp430Intr,
Expand Down
1 change: 1 addition & 0 deletions src/librustc_codegen_llvm/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub enum CallConv {
CCallConv = 0,
FastCallConv = 8,
ColdCallConv = 9,
SwiftCallConv = 16,
X86StdcallCallConv = 64,
X86FastcallCallConv = 65,
ArmAapcsCallConv = 67,
Expand Down
1 change: 1 addition & 0 deletions src/librustc_target/abi/call/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ impl<'a, Ty> ArgType<'a, Ty> {
#[derive(Copy, Clone, PartialEq, Debug)]
pub enum Conv {
C,
Swift,

ArmAapcs,

Expand Down
2 changes: 2 additions & 0 deletions src/librustc_target/spec/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub enum Abi {
// Multiplatform / generic ABIs
Rust,
C,
Swift,
System,
RustIntrinsic,
RustCall,
Expand Down Expand Up @@ -62,6 +63,7 @@ const AbiDatas: &[AbiData] = &[
// Cross-platform ABIs
AbiData {abi: Abi::Rust, name: "Rust", generic: true },
AbiData {abi: Abi::C, name: "C", generic: true },
AbiData {abi: Abi::Swift, name: "Swift", generic: true },
AbiData {abi: Abi::System, name: "system", generic: true },
AbiData {abi: Abi::RustIntrinsic, name: "rust-intrinsic", generic: true },
AbiData {abi: Abi::RustCall, name: "rust-call", generic: true },
Expand Down
3 changes: 3 additions & 0 deletions src/libsyntax/feature_gate/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,9 @@ declare_features! (
/// Allows the use of or-patterns (e.g., `0 | 1`).
(active, or_patterns, "1.38.0", Some(54883), None),

/// Allows using the `Swift` ABI.
(active, abi_swift, "1.38.0", Some(0), None),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsure as to what Rust version I would put here?


// -------------------------------------------------------------------------
// feature-group-end: actual feature gates
// -------------------------------------------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions src/libsyntax/feature_gate/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ impl<'a> PostExpansionVisitor<'a> {
gate_feature_post!(&self, abi_amdgpu_kernel, span,
"amdgpu-kernel ABI is experimental and subject to change");
},
Abi::Swift => {
gate_feature_post!(&self, abi_swift, span,
"Swift ABI is experimental and subject to change");
},
// Stable
Abi::Cdecl |
Abi::Stdcall |
Expand Down
1 change: 1 addition & 0 deletions src/libsyntax_pos/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ symbols! {
Symbols {
aarch64_target_feature,
abi,
abi_swift,
abi_amdgpu_kernel,
abi_msp430_interrupt,
abi_ptx,
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/codemap_tests/unicode.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0703]: invalid ABI: found `路濫狼á́́`
LL | extern "路濫狼á́́" fn foo() {}
| ^^^^^^^^^ invalid ABI
|
= help: valid ABIs: cdecl, stdcall, fastcall, vectorcall, thiscall, aapcs, win64, sysv64, ptx-kernel, msp430-interrupt, x86-interrupt, amdgpu-kernel, Rust, C, system, rust-intrinsic, rust-call, platform-intrinsic, unadjusted
= help: valid ABIs: cdecl, stdcall, fastcall, vectorcall, thiscall, aapcs, win64, sysv64, ptx-kernel, msp430-interrupt, x86-interrupt, amdgpu-kernel, Rust, C, Swift, system, rust-intrinsic, rust-call, platform-intrinsic, unadjusted

error: aborting due to previous error

8 changes: 8 additions & 0 deletions src/test/ui/feature-gates/feature-gate-abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// gate-test-abi_ptx
// gate-test-abi_x86_interrupt
// gate-test-abi_amdgpu_kernel
// gate-test-abi_swift

// Functions
extern "rust-intrinsic" fn f1() {} //~ ERROR intrinsics are subject to change
Expand All @@ -20,6 +21,7 @@ extern "ptx-kernel" fn f6() {} //~ ERROR PTX ABIs are experimental and subject t
extern "x86-interrupt" fn f7() {} //~ ERROR x86-interrupt ABI is experimental
extern "thiscall" fn f8() {} //~ ERROR thiscall is experimental and subject to change
extern "amdgpu-kernel" fn f9() {} //~ ERROR amdgpu-kernel ABI is experimental and subject to change
extern "Swift" fn f10() {} //~ ERROR Swift ABI is experimental and subject to change

// Methods in trait definition
trait Tr {
Expand All @@ -34,6 +36,7 @@ trait Tr {
extern "x86-interrupt" fn m7(); //~ ERROR x86-interrupt ABI is experimental
extern "thiscall" fn m8(); //~ ERROR thiscall is experimental and subject to change
extern "amdgpu-kernel" fn m9(); //~ ERROR amdgpu-kernel ABI is experimental and subject to change
extern "Swift" fn m10(); //~ ERROR Swift ABI is experimental and subject to change

extern "vectorcall" fn dm3() {} //~ ERROR vectorcall is experimental and subject to change
extern "rust-call" fn dm4() {} //~ ERROR rust-call ABI is subject to change
Expand All @@ -42,6 +45,7 @@ trait Tr {
extern "x86-interrupt" fn dm7() {} //~ ERROR x86-interrupt ABI is experimental
extern "thiscall" fn dm8() {} //~ ERROR thiscall is experimental and subject to change
extern "amdgpu-kernel" fn dm9() {} //~ ERROR amdgpu-kernel ABI is experimental and subject to change
extern "Swift" fn dm10() {} //~ ERROR Swift ABI is experimental and subject to change
}

struct S;
Expand All @@ -59,6 +63,7 @@ impl Tr for S {
extern "x86-interrupt" fn m7() {} //~ ERROR x86-interrupt ABI is experimental
extern "thiscall" fn m8() {} //~ ERROR thiscall is experimental and subject to change
extern "amdgpu-kernel" fn m9() {} //~ ERROR amdgpu-kernel ABI is experimental and subject to change
extern "Swift" fn m10() {} //~ ERROR Swift ABI is experimental and subject to change
}

// Methods in inherent impl
Expand All @@ -74,6 +79,7 @@ impl S {
extern "x86-interrupt" fn im7() {} //~ ERROR x86-interrupt ABI is experimental
extern "thiscall" fn im8() {} //~ ERROR thiscall is experimental and subject to change
extern "amdgpu-kernel" fn im9() {} //~ ERROR amdgpu-kernel ABI is experimental and subject to change
extern "Swift" fn im10() {} //~ ERROR Swift ABI is experimental and subject to change
}

// Function pointer types
Expand All @@ -86,6 +92,7 @@ type A6 = extern "ptx-kernel" fn (); //~ ERROR PTX ABIs are experimental and sub
type A7 = extern "x86-interrupt" fn(); //~ ERROR x86-interrupt ABI is experimental
type A8 = extern "thiscall" fn(); //~ ERROR thiscall is experimental and subject to change
type A9 = extern "amdgpu-kernel" fn(); //~ ERROR amdgpu-kernel ABI is experimental and subject to change
type A10 = extern "Swift" fn(); //~ ERROR Swift ABI is experimental and subject to change

// Foreign modules
extern "rust-intrinsic" {} //~ ERROR intrinsics are subject to change
Expand All @@ -97,5 +104,6 @@ extern "ptx-kernel" {} //~ ERROR PTX ABIs are experimental and subject to change
extern "x86-interrupt" {} //~ ERROR x86-interrupt ABI is experimental
extern "thiscall" {} //~ ERROR thiscall is experimental and subject to change
extern "amdgpu-kernel" {} //~ ERROR amdgpu-kernel ABI is experimental and subject to change
extern "Swift" {} //~ ERROR Swift ABI is experimental and subject to change

fn main() {}
Loading