Skip to content
Draft
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
5 changes: 5 additions & 0 deletions compiler/rustc_abi/src/canon_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ pub enum CanonAbi {
/// ABI relevant to GPUs: the entry point for a GPU kernel
GpuKernel,

/// ABI relevant to WebAssembly, leveraging multiple returns.
WasmMultivalue,

/// ABIs relevant to bare-metal interrupt targets
// FIXME(workingjubilee): a particular reason for this nesting is we might not need these?
// interrupt ABIs should have the same properties:
Expand All @@ -63,6 +66,7 @@ impl CanonAbi {
CanonAbi::C
| CanonAbi::Custom
| CanonAbi::Swift
| CanonAbi::WasmMultivalue
| CanonAbi::Arm(_)
| CanonAbi::GpuKernel
| CanonAbi::Interrupt(_)
Expand All @@ -83,6 +87,7 @@ impl fmt::Display for CanonAbi {
CanonAbi::RustPreserveNone => ExternAbi::RustPreserveNone,
CanonAbi::Custom => ExternAbi::Custom,
CanonAbi::Swift => ExternAbi::Swift,
CanonAbi::WasmMultivalue => ExternAbi::WasmMultivalue,
CanonAbi::Arm(arm_call) => match arm_call {
ArmCall::Aapcs => ExternAbi::Aapcs { unwind: false },
ArmCall::CCmseNonSecureCall => ExternAbi::CmseNonSecureCall,
Expand Down
8 changes: 7 additions & 1 deletion compiler/rustc_abi/src/extern_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ pub enum ExternAbi {
Win64 {
unwind: bool,
},

/// WebAssembly-specific ABI to support multiple returns using the
/// multivalue wasm proposal.
WasmMultivalue,
}

macro_rules! abi_impls {
Expand Down Expand Up @@ -210,6 +214,7 @@ abi_impls! {
Unadjusted =><= "unadjusted",
Vectorcall { unwind: false } =><= "vectorcall",
Vectorcall { unwind: true } =><= "vectorcall-unwind",
WasmMultivalue =><= "wasm-multivalue",
Win64 { unwind: false } =><= "win64",
Win64 { unwind: true } =><= "win64-unwind",
X86Interrupt =><= "x86-interrupt",
Expand Down Expand Up @@ -354,7 +359,8 @@ impl ExternAbi {
| Self::SysV64 { .. }
| Self::Win64 { .. }
| Self::RustPreserveNone
| Self::Swift => true,
| Self::Swift
| Self::WasmMultivalue => true,
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_ast_lowering/src/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,10 @@ pub fn extern_abi_stability(abi: ExternAbi) -> Result<(), UnstableAbi> {
ExternAbi::Swift => {
Err(UnstableAbi { abi, feature: sym::abi_swift, explain: GateReason::Experimental })
}
ExternAbi::WasmMultivalue => Err(UnstableAbi {
abi,
feature: sym::abi_wasm_multivalue,
explain: GateReason::Experimental,
}),
}
}
1 change: 1 addition & 0 deletions compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ impl<'a> AstValidator<'a> {
| CanonAbi::RustCold
| CanonAbi::RustPreserveNone
| CanonAbi::Swift
| CanonAbi::WasmMultivalue
| CanonAbi::Arm(_)
| CanonAbi::X86(_) => { /* nothing to check */ }

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/src/abi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub(crate) fn conv_to_call_conv(
CanonAbi::Interrupt(_) | CanonAbi::Arm(_) | CanonAbi::Swift => {
sess.dcx().fatal("call conv {c:?} is not yet implemented")
}
CanonAbi::GpuKernel => {
CanonAbi::GpuKernel | CanonAbi::WasmMultivalue => {
unreachable!("tried to use {c:?} call conv which only exists on an unsupported target")
}
}
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_codegen_gcc/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,10 @@ pub fn conv_to_fn_attribute<'gcc>(conv: CanonAbi, arch: &Arch) -> Option<FnAttri
CanonAbi::Custom => return None,
// gcc/gccjit does not have anything for Swift's calling convention.
CanonAbi::Swift => panic!("gcc/gccjit backend does not support Swift calling convention"),
// gcc/gccjit does not target WebAssembly.
CanonAbi::WasmMultivalue => {
panic!("gcc/gccjit backend does not support the wasm-multivalue calling convention")
}
CanonAbi::Arm(arm_call) => match arm_call {
ArmCall::CCmseNonSecureCall => FnAttribute::ArmCmseNonsecureCall,
ArmCall::CCmseNonSecureEntry => FnAttribute::ArmCmseNonsecureEntry,
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_codegen_llvm/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,12 @@ pub(crate) fn to_llvm_calling_convention(sess: &Session, abi: CanonAbi) -> llvm:
// convention for declaring foreign functions.
CanonAbi::Custom => llvm::CCallConv,
CanonAbi::Swift => llvm::SwiftCallConv,
CanonAbi::WasmMultivalue => {
if crate::llvm_util::get_version() < (23, 0, 0) {
sess.dcx().emit_fatal(crate::errors::WasmMultivalueRequiresLlvm23);
}
llvm::WasmMultivalue
}
CanonAbi::GpuKernel => match &sess.target.arch {
Arch::AmdGpu => llvm::AmdgpuKernel,
Arch::Nvptx64 => llvm::PtxKernel,
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_codegen_llvm/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ pub(crate) struct SymbolAlreadyDefined<'a> {
#[diag("`-Zsanitizer=memtag` requires `-Ctarget-feature=+mte`")]
pub(crate) struct SanitizerMemtagRequiresMte;

#[derive(Diagnostic)]
#[diag("the `\"wasm-multivalue\"` ABI requires LLVM 23 or newer")]
pub(crate) struct WasmMultivalueRequiresLlvm23;

pub(crate) struct ParseTargetMachineConfig<'a>(pub LlvmError<'a>);

impl<G: EmissionGuarantee> Diagnostic<'_, G> for ParseTargetMachineConfig<'_> {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_codegen_llvm/src/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ pub(crate) enum CallConv {
AvrNonBlockingInterrupt = 84,
AvrInterrupt = 85,
AmdgpuKernel = 91,
WasmMultivalue = 128,
}

/// Must match the layout of `LLVMLinkage`.
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,8 @@ declare_features! (
(unstable, abi_riscv_interrupt, "1.73.0", Some(111889)),
/// Allows `extern "Swift" fn()`.
(unstable, abi_swift, "1.97.0", Some(156481)),
/// Allows `extern "wasm-multivalue" fn()`.
(unstable, abi_wasm_multivalue, "CURRENT_RUSTC_VERSION", Some(0)),
/// Allows `extern "x86-interrupt" fn()`.
(unstable, abi_x86_interrupt, "1.17.0", Some(40180)),
/// Allows additional const parameter types, such as `[u8; 10]` or user defined types
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_hir_typeck/src/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
| CanonAbi::RustCold
| CanonAbi::RustPreserveNone
| CanonAbi::Swift
| CanonAbi::WasmMultivalue
| CanonAbi::Arm(_)
| CanonAbi::X86(_) => {}
}
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_middle/src/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1323,6 +1323,7 @@ pub fn fn_can_unwind(tcx: TyCtxt<'_>, fn_def_id: Option<DefId>, abi: ExternAbi)
| RiscvInterruptS
| RustInvalid
| Swift
| WasmMultivalue
| Unadjusted => false,
Rust | RustCall | RustCold | RustPreserveNone => tcx.sess.panic_strategy().unwinds(),
}
Expand Down
10 changes: 10 additions & 0 deletions compiler/rustc_monomorphize/src/mono_checks/abi_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,16 @@ fn do_check_simd_vector_abi<'tcx>(
is_call,
});
}
// The `wasm-multivalue` ABI relies on the WebAssembly multi-value proposal.
if abi.conv == CanonAbi::WasmMultivalue && !have_feature(sym::multivalue) {
let (span, _hir_id) = loc();
tcx.dcx().emit_err(errors::AbiRequiredTargetFeature {
span,
required_feature: "multivalue",
abi: "wasm-multivalue",
is_call,
});
}
}

/// Emit an error when a non-rustic ABI has unsized parameters.
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_public/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,8 @@ pub enum CallConvention {
AvrNonBlockingInterrupt,

RiscvInterrupt,

WasmMultivalue,
}

#[non_exhaustive]
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_public/src/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,7 @@ pub enum Abi {
RustInvalid,
Custom,
Swift,
WasmMultivalue,
}

/// A binder represents a possibly generic type and its bound vars.
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_public/src/unstable/convert/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,7 @@ impl RustcInternal for Abi {
Abi::RustPreserveNone => rustc_abi::ExternAbi::RustPreserveNone,
Abi::Custom => rustc_abi::ExternAbi::Custom,
Abi::Swift => rustc_abi::ExternAbi::Swift,
Abi::WasmMultivalue => rustc_abi::ExternAbi::WasmMultivalue,
}
}
}
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_public/src/unstable/convert/stable/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ impl<'tcx> Stable<'tcx> for CanonAbi {
CanonAbi::RustPreserveNone => CallConvention::PreserveNone,
CanonAbi::Custom => CallConvention::Custom,
CanonAbi::Swift => CallConvention::Swift,
CanonAbi::WasmMultivalue => CallConvention::WasmMultivalue,
CanonAbi::Arm(arm_call) => match arm_call {
ArmCall::Aapcs => CallConvention::ArmAapcs,
ArmCall::CCmseNonSecureCall => CallConvention::CCmseNonSecureCall,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_public/src/unstable/convert/stable/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,7 @@ impl<'tcx> Stable<'tcx> for rustc_abi::ExternAbi {
ExternAbi::RiscvInterruptS => Abi::RiscvInterruptS,
ExternAbi::Custom => Abi::Custom,
ExternAbi::Swift => Abi::Swift,
ExternAbi::WasmMultivalue => Abi::WasmMultivalue,
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ symbols! {
abi_thiscall,
abi_unadjusted,
abi_vectorcall,
abi_wasm_multivalue,
abi_x86_interrupt,
abort,
add,
Expand Down Expand Up @@ -1336,6 +1337,7 @@ symbols! {
mul_assign,
mul_with_overflow,
multiple_supertrait_upcastable,
multivalue,
must_not_suspend,
must_use,
mut_preserve_binding_mode_2024,
Expand Down
Loading
Loading