From 482a3d06c3d1f83761bf3c94e1bad4fac7d32db4 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 1 Apr 2021 16:08:29 -0700 Subject: [PATCH] rustc: Add a new `wasm` ABI This commit implements the idea of a new ABI for the WebAssembly target, one called `"wasm"`. This ABI is entirely of my own invention and has no current precedent, but I think that the addition of this ABI might help solve a number of issues with the WebAssembly targets. When `wasm32-unknown-unknown` was first added to Rust I naively "implemented an abi" for the target. I then went to write `wasm-bindgen` which accidentally relied on details of this ABI. Turns out the ABI definition didn't match C, which is causing issues for C/Rust interop. Currently the compiler has a "wasm32 bindgen compat" ABI which is the original implementation I added, and it's purely there for, well, `wasm-bindgen`. Another issue with the WebAssembly target is that it's not clear to me when and if the default C ABI will change to account for WebAssembly's multi-value feature (a feature that allows functions to return multiple values). Even if this does happen, though, it seems like the C ABI will be guided based on the performance of WebAssembly code and will likely not match even what the current wasm-bindgen-compat ABI is today. This leaves a hole in Rust's expressivity in binding WebAssembly where given a particular import type, Rust may not be able to import that signature with an updated C ABI for multi-value. To fix these issues I had the idea of a new ABI for WebAssembly, one called `wasm`. The definition of this ABI is "what you write maps straight to wasm". The goal here is that whatever you write down in the parameter list or in the return values goes straight into the function's signature in the WebAssembly file. This special ABI is for intentionally matching the ABI of an imported function from the environment or exporting a function with the right signature. With the addition of a new ABI, this enables rustc to: * Eventually remove the "wasm-bindgen compat hack". Once this ABI is stable wasm-bindgen can switch to using it everywhere. Afterwards the wasm32-unknown-unknown target can have its default ABI updated to match C. * Expose the ability to precisely match an ABI signature for a WebAssembly function, regardless of what the C ABI that clang chooses turns out to be. * Continue to evolve the definition of the default C ABI to match what clang does on all targets, since the purpose of that ABI will be explicitly matching C rather than generating particular function imports/exports. Naturally this is implemented as an unstable feature initially, but it would be nice for this to get stabilized (if it works) in the near-ish future to remove the wasm32-unknown-unknown incompatibility with the C ABI. Doing this, however, requires the feature to be on stable because wasm-bindgen works with stable Rust. --- compiler/rustc_ast_passes/src/feature_gate.rs | 8 + compiler/rustc_codegen_llvm/src/attributes.rs | 44 ++-- compiler/rustc_feature/src/active.rs | 3 + compiler/rustc_middle/src/ty/layout.rs | 2 + compiler/rustc_mir_build/src/build/mod.rs | 1 + compiler/rustc_span/src/symbol.rs | 1 + compiler/rustc_target/src/abi/call/mod.rs | 18 +- .../src/abi/call/{wasm32.rs => wasm.rs} | 27 ++- .../src/abi/call/wasm32_bindgen_compat.rs | 29 --- compiler/rustc_target/src/abi/call/wasm64.rs | 58 ------ compiler/rustc_target/src/spec/abi.rs | 15 +- compiler/rustc_target/src/spec/mod.rs | 22 ++ .../src/spec/wasm32_unknown_unknown.rs | 12 ++ .../host-x86_64/test-various/Dockerfile | 4 +- src/test/run-make/wasm-abi/Makefile | 7 + src/test/run-make/wasm-abi/foo.js | 22 ++ src/test/run-make/wasm-abi/foo.rs | 87 ++++++++ src/test/ui/codemap_tests/unicode.stderr | 2 +- src/test/ui/feature-gates/feature-gate-abi.rs | 25 ++- .../ui/feature-gates/feature-gate-abi.stderr | 195 ++++++++++++------ .../ui/feature-gates/feature-gate-wasm_abi.rs | 7 + .../feature-gate-wasm_abi.stderr | 12 ++ src/test/ui/parser/issue-8537.stderr | 2 +- 23 files changed, 405 insertions(+), 198 deletions(-) rename compiler/rustc_target/src/abi/call/{wasm32.rs => wasm.rs} (66%) delete mode 100644 compiler/rustc_target/src/abi/call/wasm32_bindgen_compat.rs delete mode 100644 compiler/rustc_target/src/abi/call/wasm64.rs create mode 100644 src/test/run-make/wasm-abi/Makefile create mode 100644 src/test/run-make/wasm-abi/foo.js create mode 100644 src/test/run-make/wasm-abi/foo.rs create mode 100644 src/test/ui/feature-gates/feature-gate-wasm_abi.rs create mode 100644 src/test/ui/feature-gates/feature-gate-wasm_abi.stderr diff --git a/compiler/rustc_ast_passes/src/feature_gate.rs b/compiler/rustc_ast_passes/src/feature_gate.rs index 3724438cc6ed2..87c4bfae1af23 100644 --- a/compiler/rustc_ast_passes/src/feature_gate.rs +++ b/compiler/rustc_ast_passes/src/feature_gate.rs @@ -196,6 +196,14 @@ impl<'a> PostExpansionVisitor<'a> { "thiscall-unwind ABI is experimental and subject to change" ); } + "wasm" => { + gate_feature_post!( + &self, + wasm_abi, + span, + "wasm ABI is experimental and subject to change" + ); + } abi => self .sess .parse_sess diff --git a/compiler/rustc_codegen_llvm/src/attributes.rs b/compiler/rustc_codegen_llvm/src/attributes.rs index e06c1c825f6eb..9e5e2b1039efe 100644 --- a/compiler/rustc_codegen_llvm/src/attributes.rs +++ b/compiler/rustc_codegen_llvm/src/attributes.rs @@ -13,6 +13,7 @@ use rustc_middle::ty::query::Providers; use rustc_middle::ty::{self, TyCtxt}; use rustc_session::config::OptLevel; use rustc_session::Session; +use rustc_target::spec::abi::Abi; use rustc_target::spec::{SanitizerSet, StackProbeType}; use crate::attributes; @@ -293,7 +294,7 @@ pub fn from_fn_attrs(cx: &CodegenCx<'ll, 'tcx>, llfn: &'ll Value, instance: ty:: // The target doesn't care; the subtarget reads our attribute. apply_tune_cpu_attr(cx, llfn); - let function_features = codegen_fn_attrs + let mut function_features = codegen_fn_attrs .target_features .iter() .map(|f| { @@ -305,23 +306,10 @@ pub fn from_fn_attrs(cx: &CodegenCx<'ll, 'tcx>, llfn: &'ll Value, instance: ty:: InstructionSetAttr::ArmT32 => "+thumb-mode".to_string(), })) .collect::>(); - if !function_features.is_empty() { - let mut global_features = llvm_util::llvm_global_features(cx.tcx.sess); - global_features.extend(function_features.into_iter()); - let features = global_features.join(","); - let val = CString::new(features).unwrap(); - llvm::AddFunctionAttrStringValue( - llfn, - llvm::AttributePlace::Function, - cstr!("target-features"), - &val, - ); - } - // Note that currently the `wasm-import-module` doesn't do anything, but - // eventually LLVM 7 should read this and ferry the appropriate import - // module to the output file. if cx.tcx.sess.target.is_like_wasm { + // If this function is an import from the environment but the wasm + // import has a specific module/name, apply them here. if let Some(module) = wasm_import_module(cx.tcx, instance.def_id()) { llvm::AddFunctionAttrStringValue( llfn, @@ -340,6 +328,30 @@ pub fn from_fn_attrs(cx: &CodegenCx<'ll, 'tcx>, llfn: &'ll Value, instance: ty:: &name, ); } + + // The `"wasm"` abi on wasm targets automatically enables the + // `+multivalue` feature because the purpose of the wasm abi is to match + // the WebAssembly specification, which has this feature. This won't be + // needed when LLVM enables this `multivalue` feature by default. + if !cx.tcx.is_closure(instance.def_id()) { + let abi = cx.tcx.fn_sig(instance.def_id()).abi(); + if abi == Abi::Wasm { + function_features.push("+multivalue".to_string()); + } + } + } + + if !function_features.is_empty() { + let mut global_features = llvm_util::llvm_global_features(cx.tcx.sess); + global_features.extend(function_features.into_iter()); + let features = global_features.join(","); + let val = CString::new(features).unwrap(); + llvm::AddFunctionAttrStringValue( + llfn, + llvm::AttributePlace::Function, + cstr!("target-features"), + &val, + ); } } diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs index 93de4891ec7d2..1a91eb600a91b 100644 --- a/compiler/rustc_feature/src/active.rs +++ b/compiler/rustc_feature/src/active.rs @@ -645,6 +645,9 @@ declare_features! ( /// Allows using `#[repr(align(...))]` on function items (active, fn_align, "1.53.0", Some(82232), None), + /// Allows `extern "wasm" fn` + (active, wasm_abi, "1.53.0", Some(83788), None), + // ------------------------------------------------------------------------- // feature-group-end: actual feature gates // ------------------------------------------------------------------------- diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index e7bbdc3ccebdf..c2e9dba6c8e8a 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -2630,6 +2630,7 @@ fn fn_can_unwind( | AvrInterrupt | AvrNonBlockingInterrupt | CCmseNonSecureCall + | Wasm | RustIntrinsic | PlatformIntrinsic | Unadjusted => false, @@ -2712,6 +2713,7 @@ where AmdGpuKernel => Conv::AmdGpuKernel, AvrInterrupt => Conv::AvrInterrupt, AvrNonBlockingInterrupt => Conv::AvrNonBlockingInterrupt, + Wasm => Conv::C, // These API constants ought to be more specific... Cdecl => Conv::C, diff --git a/compiler/rustc_mir_build/src/build/mod.rs b/compiler/rustc_mir_build/src/build/mod.rs index c90f94c6d63fb..3a189e6b33dda 100644 --- a/compiler/rustc_mir_build/src/build/mod.rs +++ b/compiler/rustc_mir_build/src/build/mod.rs @@ -609,6 +609,7 @@ fn should_abort_on_panic(tcx: TyCtxt<'_>, fn_def_id: LocalDefId, abi: Abi) -> bo | AvrInterrupt | AvrNonBlockingInterrupt | CCmseNonSecureCall + | Wasm | RustIntrinsic | PlatformIntrinsic | Unadjusted => true, diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 03fe5bcd2971b..ee1d206095e5d 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1295,6 +1295,7 @@ symbols! { vreg, vreg_low16, warn, + wasm_abi, wasm_import_module, wasm_target_feature, while_let, diff --git a/compiler/rustc_target/src/abi/call/mod.rs b/compiler/rustc_target/src/abi/call/mod.rs index 395235399ea86..d9d7d467d9294 100644 --- a/compiler/rustc_target/src/abi/call/mod.rs +++ b/compiler/rustc_target/src/abi/call/mod.rs @@ -18,9 +18,7 @@ mod riscv; mod s390x; mod sparc; mod sparc64; -mod wasm32; -mod wasm32_bindgen_compat; -mod wasm64; +mod wasm; mod x86; mod x86_64; mod x86_win64; @@ -648,12 +646,14 @@ impl<'a, Ty> FnAbi<'a, Ty> { "nvptx64" => nvptx64::compute_abi_info(self), "hexagon" => hexagon::compute_abi_info(self), "riscv32" | "riscv64" => riscv::compute_abi_info(cx, self), - "wasm32" => match cx.target_spec().os.as_str() { - "emscripten" | "wasi" => wasm32::compute_abi_info(cx, self), - _ => wasm32_bindgen_compat::compute_abi_info(self), - }, - "asmjs" => wasm32::compute_abi_info(cx, self), - "wasm64" => wasm64::compute_abi_info(cx, self), + "wasm32" | "wasm64" => { + if cx.target_spec().adjust_abi(abi) == spec::abi::Abi::Wasm { + wasm::compute_wasm_abi_info(self) + } else { + wasm::compute_c_abi_info(cx, self) + } + } + "asmjs" => wasm::compute_c_abi_info(cx, self), a => return Err(format!("unrecognized arch \"{}\" in target specification", a)), } diff --git a/compiler/rustc_target/src/abi/call/wasm32.rs b/compiler/rustc_target/src/abi/call/wasm.rs similarity index 66% rename from compiler/rustc_target/src/abi/call/wasm32.rs rename to compiler/rustc_target/src/abi/call/wasm.rs index ff2c0e9bb6fcc..bf2c08bb1662d 100644 --- a/compiler/rustc_target/src/abi/call/wasm32.rs +++ b/compiler/rustc_target/src/abi/call/wasm.rs @@ -40,7 +40,8 @@ where } } -pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) +/// The purpose of this ABI is to match the C ABI (aka clang) exactly. +pub fn compute_c_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) where Ty: TyAndLayoutMethods<'a, C> + Copy, C: LayoutOf> + HasDataLayout, @@ -56,3 +57,27 @@ where classify_arg(cx, arg); } } + +/// The purpose of this ABI is for matching the WebAssembly standard. This +/// intentionally diverges from the C ABI and is specifically crafted to take +/// advantage of LLVM's support of multiple returns in WebAssembly. +pub fn compute_wasm_abi_info(fn_abi: &mut FnAbi<'_, Ty>) { + if !fn_abi.ret.is_ignore() { + classify_ret(&mut fn_abi.ret); + } + + for arg in &mut fn_abi.args { + if arg.is_ignore() { + continue; + } + classify_arg(arg); + } + + fn classify_ret(ret: &mut ArgAbi<'_, Ty>) { + ret.extend_integer_width_to(32); + } + + fn classify_arg(arg: &mut ArgAbi<'_, Ty>) { + arg.extend_integer_width_to(32); + } +} diff --git a/compiler/rustc_target/src/abi/call/wasm32_bindgen_compat.rs b/compiler/rustc_target/src/abi/call/wasm32_bindgen_compat.rs deleted file mode 100644 index 59571fd9d4821..0000000000000 --- a/compiler/rustc_target/src/abi/call/wasm32_bindgen_compat.rs +++ /dev/null @@ -1,29 +0,0 @@ -// This is not and has never been a correct C ABI for WebAssembly, but -// for a long time this was the C ABI that Rust used. wasm-bindgen -// depends on ABI details for this ABI and is incompatible with the -// correct C ABI, so this ABI is being kept around until wasm-bindgen -// can be fixed to work with the correct ABI. See #63649 for further -// discussion. - -use crate::abi::call::{ArgAbi, FnAbi}; - -fn classify_ret(ret: &mut ArgAbi<'_, Ty>) { - ret.extend_integer_width_to(32); -} - -fn classify_arg(arg: &mut ArgAbi<'_, Ty>) { - arg.extend_integer_width_to(32); -} - -pub fn compute_abi_info(fn_abi: &mut FnAbi<'_, Ty>) { - if !fn_abi.ret.is_ignore() { - classify_ret(&mut fn_abi.ret); - } - - for arg in &mut fn_abi.args { - if arg.is_ignore() { - continue; - } - classify_arg(arg); - } -} diff --git a/compiler/rustc_target/src/abi/call/wasm64.rs b/compiler/rustc_target/src/abi/call/wasm64.rs deleted file mode 100644 index 46d670d168949..0000000000000 --- a/compiler/rustc_target/src/abi/call/wasm64.rs +++ /dev/null @@ -1,58 +0,0 @@ -use crate::abi::call::{ArgAbi, FnAbi, Uniform}; -use crate::abi::{HasDataLayout, LayoutOf, TyAndLayout, TyAndLayoutMethods}; - -fn unwrap_trivial_aggregate<'a, Ty, C>(cx: &C, val: &mut ArgAbi<'a, Ty>) -> bool -where - Ty: TyAndLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, -{ - if val.layout.is_aggregate() { - if let Some(unit) = val.layout.homogeneous_aggregate(cx).ok().and_then(|ha| ha.unit()) { - let size = val.layout.size; - if unit.size == size { - val.cast_to(Uniform { unit, total: size }); - return true; - } - } - } - false -} - -fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>) -where - Ty: TyAndLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, -{ - ret.extend_integer_width_to(64); - if ret.layout.is_aggregate() && !unwrap_trivial_aggregate(cx, ret) { - ret.make_indirect(); - } -} - -fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) -where - Ty: TyAndLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, -{ - arg.extend_integer_width_to(64); - if arg.layout.is_aggregate() && !unwrap_trivial_aggregate(cx, arg) { - arg.make_indirect_byval(); - } -} - -pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) -where - Ty: TyAndLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, -{ - if !fn_abi.ret.is_ignore() { - classify_ret(cx, &mut fn_abi.ret); - } - - for arg in &mut fn_abi.args { - if arg.is_ignore() { - continue; - } - classify_arg(cx, arg); - } -} diff --git a/compiler/rustc_target/src/spec/abi.rs b/compiler/rustc_target/src/spec/abi.rs index 17eb33b8f2eaa..a026a623f7866 100644 --- a/compiler/rustc_target/src/spec/abi.rs +++ b/compiler/rustc_target/src/spec/abi.rs @@ -34,6 +34,7 @@ pub enum Abi { AvrInterrupt, AvrNonBlockingInterrupt, CCmseNonSecureCall, + Wasm, // Multiplatform / generic ABIs System { unwind: bool }, @@ -83,6 +84,7 @@ const AbiDatas: &[AbiData] = &[ generic: false, }, AbiData { abi: Abi::CCmseNonSecureCall, name: "C-cmse-nonsecure-call", generic: false }, + AbiData { abi: Abi::Wasm, name: "wasm", generic: false }, // Cross-platform ABIs AbiData { abi: Abi::System { unwind: false }, name: "system", generic: true }, AbiData { abi: Abi::System { unwind: true }, name: "system-unwind", generic: true }, @@ -131,13 +133,14 @@ impl Abi { AvrInterrupt => 18, AvrNonBlockingInterrupt => 19, CCmseNonSecureCall => 20, + Wasm => 21, // Cross-platform ABIs - System { unwind: false } => 21, - System { unwind: true } => 22, - RustIntrinsic => 23, - RustCall => 24, - PlatformIntrinsic => 25, - Unadjusted => 26, + System { unwind: false } => 22, + System { unwind: true } => 23, + RustIntrinsic => 24, + RustCall => 25, + PlatformIntrinsic => 26, + Unadjusted => 27, }; debug_assert!( AbiDatas diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index 801cdd3ebe924..57b0a36e009ef 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -1254,6 +1254,9 @@ pub struct TargetOptions { /// enabled can generated on this target, but the necessary supporting libraries are not /// distributed with the target, the sanitizer should still appear in this list for the target. pub supported_sanitizers: SanitizerSet, + + /// If present it's a default value to use for adjusting the C ABI. + pub default_adjusted_cabi: Option, } impl Default for TargetOptions { @@ -1357,6 +1360,7 @@ impl Default for TargetOptions { has_thumb_interworking: false, split_debuginfo: SplitDebuginfo::Off, supported_sanitizers: SanitizerSet::empty(), + default_adjusted_cabi: None, } } } @@ -1408,6 +1412,9 @@ impl Target { Abi::C { unwind: false } } } + + Abi::C { unwind } => self.default_adjusted_cabi.unwrap_or(Abi::C { unwind }), + abi => abi, } } @@ -1742,6 +1749,16 @@ impl Target { } } } ); + ($key_name:ident, Option) => ( { + let name = (stringify!($key_name)).replace("_", "-"); + obj.find(&name[..]).and_then(|o| o.as_string().and_then(|s| { + match lookup_abi(s) { + Some(abi) => base.$key_name = Some(abi), + _ => return Some(Err(format!("'{}' is not a valid value for abi", s))), + } + Some(Ok(())) + })).unwrap_or(Ok(())) + } ); } if let Some(s) = obj.find("target-endian").and_then(Json::as_string) { @@ -1841,6 +1858,7 @@ impl Target { key!(has_thumb_interworking, bool); key!(split_debuginfo, SplitDebuginfo)?; key!(supported_sanitizers, SanitizerSet)?; + key!(default_adjusted_cabi, Option)?; // NB: The old name is deprecated, but support for it is retained for // compatibility. @@ -2081,6 +2099,10 @@ impl ToJson for Target { target_option_val!(split_debuginfo); target_option_val!(supported_sanitizers); + if let Some(abi) = self.default_adjusted_cabi { + d.insert("default-adjusted-cabi".to_string(), Abi::name(abi).to_json()); + } + if default.unsupported_abis != self.unsupported_abis { d.insert( "unsupported-abis".to_string(), diff --git a/compiler/rustc_target/src/spec/wasm32_unknown_unknown.rs b/compiler/rustc_target/src/spec/wasm32_unknown_unknown.rs index 0a88ee426297b..834c4dbfc05f6 100644 --- a/compiler/rustc_target/src/spec/wasm32_unknown_unknown.rs +++ b/compiler/rustc_target/src/spec/wasm32_unknown_unknown.rs @@ -12,11 +12,23 @@ use super::wasm_base; use super::{LinkerFlavor, LldFlavor, Target}; +use crate::spec::abi::Abi; pub fn target() -> Target { let mut options = wasm_base::options(); options.os = "unknown".to_string(); options.linker_flavor = LinkerFlavor::Lld(LldFlavor::Wasm); + + // This is a default for backwards-compatibility with the original + // definition of this target oh-so-long-ago. Once the "wasm" ABI is + // stable and the wasm-bindgen project has switched to using it then there's + // no need for this and it can be removed. + // + // Currently this is the reason that this target's ABI is mismatched with + // clang's ABI. This means that, in the limit, you can't merge C and Rust + // code on this target due to this ABI mismatch. + options.default_adjusted_cabi = Some(Abi::Wasm); + let clang_args = options.pre_link_args.entry(LinkerFlavor::Gcc).or_default(); // Make sure clang uses LLD as its linker and is configured appropriately diff --git a/src/ci/docker/host-x86_64/test-various/Dockerfile b/src/ci/docker/host-x86_64/test-various/Dockerfile index f5fe546cdc6b5..ad0e8e9f92808 100644 --- a/src/ci/docker/host-x86_64/test-various/Dockerfile +++ b/src/ci/docker/host-x86_64/test-various/Dockerfile @@ -18,7 +18,7 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-ins wget \ patch -RUN curl -sL https://nodejs.org/dist/v14.4.0/node-v14.4.0-linux-x64.tar.xz | \ +RUN curl -sL https://nodejs.org/dist/v15.14.0/node-v15.14.0-linux-x64.tar.xz | \ tar -xJ WORKDIR /build/ @@ -31,7 +31,7 @@ RUN sh /scripts/sccache.sh ENV RUST_CONFIGURE_ARGS \ --musl-root-x86_64=/usr/local/x86_64-linux-musl \ - --set build.nodejs=/node-v14.4.0-linux-x64/bin/node \ + --set build.nodejs=/node-v15.14.0-linux-x64/bin/node \ --set rust.lld # Some run-make tests have assertions about code size, and enabling debug diff --git a/src/test/run-make/wasm-abi/Makefile b/src/test/run-make/wasm-abi/Makefile new file mode 100644 index 0000000000000..61fc4e8f57fb8 --- /dev/null +++ b/src/test/run-make/wasm-abi/Makefile @@ -0,0 +1,7 @@ +-include ../../run-make-fulldeps/tools.mk + +# only-wasm32-bare + +all: + $(RUSTC) foo.rs --target wasm32-unknown-unknown + $(NODE) foo.js $(TMPDIR)/foo.wasm diff --git a/src/test/run-make/wasm-abi/foo.js b/src/test/run-make/wasm-abi/foo.js new file mode 100644 index 0000000000000..9e9a65401af81 --- /dev/null +++ b/src/test/run-make/wasm-abi/foo.js @@ -0,0 +1,22 @@ +const fs = require('fs'); +const process = require('process'); +const assert = require('assert'); +const buffer = fs.readFileSync(process.argv[2]); + +const m = new WebAssembly.Module(buffer); +const i = new WebAssembly.Instance(m, { + host: { + two_i32: () => [100, 101], + two_i64: () => [102n, 103n], + two_f32: () => [104, 105], + two_f64: () => [106, 107], + mishmash: () => [108, 109, 110, 111n, 112, 113], + } +}); + +assert.deepEqual(i.exports.return_two_i32(), [1, 2]) +assert.deepEqual(i.exports.return_two_i64(), [3, 4]) +assert.deepEqual(i.exports.return_two_f32(), [5, 6]) +assert.deepEqual(i.exports.return_two_f64(), [7, 8]) +assert.deepEqual(i.exports.return_mishmash(), [9, 10, 11, 12, 13, 14]) +i.exports.call_imports(); diff --git a/src/test/run-make/wasm-abi/foo.rs b/src/test/run-make/wasm-abi/foo.rs new file mode 100644 index 0000000000000..0678eb3ff51ae --- /dev/null +++ b/src/test/run-make/wasm-abi/foo.rs @@ -0,0 +1,87 @@ +#![crate_type = "cdylib"] +#![deny(warnings)] +#![feature(wasm_abi)] + +#[repr(C)] +#[derive(PartialEq, Debug)] +pub struct TwoI32 { + pub a: i32, + pub b: i32, +} + +#[no_mangle] +pub extern "wasm" fn return_two_i32() -> TwoI32 { + TwoI32 { a: 1, b: 2 } +} + +#[repr(C)] +#[derive(PartialEq, Debug)] +pub struct TwoI64 { + pub a: i64, + pub b: i64, +} + +#[no_mangle] +pub extern "wasm" fn return_two_i64() -> TwoI64 { + TwoI64 { a: 3, b: 4 } +} + +#[repr(C)] +#[derive(PartialEq, Debug)] +pub struct TwoF32 { + pub a: f32, + pub b: f32, +} + +#[no_mangle] +pub extern "wasm" fn return_two_f32() -> TwoF32 { + TwoF32 { a: 5., b: 6. } +} + +#[repr(C)] +#[derive(PartialEq, Debug)] +pub struct TwoF64 { + pub a: f64, + pub b: f64, +} + +#[no_mangle] +pub extern "wasm" fn return_two_f64() -> TwoF64 { + TwoF64 { a: 7., b: 8. } +} + +#[repr(C)] +#[derive(PartialEq, Debug)] +pub struct Mishmash { + pub a: f64, + pub b: f32, + pub c: i32, + pub d: i64, + pub e: TwoI32, +} + +#[no_mangle] +pub extern "wasm" fn return_mishmash() -> Mishmash { + Mishmash { a: 9., b: 10., c: 11, d: 12, e: TwoI32 { a: 13, b: 14 } } +} + +#[link(wasm_import_module = "host")] +extern "wasm" { + fn two_i32() -> TwoI32; + fn two_i64() -> TwoI64; + fn two_f32() -> TwoF32; + fn two_f64() -> TwoF64; + fn mishmash() -> Mishmash; +} + +#[no_mangle] +pub unsafe extern "C" fn call_imports() { + assert_eq!(two_i32(), TwoI32 { a: 100, b: 101 }); + assert_eq!(two_i64(), TwoI64 { a: 102, b: 103 }); + assert_eq!(two_f32(), TwoF32 { a: 104., b: 105. }); + assert_eq!(two_f64(), TwoF64 { a: 106., b: 107. }); + assert_eq!( + mishmash(), + Mishmash { a: 108., b: 109., c: 110, d: 111, e: TwoI32 { a: 112, b: 113 } } + ); +} diff --git a/src/test/ui/codemap_tests/unicode.stderr b/src/test/ui/codemap_tests/unicode.stderr index b7ba4fa46d92b..357dd25389ecb 100644 --- a/src/test/ui/codemap_tests/unicode.stderr +++ b/src/test/ui/codemap_tests/unicode.stderr @@ -4,7 +4,7 @@ error[E0703]: invalid ABI: found `路濫狼á́́` LL | extern "路濫狼á́́" fn foo() {} | ^^^^^^^^^ invalid ABI | - = help: valid ABIs: Rust, C, C-unwind, cdecl, stdcall, stdcall-unwind, fastcall, vectorcall, thiscall, thiscall-unwind, aapcs, win64, sysv64, ptx-kernel, msp430-interrupt, x86-interrupt, amdgpu-kernel, efiapi, avr-interrupt, avr-non-blocking-interrupt, C-cmse-nonsecure-call, system, system-unwind, rust-intrinsic, rust-call, platform-intrinsic, unadjusted + = help: valid ABIs: Rust, C, C-unwind, cdecl, stdcall, stdcall-unwind, fastcall, vectorcall, thiscall, thiscall-unwind, aapcs, win64, sysv64, ptx-kernel, msp430-interrupt, x86-interrupt, amdgpu-kernel, efiapi, avr-interrupt, avr-non-blocking-interrupt, C-cmse-nonsecure-call, wasm, system, system-unwind, rust-intrinsic, rust-call, platform-intrinsic, unadjusted error: aborting due to previous error diff --git a/src/test/ui/feature-gates/feature-gate-abi.rs b/src/test/ui/feature-gates/feature-gate-abi.rs index 3883106a3af95..49cf2e158edfc 100644 --- a/src/test/ui/feature-gates/feature-gate-abi.rs +++ b/src/test/ui/feature-gates/feature-gate-abi.rs @@ -10,9 +10,9 @@ // Functions extern "rust-intrinsic" fn f1() {} //~ ERROR intrinsics are subject to change -//~^ ERROR intrinsic must be in + //~^ ERROR intrinsic must be in extern "platform-intrinsic" fn f2() {} //~ ERROR platform intrinsics are experimental -//~^ ERROR intrinsic must be in + //~^ ERROR intrinsic must be in extern "vectorcall" fn f3() {} //~ ERROR vectorcall is experimental and subject to change extern "rust-call" fn f4(_: ()) {} //~ ERROR rust-call ABI is subject to change extern "msp430-interrupt" fn f5() {} //~ ERROR msp430-interrupt ABI is experimental @@ -21,13 +21,14 @@ 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 "efiapi" fn f10() {} //~ ERROR efiapi ABI is experimental and subject to change +extern "wasm" fn f11() {} //~ ERROR wasm ABI is experimental and subject to change // Methods in trait definition trait Tr { extern "rust-intrinsic" fn m1(); //~ ERROR intrinsics are subject to change - //~^ ERROR intrinsic must be in + //~^ ERROR intrinsic must be in extern "platform-intrinsic" fn m2(); //~ ERROR platform intrinsics are experimental - //~^ ERROR intrinsic must be in + //~^ ERROR intrinsic must be in extern "vectorcall" fn m3(); //~ ERROR vectorcall is experimental and subject to change extern "rust-call" fn m4(_: ()); //~ ERROR rust-call ABI is subject to change extern "msp430-interrupt" fn m5(); //~ ERROR msp430-interrupt ABI is experimental @@ -36,6 +37,7 @@ trait Tr { 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 "efiapi" fn m10(); //~ ERROR efiapi ABI is experimental and subject to change + extern "wasm" fn m11() {} //~ ERROR wasm 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 @@ -45,6 +47,7 @@ trait Tr { 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 "efiapi" fn dm10() {} //~ ERROR efiapi ABI is experimental and subject to change + extern "wasm" fn dm11() {} //~ ERROR wasm ABI is experimental and subject to change } struct S; @@ -52,9 +55,9 @@ struct S; // Methods in trait impl impl Tr for S { extern "rust-intrinsic" fn m1() {} //~ ERROR intrinsics are subject to change - //~^ ERROR intrinsic must be in + //~^ ERROR intrinsic must be in extern "platform-intrinsic" fn m2() {} //~ ERROR platform intrinsics are experimental - //~^ ERROR intrinsic must be in + //~^ ERROR intrinsic must be in extern "vectorcall" fn m3() {} //~ ERROR vectorcall is experimental and subject to change extern "rust-call" fn m4(_: ()) {} //~ ERROR rust-call ABI is subject to change extern "msp430-interrupt" fn m5() {} //~ ERROR msp430-interrupt ABI is experimental @@ -63,14 +66,15 @@ impl Tr for S { 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 "efiapi" fn m10() {} //~ ERROR efiapi ABI is experimental and subject to change + extern "wasm" fn m11() {} //~ ERROR wasm ABI is experimental and subject to change } // Methods in inherent impl impl S { extern "rust-intrinsic" fn im1() {} //~ ERROR intrinsics are subject to change - //~^ ERROR intrinsic must be in + //~^ ERROR intrinsic must be in extern "platform-intrinsic" fn im2() {} //~ ERROR platform intrinsics are experimental - //~^ ERROR intrinsic must be in + //~^ ERROR intrinsic must be in extern "vectorcall" fn im3() {} //~ ERROR vectorcall is experimental and subject to change extern "rust-call" fn im4(_: ()) {} //~ ERROR rust-call ABI is subject to change extern "msp430-interrupt" fn im5() {} //~ ERROR msp430-interrupt ABI is experimental @@ -79,6 +83,7 @@ impl S { 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 "efiapi" fn im10() {} //~ ERROR efiapi ABI is experimental and subject to change + extern "wasm" fn im11() {} //~ ERROR wasm ABI is experimental and subject to change } // Function pointer types @@ -87,11 +92,12 @@ type A2 = extern "platform-intrinsic" fn(); //~ ERROR platform intrinsics are ex type A3 = extern "vectorcall" fn(); //~ ERROR vectorcall is experimental and subject to change type A4 = extern "rust-call" fn(_: ()); //~ ERROR rust-call ABI is subject to change type A5 = extern "msp430-interrupt" fn(); //~ ERROR msp430-interrupt ABI is experimental -type A6 = extern "ptx-kernel" fn (); //~ ERROR PTX ABIs are experimental and subject to change +type A6 = extern "ptx-kernel" fn(); //~ ERROR PTX ABIs are experimental and subject to change 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 "efiapi" fn(); //~ ERROR efiapi ABI is experimental and subject to change +type A11 = extern "wasm" fn(); //~ ERROR wasm ABI is experimental and subject to change // Foreign modules extern "rust-intrinsic" {} //~ ERROR intrinsics are subject to change @@ -104,5 +110,6 @@ 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 "efiapi" {} //~ ERROR efiapi ABI is experimental and subject to change +extern "wasm" {} //~ ERROR wasm ABI is experimental and subject to change fn main() {} diff --git a/src/test/ui/feature-gates/feature-gate-abi.stderr b/src/test/ui/feature-gates/feature-gate-abi.stderr index eeeb349c66277..078d21ad36f90 100644 --- a/src/test/ui/feature-gates/feature-gate-abi.stderr +++ b/src/test/ui/feature-gates/feature-gate-abi.stderr @@ -85,8 +85,17 @@ LL | extern "efiapi" fn f10() {} = note: see issue #65815 for more information = help: add `#![feature(abi_efiapi)]` to the crate attributes to enable +error[E0658]: wasm ABI is experimental and subject to change + --> $DIR/feature-gate-abi.rs:24:8 + | +LL | extern "wasm" fn f11() {} + | ^^^^^^ + | + = note: see issue #83788 for more information + = help: add `#![feature(wasm_abi)]` to the crate attributes to enable + error[E0658]: intrinsics are subject to change - --> $DIR/feature-gate-abi.rs:27:12 + --> $DIR/feature-gate-abi.rs:28:12 | LL | extern "rust-intrinsic" fn m1(); | ^^^^^^^^^^^^^^^^ @@ -94,7 +103,7 @@ LL | extern "rust-intrinsic" fn m1(); = help: add `#![feature(intrinsics)]` to the crate attributes to enable error[E0658]: platform intrinsics are experimental and possibly buggy - --> $DIR/feature-gate-abi.rs:29:12 + --> $DIR/feature-gate-abi.rs:30:12 | LL | extern "platform-intrinsic" fn m2(); | ^^^^^^^^^^^^^^^^^^^^ @@ -103,7 +112,7 @@ LL | extern "platform-intrinsic" fn m2(); = help: add `#![feature(platform_intrinsics)]` to the crate attributes to enable error[E0658]: vectorcall is experimental and subject to change - --> $DIR/feature-gate-abi.rs:31:12 + --> $DIR/feature-gate-abi.rs:32:12 | LL | extern "vectorcall" fn m3(); | ^^^^^^^^^^^^ @@ -111,7 +120,7 @@ LL | extern "vectorcall" fn m3(); = help: add `#![feature(abi_vectorcall)]` to the crate attributes to enable error[E0658]: rust-call ABI is subject to change - --> $DIR/feature-gate-abi.rs:32:12 + --> $DIR/feature-gate-abi.rs:33:12 | LL | extern "rust-call" fn m4(_: ()); | ^^^^^^^^^^^ @@ -120,7 +129,7 @@ LL | extern "rust-call" fn m4(_: ()); = help: add `#![feature(unboxed_closures)]` to the crate attributes to enable error[E0658]: msp430-interrupt ABI is experimental and subject to change - --> $DIR/feature-gate-abi.rs:33:12 + --> $DIR/feature-gate-abi.rs:34:12 | LL | extern "msp430-interrupt" fn m5(); | ^^^^^^^^^^^^^^^^^^ @@ -129,7 +138,7 @@ LL | extern "msp430-interrupt" fn m5(); = help: add `#![feature(abi_msp430_interrupt)]` to the crate attributes to enable error[E0658]: PTX ABIs are experimental and subject to change - --> $DIR/feature-gate-abi.rs:34:12 + --> $DIR/feature-gate-abi.rs:35:12 | LL | extern "ptx-kernel" fn m6(); | ^^^^^^^^^^^^ @@ -138,7 +147,7 @@ LL | extern "ptx-kernel" fn m6(); = help: add `#![feature(abi_ptx)]` to the crate attributes to enable error[E0658]: x86-interrupt ABI is experimental and subject to change - --> $DIR/feature-gate-abi.rs:35:12 + --> $DIR/feature-gate-abi.rs:36:12 | LL | extern "x86-interrupt" fn m7(); | ^^^^^^^^^^^^^^^ @@ -147,7 +156,7 @@ LL | extern "x86-interrupt" fn m7(); = help: add `#![feature(abi_x86_interrupt)]` to the crate attributes to enable error[E0658]: thiscall is experimental and subject to change - --> $DIR/feature-gate-abi.rs:36:12 + --> $DIR/feature-gate-abi.rs:37:12 | LL | extern "thiscall" fn m8(); | ^^^^^^^^^^ @@ -155,7 +164,7 @@ LL | extern "thiscall" fn m8(); = help: add `#![feature(abi_thiscall)]` to the crate attributes to enable error[E0658]: amdgpu-kernel ABI is experimental and subject to change - --> $DIR/feature-gate-abi.rs:37:12 + --> $DIR/feature-gate-abi.rs:38:12 | LL | extern "amdgpu-kernel" fn m9(); | ^^^^^^^^^^^^^^^ @@ -164,7 +173,7 @@ LL | extern "amdgpu-kernel" fn m9(); = help: add `#![feature(abi_amdgpu_kernel)]` to the crate attributes to enable error[E0658]: efiapi ABI is experimental and subject to change - --> $DIR/feature-gate-abi.rs:38:12 + --> $DIR/feature-gate-abi.rs:39:12 | LL | extern "efiapi" fn m10(); | ^^^^^^^^ @@ -172,16 +181,25 @@ LL | extern "efiapi" fn m10(); = note: see issue #65815 for more information = help: add `#![feature(abi_efiapi)]` to the crate attributes to enable -error[E0658]: vectorcall is experimental and subject to change +error[E0658]: wasm ABI is experimental and subject to change --> $DIR/feature-gate-abi.rs:40:12 | +LL | extern "wasm" fn m11() {} + | ^^^^^^ + | + = note: see issue #83788 for more information + = help: add `#![feature(wasm_abi)]` to the crate attributes to enable + +error[E0658]: vectorcall is experimental and subject to change + --> $DIR/feature-gate-abi.rs:42:12 + | LL | extern "vectorcall" fn dm3() {} | ^^^^^^^^^^^^ | = help: add `#![feature(abi_vectorcall)]` to the crate attributes to enable error[E0658]: rust-call ABI is subject to change - --> $DIR/feature-gate-abi.rs:41:12 + --> $DIR/feature-gate-abi.rs:43:12 | LL | extern "rust-call" fn dm4(_: ()) {} | ^^^^^^^^^^^ @@ -190,7 +208,7 @@ LL | extern "rust-call" fn dm4(_: ()) {} = help: add `#![feature(unboxed_closures)]` to the crate attributes to enable error[E0658]: msp430-interrupt ABI is experimental and subject to change - --> $DIR/feature-gate-abi.rs:42:12 + --> $DIR/feature-gate-abi.rs:44:12 | LL | extern "msp430-interrupt" fn dm5() {} | ^^^^^^^^^^^^^^^^^^ @@ -199,7 +217,7 @@ LL | extern "msp430-interrupt" fn dm5() {} = help: add `#![feature(abi_msp430_interrupt)]` to the crate attributes to enable error[E0658]: PTX ABIs are experimental and subject to change - --> $DIR/feature-gate-abi.rs:43:12 + --> $DIR/feature-gate-abi.rs:45:12 | LL | extern "ptx-kernel" fn dm6() {} | ^^^^^^^^^^^^ @@ -208,7 +226,7 @@ LL | extern "ptx-kernel" fn dm6() {} = help: add `#![feature(abi_ptx)]` to the crate attributes to enable error[E0658]: x86-interrupt ABI is experimental and subject to change - --> $DIR/feature-gate-abi.rs:44:12 + --> $DIR/feature-gate-abi.rs:46:12 | LL | extern "x86-interrupt" fn dm7() {} | ^^^^^^^^^^^^^^^ @@ -217,7 +235,7 @@ LL | extern "x86-interrupt" fn dm7() {} = help: add `#![feature(abi_x86_interrupt)]` to the crate attributes to enable error[E0658]: thiscall is experimental and subject to change - --> $DIR/feature-gate-abi.rs:45:12 + --> $DIR/feature-gate-abi.rs:47:12 | LL | extern "thiscall" fn dm8() {} | ^^^^^^^^^^ @@ -225,7 +243,7 @@ LL | extern "thiscall" fn dm8() {} = help: add `#![feature(abi_thiscall)]` to the crate attributes to enable error[E0658]: amdgpu-kernel ABI is experimental and subject to change - --> $DIR/feature-gate-abi.rs:46:12 + --> $DIR/feature-gate-abi.rs:48:12 | LL | extern "amdgpu-kernel" fn dm9() {} | ^^^^^^^^^^^^^^^ @@ -234,7 +252,7 @@ LL | extern "amdgpu-kernel" fn dm9() {} = help: add `#![feature(abi_amdgpu_kernel)]` to the crate attributes to enable error[E0658]: efiapi ABI is experimental and subject to change - --> $DIR/feature-gate-abi.rs:47:12 + --> $DIR/feature-gate-abi.rs:49:12 | LL | extern "efiapi" fn dm10() {} | ^^^^^^^^ @@ -242,8 +260,17 @@ LL | extern "efiapi" fn dm10() {} = note: see issue #65815 for more information = help: add `#![feature(abi_efiapi)]` to the crate attributes to enable +error[E0658]: wasm ABI is experimental and subject to change + --> $DIR/feature-gate-abi.rs:50:12 + | +LL | extern "wasm" fn dm11() {} + | ^^^^^^ + | + = note: see issue #83788 for more information + = help: add `#![feature(wasm_abi)]` to the crate attributes to enable + error[E0658]: intrinsics are subject to change - --> $DIR/feature-gate-abi.rs:54:12 + --> $DIR/feature-gate-abi.rs:57:12 | LL | extern "rust-intrinsic" fn m1() {} | ^^^^^^^^^^^^^^^^ @@ -251,7 +278,7 @@ LL | extern "rust-intrinsic" fn m1() {} = help: add `#![feature(intrinsics)]` to the crate attributes to enable error[E0658]: platform intrinsics are experimental and possibly buggy - --> $DIR/feature-gate-abi.rs:56:12 + --> $DIR/feature-gate-abi.rs:59:12 | LL | extern "platform-intrinsic" fn m2() {} | ^^^^^^^^^^^^^^^^^^^^ @@ -260,7 +287,7 @@ LL | extern "platform-intrinsic" fn m2() {} = help: add `#![feature(platform_intrinsics)]` to the crate attributes to enable error[E0658]: vectorcall is experimental and subject to change - --> $DIR/feature-gate-abi.rs:58:12 + --> $DIR/feature-gate-abi.rs:61:12 | LL | extern "vectorcall" fn m3() {} | ^^^^^^^^^^^^ @@ -268,7 +295,7 @@ LL | extern "vectorcall" fn m3() {} = help: add `#![feature(abi_vectorcall)]` to the crate attributes to enable error[E0658]: rust-call ABI is subject to change - --> $DIR/feature-gate-abi.rs:59:12 + --> $DIR/feature-gate-abi.rs:62:12 | LL | extern "rust-call" fn m4(_: ()) {} | ^^^^^^^^^^^ @@ -277,7 +304,7 @@ LL | extern "rust-call" fn m4(_: ()) {} = help: add `#![feature(unboxed_closures)]` to the crate attributes to enable error[E0658]: msp430-interrupt ABI is experimental and subject to change - --> $DIR/feature-gate-abi.rs:60:12 + --> $DIR/feature-gate-abi.rs:63:12 | LL | extern "msp430-interrupt" fn m5() {} | ^^^^^^^^^^^^^^^^^^ @@ -286,7 +313,7 @@ LL | extern "msp430-interrupt" fn m5() {} = help: add `#![feature(abi_msp430_interrupt)]` to the crate attributes to enable error[E0658]: PTX ABIs are experimental and subject to change - --> $DIR/feature-gate-abi.rs:61:12 + --> $DIR/feature-gate-abi.rs:64:12 | LL | extern "ptx-kernel" fn m6() {} | ^^^^^^^^^^^^ @@ -295,7 +322,7 @@ LL | extern "ptx-kernel" fn m6() {} = help: add `#![feature(abi_ptx)]` to the crate attributes to enable error[E0658]: x86-interrupt ABI is experimental and subject to change - --> $DIR/feature-gate-abi.rs:62:12 + --> $DIR/feature-gate-abi.rs:65:12 | LL | extern "x86-interrupt" fn m7() {} | ^^^^^^^^^^^^^^^ @@ -304,7 +331,7 @@ LL | extern "x86-interrupt" fn m7() {} = help: add `#![feature(abi_x86_interrupt)]` to the crate attributes to enable error[E0658]: thiscall is experimental and subject to change - --> $DIR/feature-gate-abi.rs:63:12 + --> $DIR/feature-gate-abi.rs:66:12 | LL | extern "thiscall" fn m8() {} | ^^^^^^^^^^ @@ -312,7 +339,7 @@ LL | extern "thiscall" fn m8() {} = help: add `#![feature(abi_thiscall)]` to the crate attributes to enable error[E0658]: amdgpu-kernel ABI is experimental and subject to change - --> $DIR/feature-gate-abi.rs:64:12 + --> $DIR/feature-gate-abi.rs:67:12 | LL | extern "amdgpu-kernel" fn m9() {} | ^^^^^^^^^^^^^^^ @@ -321,7 +348,7 @@ LL | extern "amdgpu-kernel" fn m9() {} = help: add `#![feature(abi_amdgpu_kernel)]` to the crate attributes to enable error[E0658]: efiapi ABI is experimental and subject to change - --> $DIR/feature-gate-abi.rs:65:12 + --> $DIR/feature-gate-abi.rs:68:12 | LL | extern "efiapi" fn m10() {} | ^^^^^^^^ @@ -329,8 +356,17 @@ LL | extern "efiapi" fn m10() {} = note: see issue #65815 for more information = help: add `#![feature(abi_efiapi)]` to the crate attributes to enable +error[E0658]: wasm ABI is experimental and subject to change + --> $DIR/feature-gate-abi.rs:69:12 + | +LL | extern "wasm" fn m11() {} + | ^^^^^^ + | + = note: see issue #83788 for more information + = help: add `#![feature(wasm_abi)]` to the crate attributes to enable + error[E0658]: intrinsics are subject to change - --> $DIR/feature-gate-abi.rs:70:12 + --> $DIR/feature-gate-abi.rs:74:12 | LL | extern "rust-intrinsic" fn im1() {} | ^^^^^^^^^^^^^^^^ @@ -338,7 +374,7 @@ LL | extern "rust-intrinsic" fn im1() {} = help: add `#![feature(intrinsics)]` to the crate attributes to enable error[E0658]: platform intrinsics are experimental and possibly buggy - --> $DIR/feature-gate-abi.rs:72:12 + --> $DIR/feature-gate-abi.rs:76:12 | LL | extern "platform-intrinsic" fn im2() {} | ^^^^^^^^^^^^^^^^^^^^ @@ -347,7 +383,7 @@ LL | extern "platform-intrinsic" fn im2() {} = help: add `#![feature(platform_intrinsics)]` to the crate attributes to enable error[E0658]: vectorcall is experimental and subject to change - --> $DIR/feature-gate-abi.rs:74:12 + --> $DIR/feature-gate-abi.rs:78:12 | LL | extern "vectorcall" fn im3() {} | ^^^^^^^^^^^^ @@ -355,7 +391,7 @@ LL | extern "vectorcall" fn im3() {} = help: add `#![feature(abi_vectorcall)]` to the crate attributes to enable error[E0658]: rust-call ABI is subject to change - --> $DIR/feature-gate-abi.rs:75:12 + --> $DIR/feature-gate-abi.rs:79:12 | LL | extern "rust-call" fn im4(_: ()) {} | ^^^^^^^^^^^ @@ -364,7 +400,7 @@ LL | extern "rust-call" fn im4(_: ()) {} = help: add `#![feature(unboxed_closures)]` to the crate attributes to enable error[E0658]: msp430-interrupt ABI is experimental and subject to change - --> $DIR/feature-gate-abi.rs:76:12 + --> $DIR/feature-gate-abi.rs:80:12 | LL | extern "msp430-interrupt" fn im5() {} | ^^^^^^^^^^^^^^^^^^ @@ -373,7 +409,7 @@ LL | extern "msp430-interrupt" fn im5() {} = help: add `#![feature(abi_msp430_interrupt)]` to the crate attributes to enable error[E0658]: PTX ABIs are experimental and subject to change - --> $DIR/feature-gate-abi.rs:77:12 + --> $DIR/feature-gate-abi.rs:81:12 | LL | extern "ptx-kernel" fn im6() {} | ^^^^^^^^^^^^ @@ -382,7 +418,7 @@ LL | extern "ptx-kernel" fn im6() {} = help: add `#![feature(abi_ptx)]` to the crate attributes to enable error[E0658]: x86-interrupt ABI is experimental and subject to change - --> $DIR/feature-gate-abi.rs:78:12 + --> $DIR/feature-gate-abi.rs:82:12 | LL | extern "x86-interrupt" fn im7() {} | ^^^^^^^^^^^^^^^ @@ -391,7 +427,7 @@ LL | extern "x86-interrupt" fn im7() {} = help: add `#![feature(abi_x86_interrupt)]` to the crate attributes to enable error[E0658]: thiscall is experimental and subject to change - --> $DIR/feature-gate-abi.rs:79:12 + --> $DIR/feature-gate-abi.rs:83:12 | LL | extern "thiscall" fn im8() {} | ^^^^^^^^^^ @@ -399,7 +435,7 @@ LL | extern "thiscall" fn im8() {} = help: add `#![feature(abi_thiscall)]` to the crate attributes to enable error[E0658]: amdgpu-kernel ABI is experimental and subject to change - --> $DIR/feature-gate-abi.rs:80:12 + --> $DIR/feature-gate-abi.rs:84:12 | LL | extern "amdgpu-kernel" fn im9() {} | ^^^^^^^^^^^^^^^ @@ -408,7 +444,7 @@ LL | extern "amdgpu-kernel" fn im9() {} = help: add `#![feature(abi_amdgpu_kernel)]` to the crate attributes to enable error[E0658]: efiapi ABI is experimental and subject to change - --> $DIR/feature-gate-abi.rs:81:12 + --> $DIR/feature-gate-abi.rs:85:12 | LL | extern "efiapi" fn im10() {} | ^^^^^^^^ @@ -416,8 +452,17 @@ LL | extern "efiapi" fn im10() {} = note: see issue #65815 for more information = help: add `#![feature(abi_efiapi)]` to the crate attributes to enable +error[E0658]: wasm ABI is experimental and subject to change + --> $DIR/feature-gate-abi.rs:86:12 + | +LL | extern "wasm" fn im11() {} + | ^^^^^^ + | + = note: see issue #83788 for more information + = help: add `#![feature(wasm_abi)]` to the crate attributes to enable + error[E0658]: intrinsics are subject to change - --> $DIR/feature-gate-abi.rs:85:18 + --> $DIR/feature-gate-abi.rs:90:18 | LL | type A1 = extern "rust-intrinsic" fn(); | ^^^^^^^^^^^^^^^^ @@ -425,7 +470,7 @@ LL | type A1 = extern "rust-intrinsic" fn(); = help: add `#![feature(intrinsics)]` to the crate attributes to enable error[E0658]: platform intrinsics are experimental and possibly buggy - --> $DIR/feature-gate-abi.rs:86:18 + --> $DIR/feature-gate-abi.rs:91:18 | LL | type A2 = extern "platform-intrinsic" fn(); | ^^^^^^^^^^^^^^^^^^^^ @@ -434,7 +479,7 @@ LL | type A2 = extern "platform-intrinsic" fn(); = help: add `#![feature(platform_intrinsics)]` to the crate attributes to enable error[E0658]: vectorcall is experimental and subject to change - --> $DIR/feature-gate-abi.rs:87:18 + --> $DIR/feature-gate-abi.rs:92:18 | LL | type A3 = extern "vectorcall" fn(); | ^^^^^^^^^^^^ @@ -442,7 +487,7 @@ LL | type A3 = extern "vectorcall" fn(); = help: add `#![feature(abi_vectorcall)]` to the crate attributes to enable error[E0658]: rust-call ABI is subject to change - --> $DIR/feature-gate-abi.rs:88:18 + --> $DIR/feature-gate-abi.rs:93:18 | LL | type A4 = extern "rust-call" fn(_: ()); | ^^^^^^^^^^^ @@ -451,7 +496,7 @@ LL | type A4 = extern "rust-call" fn(_: ()); = help: add `#![feature(unboxed_closures)]` to the crate attributes to enable error[E0658]: msp430-interrupt ABI is experimental and subject to change - --> $DIR/feature-gate-abi.rs:89:18 + --> $DIR/feature-gate-abi.rs:94:18 | LL | type A5 = extern "msp430-interrupt" fn(); | ^^^^^^^^^^^^^^^^^^ @@ -460,16 +505,16 @@ LL | type A5 = extern "msp430-interrupt" fn(); = help: add `#![feature(abi_msp430_interrupt)]` to the crate attributes to enable error[E0658]: PTX ABIs are experimental and subject to change - --> $DIR/feature-gate-abi.rs:90:18 + --> $DIR/feature-gate-abi.rs:95:18 | -LL | type A6 = extern "ptx-kernel" fn (); +LL | type A6 = extern "ptx-kernel" fn(); | ^^^^^^^^^^^^ | = note: see issue #38788 for more information = help: add `#![feature(abi_ptx)]` to the crate attributes to enable error[E0658]: x86-interrupt ABI is experimental and subject to change - --> $DIR/feature-gate-abi.rs:91:18 + --> $DIR/feature-gate-abi.rs:96:18 | LL | type A7 = extern "x86-interrupt" fn(); | ^^^^^^^^^^^^^^^ @@ -478,7 +523,7 @@ LL | type A7 = extern "x86-interrupt" fn(); = help: add `#![feature(abi_x86_interrupt)]` to the crate attributes to enable error[E0658]: thiscall is experimental and subject to change - --> $DIR/feature-gate-abi.rs:92:18 + --> $DIR/feature-gate-abi.rs:97:18 | LL | type A8 = extern "thiscall" fn(); | ^^^^^^^^^^ @@ -486,7 +531,7 @@ LL | type A8 = extern "thiscall" fn(); = help: add `#![feature(abi_thiscall)]` to the crate attributes to enable error[E0658]: amdgpu-kernel ABI is experimental and subject to change - --> $DIR/feature-gate-abi.rs:93:18 + --> $DIR/feature-gate-abi.rs:98:18 | LL | type A9 = extern "amdgpu-kernel" fn(); | ^^^^^^^^^^^^^^^ @@ -495,7 +540,7 @@ LL | type A9 = extern "amdgpu-kernel" fn(); = help: add `#![feature(abi_amdgpu_kernel)]` to the crate attributes to enable error[E0658]: efiapi ABI is experimental and subject to change - --> $DIR/feature-gate-abi.rs:94:19 + --> $DIR/feature-gate-abi.rs:99:19 | LL | type A10 = extern "efiapi" fn(); | ^^^^^^^^ @@ -503,8 +548,17 @@ LL | type A10 = extern "efiapi" fn(); = note: see issue #65815 for more information = help: add `#![feature(abi_efiapi)]` to the crate attributes to enable +error[E0658]: wasm ABI is experimental and subject to change + --> $DIR/feature-gate-abi.rs:100:19 + | +LL | type A11 = extern "wasm" fn(); + | ^^^^^^ + | + = note: see issue #83788 for more information + = help: add `#![feature(wasm_abi)]` to the crate attributes to enable + error[E0658]: intrinsics are subject to change - --> $DIR/feature-gate-abi.rs:97:8 + --> $DIR/feature-gate-abi.rs:103:8 | LL | extern "rust-intrinsic" {} | ^^^^^^^^^^^^^^^^ @@ -512,7 +566,7 @@ LL | extern "rust-intrinsic" {} = help: add `#![feature(intrinsics)]` to the crate attributes to enable error[E0658]: platform intrinsics are experimental and possibly buggy - --> $DIR/feature-gate-abi.rs:98:8 + --> $DIR/feature-gate-abi.rs:104:8 | LL | extern "platform-intrinsic" {} | ^^^^^^^^^^^^^^^^^^^^ @@ -521,7 +575,7 @@ LL | extern "platform-intrinsic" {} = help: add `#![feature(platform_intrinsics)]` to the crate attributes to enable error[E0658]: vectorcall is experimental and subject to change - --> $DIR/feature-gate-abi.rs:99:8 + --> $DIR/feature-gate-abi.rs:105:8 | LL | extern "vectorcall" {} | ^^^^^^^^^^^^ @@ -529,7 +583,7 @@ LL | extern "vectorcall" {} = help: add `#![feature(abi_vectorcall)]` to the crate attributes to enable error[E0658]: rust-call ABI is subject to change - --> $DIR/feature-gate-abi.rs:100:8 + --> $DIR/feature-gate-abi.rs:106:8 | LL | extern "rust-call" {} | ^^^^^^^^^^^ @@ -538,7 +592,7 @@ LL | extern "rust-call" {} = help: add `#![feature(unboxed_closures)]` to the crate attributes to enable error[E0658]: msp430-interrupt ABI is experimental and subject to change - --> $DIR/feature-gate-abi.rs:101:8 + --> $DIR/feature-gate-abi.rs:107:8 | LL | extern "msp430-interrupt" {} | ^^^^^^^^^^^^^^^^^^ @@ -547,7 +601,7 @@ LL | extern "msp430-interrupt" {} = help: add `#![feature(abi_msp430_interrupt)]` to the crate attributes to enable error[E0658]: PTX ABIs are experimental and subject to change - --> $DIR/feature-gate-abi.rs:102:8 + --> $DIR/feature-gate-abi.rs:108:8 | LL | extern "ptx-kernel" {} | ^^^^^^^^^^^^ @@ -556,7 +610,7 @@ LL | extern "ptx-kernel" {} = help: add `#![feature(abi_ptx)]` to the crate attributes to enable error[E0658]: x86-interrupt ABI is experimental and subject to change - --> $DIR/feature-gate-abi.rs:103:8 + --> $DIR/feature-gate-abi.rs:109:8 | LL | extern "x86-interrupt" {} | ^^^^^^^^^^^^^^^ @@ -565,7 +619,7 @@ LL | extern "x86-interrupt" {} = help: add `#![feature(abi_x86_interrupt)]` to the crate attributes to enable error[E0658]: thiscall is experimental and subject to change - --> $DIR/feature-gate-abi.rs:104:8 + --> $DIR/feature-gate-abi.rs:110:8 | LL | extern "thiscall" {} | ^^^^^^^^^^ @@ -573,7 +627,7 @@ LL | extern "thiscall" {} = help: add `#![feature(abi_thiscall)]` to the crate attributes to enable error[E0658]: amdgpu-kernel ABI is experimental and subject to change - --> $DIR/feature-gate-abi.rs:105:8 + --> $DIR/feature-gate-abi.rs:111:8 | LL | extern "amdgpu-kernel" {} | ^^^^^^^^^^^^^^^ @@ -582,7 +636,7 @@ LL | extern "amdgpu-kernel" {} = help: add `#![feature(abi_amdgpu_kernel)]` to the crate attributes to enable error[E0658]: efiapi ABI is experimental and subject to change - --> $DIR/feature-gate-abi.rs:106:8 + --> $DIR/feature-gate-abi.rs:112:8 | LL | extern "efiapi" {} | ^^^^^^^^ @@ -590,14 +644,23 @@ LL | extern "efiapi" {} = note: see issue #65815 for more information = help: add `#![feature(abi_efiapi)]` to the crate attributes to enable +error[E0658]: wasm ABI is experimental and subject to change + --> $DIR/feature-gate-abi.rs:113:8 + | +LL | extern "wasm" {} + | ^^^^^^ + | + = note: see issue #83788 for more information + = help: add `#![feature(wasm_abi)]` to the crate attributes to enable + error: intrinsic must be in `extern "rust-intrinsic" { ... }` block - --> $DIR/feature-gate-abi.rs:27:32 + --> $DIR/feature-gate-abi.rs:28:32 | LL | extern "rust-intrinsic" fn m1(); | ^^ error: intrinsic must be in `extern "rust-intrinsic" { ... }` block - --> $DIR/feature-gate-abi.rs:29:36 + --> $DIR/feature-gate-abi.rs:30:36 | LL | extern "platform-intrinsic" fn m2(); | ^^ @@ -615,29 +678,29 @@ LL | extern "platform-intrinsic" fn f2() {} | ^^ error: intrinsic must be in `extern "rust-intrinsic" { ... }` block - --> $DIR/feature-gate-abi.rs:54:37 + --> $DIR/feature-gate-abi.rs:57:37 | LL | extern "rust-intrinsic" fn m1() {} | ^^ error: intrinsic must be in `extern "rust-intrinsic" { ... }` block - --> $DIR/feature-gate-abi.rs:56:41 + --> $DIR/feature-gate-abi.rs:59:41 | LL | extern "platform-intrinsic" fn m2() {} | ^^ error: intrinsic must be in `extern "rust-intrinsic" { ... }` block - --> $DIR/feature-gate-abi.rs:70:38 + --> $DIR/feature-gate-abi.rs:74:38 | LL | extern "rust-intrinsic" fn im1() {} | ^^ error: intrinsic must be in `extern "rust-intrinsic" { ... }` block - --> $DIR/feature-gate-abi.rs:72:42 + --> $DIR/feature-gate-abi.rs:76:42 | LL | extern "platform-intrinsic" fn im2() {} | ^^ -error: aborting due to 76 previous errors +error: aborting due to 83 previous errors For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/feature-gates/feature-gate-wasm_abi.rs b/src/test/ui/feature-gates/feature-gate-wasm_abi.rs new file mode 100644 index 0000000000000..8c8de0763658e --- /dev/null +++ b/src/test/ui/feature-gates/feature-gate-wasm_abi.rs @@ -0,0 +1,7 @@ +extern "wasm" fn foo() { + //~^ ERROR: wasm ABI is experimental and subject to change +} + +fn main() { + foo(); +} diff --git a/src/test/ui/feature-gates/feature-gate-wasm_abi.stderr b/src/test/ui/feature-gates/feature-gate-wasm_abi.stderr new file mode 100644 index 0000000000000..c4113fd6af979 --- /dev/null +++ b/src/test/ui/feature-gates/feature-gate-wasm_abi.stderr @@ -0,0 +1,12 @@ +error[E0658]: wasm ABI is experimental and subject to change + --> $DIR/feature-gate-wasm_abi.rs:1:8 + | +LL | extern "wasm" fn foo() { + | ^^^^^^ + | + = note: see issue #83788 for more information + = help: add `#![feature(wasm_abi)]` to the crate attributes to enable + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/parser/issue-8537.stderr b/src/test/ui/parser/issue-8537.stderr index 85e2b77d867b9..5a29ce2221fc2 100644 --- a/src/test/ui/parser/issue-8537.stderr +++ b/src/test/ui/parser/issue-8537.stderr @@ -4,7 +4,7 @@ error[E0703]: invalid ABI: found `invalid-ab_isize` LL | "invalid-ab_isize" | ^^^^^^^^^^^^^^^^^^ invalid ABI | - = help: valid ABIs: Rust, C, C-unwind, cdecl, stdcall, stdcall-unwind, fastcall, vectorcall, thiscall, thiscall-unwind, aapcs, win64, sysv64, ptx-kernel, msp430-interrupt, x86-interrupt, amdgpu-kernel, efiapi, avr-interrupt, avr-non-blocking-interrupt, C-cmse-nonsecure-call, system, system-unwind, rust-intrinsic, rust-call, platform-intrinsic, unadjusted + = help: valid ABIs: Rust, C, C-unwind, cdecl, stdcall, stdcall-unwind, fastcall, vectorcall, thiscall, thiscall-unwind, aapcs, win64, sysv64, ptx-kernel, msp430-interrupt, x86-interrupt, amdgpu-kernel, efiapi, avr-interrupt, avr-non-blocking-interrupt, C-cmse-nonsecure-call, wasm, system, system-unwind, rust-intrinsic, rust-call, platform-intrinsic, unadjusted error: aborting due to previous error