A lightweight WebAssembly runtime that is fast, secure, and standards-compliant
generate precise traps in component adapters (#12215)
Joel Dice967f4601d0a8
diff --git a/crates/cranelift/src/compiler/component.rs b/crates/cranelift/src/compiler/component.rsindex 632bd242c8..4aaae9cbc4 100644--- a/crates/cranelift/src/compiler/component.rs+++ b/crates/cranelift/src/compiler/component.rs@@ -171,7 +171,7 @@ impl<'a> TrampolineCompiler<'a> {WasmArgs::InRegisters,|me, params| {let code = wasmtime_environ::Trap::AlwaysTrapAdapter as u8;- params.push(me.builder.ins().iconst(ir::types::I8, i64::from(code)));+ params.push(me.builder.ins().iconst(ir::types::I32, i64::from(code)));},);}@@ -740,6 +740,14 @@ impl<'a> TrampolineCompiler<'a> {|_, _| {},);}+ Trampoline::Trap => {+ self.translate_libcall(+ host::trap,+ TrapSentinel::Falsy,+ WasmArgs::InRegisters,+ |_, _| {},+ );+ }Trampoline::ContextGet { instance, slot } => {self.translate_libcall(host::context_get,diff --git a/crates/environ/src/component.rs b/crates/environ/src/component.rsindex 9b97c8b179..e68c357b11 100644--- a/crates/environ/src/component.rs+++ b/crates/environ/src/component.rs@@ -203,7 +203,7 @@ macro_rules! foreach_builtin_component_function {#[cfg(feature = "component-model-async")]thread_yield_to(vmctx: vmctx, caller_instance: u32, cancellable: u8, thread_idx: u32) -> u32;- trap(vmctx: vmctx, code: u8) -> bool;+ trap(vmctx: vmctx, code: u32) -> bool;utf8_to_utf8(vmctx: vmctx, src: ptr_u8, len: size, dst: ptr_u8) -> bool;utf16_to_utf16(vmctx: vmctx, src: ptr_u16, len: size, dst: ptr_u16) -> bool;diff --git a/crates/environ/src/component/dfg.rs b/crates/environ/src/component/dfg.rsindex e98ff58e88..9bf35ec7e9 100644--- a/crates/environ/src/component/dfg.rs+++ b/crates/environ/src/component/dfg.rs@@ -476,6 +476,7 @@ pub enum Trampoline {StreamTransfer,ErrorContextTransfer,CheckBlocking,+ Trap,ContextGet {instance: RuntimeComponentInstanceIndex,slot: u32,@@ -1156,6 +1157,7 @@ impl LinearizeDfg<'_> {Trampoline::StreamTransfer => info::Trampoline::StreamTransfer,Trampoline::ErrorContextTransfer => info::Trampoline::ErrorContextTransfer,Trampoline::CheckBlocking => info::Trampoline::CheckBlocking,+ Trampoline::Trap => info::Trampoline::Trap,Trampoline::ContextGet { instance, slot } => info::Trampoline::ContextGet {instance: *instance,slot: *slot,diff --git a/crates/environ/src/component/info.rs b/crates/environ/src/component/info.rsindex 5805e91b44..6be69584fc 100644--- a/crates/environ/src/component/info.rs+++ b/crates/environ/src/component/info.rs@@ -1109,6 +1109,10 @@ pub enum Trampoline {/// async-typed function may be called via a sync lower.CheckBlocking,+ /// An intrinsic used by FACT-generated modules to trap with a specified+ /// code.+ Trap,+/// Intrinsic used to implement the `context.get` component model builtin.////// The payload here represents that this is accessing the Nth slot of local@@ -1239,6 +1243,7 @@ impl Trampoline {StreamTransfer => format!("stream-transfer"),ErrorContextTransfer => format!("error-context-transfer"),CheckBlocking => format!("check-blocking"),+ Trap => format!("trap"),ContextGet { .. } => format!("context-get"),ContextSet { .. } => format!("context-set"),ThreadIndex => format!("thread-index"),diff --git a/crates/environ/src/component/translate/adapt.rs b/crates/environ/src/component/translate/adapt.rsindex 76a75813de..75758d2558 100644--- a/crates/environ/src/component/translate/adapt.rs+++ b/crates/environ/src/component/translate/adapt.rs@@ -346,6 +346,7 @@ fn fact_import_to_core_def(simple_intrinsic(dfg::Trampoline::ErrorContextTransfer)}fact::Import::CheckBlocking => simple_intrinsic(dfg::Trampoline::CheckBlocking),+ fact::Import::Trap => simple_intrinsic(dfg::Trampoline::Trap),}}diff --git a/crates/environ/src/fact.rs b/crates/environ/src/fact.rsindex 3fa31386df..74da3aba4a 100644--- a/crates/environ/src/fact.rs+++ b/crates/environ/src/fact.rs@@ -26,7 +26,6 @@ use crate::component::{use crate::fact::transcode::Transcoder;use crate::{EntityRef, FuncIndex, GlobalIndex, MemoryIndex, PrimaryMap};use crate::{ModuleInternedTypeIndex, prelude::*};-use std::borrow::Cow;use std::collections::HashMap;use wasm_encoder::*;@@ -34,7 +33,6 @@ mod core_types;mod signature;mod trampoline;mod transcode;-mod traps;/// Fixed parameter types for the `prepare_call` built-in function.///@@ -92,6 +90,8 @@ pub struct Module<'a> {imported_check_blocking: Option<FuncIndex>,+ imported_trap: Option<FuncIndex>,+// Current status of index spaces from the imports generated so far.imported_funcs: PrimaryMap<FuncIndex, Option<CoreDef>>,imported_memories: PrimaryMap<MemoryIndex, CoreDef>,@@ -263,6 +263,7 @@ impl<'a> Module<'a> {imported_stream_transfer: None,imported_error_context_transfer: None,imported_check_blocking: None,+ imported_trap: None,exports: Vec::new(),}}@@ -727,6 +728,17 @@ impl<'a> Module<'a> {)}+ fn import_trap(&mut self) -> FuncIndex {+ self.import_simple(+ "runtime",+ "trap",+ &[ValType::I32],+ &[],+ Import::Trap,+ |me| &mut me.imported_trap,+ )+ }+fn translate_helper(&mut self, helper: Helper) -> FunctionId {*self.helper_funcs.entry(helper).or_insert_with(|| {// Generate a fresh `Function` with a unique id for what we're about to@@ -765,9 +777,7 @@ impl<'a> Module<'a> {// With all functions numbered the fragments of the body of each// function can be assigned into one final adapter function.let mut code = CodeSection::new();- let mut traps = traps::TrapSection::default();- for (id, func) in self.funcs.iter() {- let mut func_traps = Vec::new();+ for (_, func) in self.funcs.iter() {let mut body = Vec::new();// Encode all locals used for this function@@ -783,12 +793,8 @@ impl<'a> Module<'a> {// here to the final function index.for chunk in func.body.iter() {match chunk {- Body::Raw(code, traps) => {- let start = body.len();+ Body::Raw(code) => {body.extend_from_slice(code);- for (offset, trap) in traps {- func_traps.push((start + offset, *trap));- }}Body::Call(id) => {Instruction::Call(id_to_index[*id].as_u32()).encode(&mut body);@@ -799,23 +805,14 @@ impl<'a> Module<'a> {}}code.raw(&body);- traps.append(id_to_index[id].as_u32(), func_traps);}- let traps = traps.finish();-let mut result = wasm_encoder::Module::new();result.section(&self.core_types.section);result.section(&self.core_imports);result.section(&funcs);result.section(&exports);result.section(&code);- if self.debug {- result.section(&CustomSection {- name: "wasmtime-trampoline-traps".into(),- data: Cow::Borrowed(&traps),- });- }result.finish()}@@ -888,6 +885,8 @@ pub enum Import {/// An intrinsic used by FACT-generated modules to check whether an/// async-typed function may be called via a sync lower.CheckBlocking,+ /// An intrinsic for trapping the instance with a specific trap code.+ Trap,}impl Options {@@ -954,8 +953,6 @@ struct Function {////// 1. First a `Raw` variant is used to contain general instructions for the/// wasm function. This is populated by `Compiler::instruction` primarily.-/// This also comes with a list of traps. and the byte offset within the-/// first vector of where the trap information applies to.////// 2. A `Call` instruction variant for a `FunctionId` where the final/// `FuncIndex` isn't known until emission time.@@ -971,7 +968,7 @@ struct Function {/// easier to represent. A 5-byte leb may be more efficient at compile-time if/// necessary, however.enum Body {- Raw(Vec<u8>, Vec<(usize, traps::Trap)>),+ Raw(Vec<u8>),Call(FunctionId),RefFunc(FunctionId),}diff --git a/crates/environ/src/fact/trampoline.rs b/crates/environ/src/fact/trampoline.rsindex e334876ef1..0411e67f78 100644--- a/crates/environ/src/fact/trampoline.rs+++ b/crates/environ/src/fact/trampoline.rs@@ -25,13 +25,12 @@ use crate::component::{};use crate::fact::signature::Signature;use crate::fact::transcode::Transcoder;-use crate::fact::traps::Trap;use crate::fact::{AdapterData, Body, Function, FunctionId, Helper, HelperLocation, HelperType,LinearMemoryOptions, Module, Options,};use crate::prelude::*;-use crate::{FuncIndex, GlobalIndex};+use crate::{FuncIndex, GlobalIndex, Trap};use std::collections::HashMap;use std::mem;use std::ops::Range;@@ -61,11 +60,6 @@ struct Compiler<'a, 'b> {/// Locals partitioned by type which are not currently in use.free_locals: HashMap<ValType, Vec<u32>>,- /// Metadata about all `unreachable` trap instructions in this function and- /// what the trap represents. The offset within `self.code` is recorded as- /// well.- traps: Vec<(usize, Trap)>,-/// A heuristic which is intended to limit the size of a generated function/// to a certain maximum to avoid generating arbitrarily large functions.///@@ -331,7 +325,6 @@ pub(super) fn compile_helper(module: &mut Module<'_>, result: FunctionId, helpercode: Vec::new(),nlocals,free_locals: HashMap::new(),- traps: Vec::new(),result,fuel: INITIAL_FUEL,// This is a helper function and only the top-level function is@@ -445,7 +438,6 @@ impl<'a, 'b> Compiler<'a, 'b> {code: Vec::new(),nlocals,free_locals: HashMap::new(),- traps: Vec::new(),fuel: INITIAL_FUEL,emit_resource_call,}@@ -741,15 +733,23 @@ impl<'a, 'b> Compiler<'a, 'b> {// This inserts the initial check required by `canon_lower` that the// caller instance can be left and additionally checks the// flags on the callee if necessary whether it can be entered.- self.trap_if_not_flag(adapter.lower.flags, FLAG_MAY_LEAVE, Trap::CannotLeave);+ self.trap_if_not_flag(+ adapter.lower.flags,+ FLAG_MAY_LEAVE,+ Trap::CannotLeaveComponent,+ );if adapter.called_as_export {- self.trap_if_not_flag(adapter.lift.flags, FLAG_MAY_ENTER, Trap::CannotEnter);+ self.trap_if_not_flag(+ adapter.lift.flags,+ FLAG_MAY_ENTER,+ Trap::CannotEnterComponent,+ );self.set_flag(adapter.lift.flags, FLAG_MAY_ENTER, false);} else if self.module.debug {self.assert_not_flag(adapter.lift.flags,FLAG_MAY_ENTER,- "may_enter should be unset",+ Trap::DebugAssertMayEnterUnset,);}@@ -1939,7 +1939,7 @@ impl<'a, 'b> Compiler<'a, 'b> {self.ptr_sub(src_mem_opts);self.ptr_ne(src_mem_opts);self.instruction(If(BlockType::Empty));- self.trap(Trap::AssertFailed("should have finished encoding"));+ self.trap(Trap::DebugAssertStringEncodingFinished);self.instruction(End);} else {self.instruction(Drop);@@ -1967,7 +1967,7 @@ impl<'a, 'b> Compiler<'a, 'b> {self.instruction(LocalGet(dst_byte_len.idx));self.ptr_ne(dst_mem_opts);self.instruction(If(BlockType::Empty));- self.trap(Trap::AssertFailed("should have finished encoding"));+ self.trap(Trap::DebugAssertStringEncodingFinished);self.instruction(End);}@@ -2138,7 +2138,7 @@ impl<'a, 'b> Compiler<'a, 'b> {self.convert_src_len_to_dst(src.len.idx, src_mem_opts.ptr(), dst_mem_opts.ptr());self.ptr_ne(dst_mem_opts);self.instruction(If(BlockType::Empty));- self.trap(Trap::AssertFailed("expected equal code units"));+ self.trap(Trap::DebugAssertEqualCodeUnits);self.instruction(End);}@@ -2335,7 +2335,7 @@ impl<'a, 'b> Compiler<'a, 'b> {self.ptr_uconst(mem_opts, max);self.ptr_ge_u(mem_opts);self.instruction(If(BlockType::Empty));- self.trap(Trap::StringLengthTooBig);+ self.trap(Trap::StringOutOfBounds);self.instruction(End);}@@ -2374,7 +2374,7 @@ impl<'a, 'b> Compiler<'a, 'b> {match &s.opts.data_model {DataModel::Gc {} => todo!("CM+GC"),DataModel::LinearMemory(opts) => {- self.validate_memory_inbounds(opts, s.ptr.idx, byte_len, Trap::StringLengthOverflow)+ self.validate_memory_inbounds(opts, s.ptr.idx, byte_len, Trap::StringOutOfBounds)}}}@@ -2509,13 +2509,13 @@ impl<'a, 'b> Compiler<'a, 'b> {src_mem_opts,src_mem.addr.idx,src_byte_len.idx,- Trap::ListByteLengthOverflow,+ Trap::ListOutOfBounds,);self.validate_memory_inbounds(dst_mem_opts,dst_mem.addr.idx,dst_byte_len.idx,- Trap::ListByteLengthOverflow,+ Trap::ListOutOfBounds,);self.free_temp_local(src_byte_len);@@ -2636,7 +2636,7 @@ impl<'a, 'b> Compiler<'a, 'b> {self.instruction(I64ShrU);self.instruction(I32WrapI64);self.instruction(If(BlockType::Empty));- self.trap(Trap::ListByteLengthOverflow);+ self.trap(Trap::ListOutOfBounds);self.instruction(End);}self.instruction(LocalGet(len_local));@@ -2688,7 +2688,7 @@ impl<'a, 'b> Compiler<'a, 'b> {self.instruction(I64Eqz);self.instruction(BrIf(1));self.instruction(End);- self.trap(Trap::ListByteLengthOverflow);+ self.trap(Trap::ListOutOfBounds);self.instruction(End);// If a fresh local was used to store the result of the multiplication@@ -3268,12 +3268,12 @@ impl<'a, 'b> Compiler<'a, 'b> {self.instruction(End);}- fn assert_not_flag(&mut self, flags_global: GlobalIndex, flag_to_test: i32, msg: &'static str) {+ fn assert_not_flag(&mut self, flags_global: GlobalIndex, flag_to_test: i32, trap: Trap) {self.instruction(GlobalGet(flags_global.as_u32()));self.instruction(I32Const(flag_to_test));self.instruction(I32And);self.instruction(If(BlockType::Empty));- self.trap(Trap::AssertFailed(msg));+ self.trap(trap);self.instruction(End);}@@ -3320,7 +3320,7 @@ impl<'a, 'b> Compiler<'a, 'b> {self.ptr_uconst(mem_opts, align - 1);self.ptr_and(mem_opts);self.ptr_if(mem_opts, BlockType::Empty);- self.trap(Trap::AssertFailed("pointer not aligned"));+ self.trap(Trap::DebugAssertPointerAligned);self.instruction(End);}@@ -3416,22 +3416,23 @@ impl<'a, 'b> Compiler<'a, 'b> {}fn trap(&mut self, trap: Trap) {- self.traps.push((self.code.len(), trap));+ let trap_func = self.module.import_trap();+ self.instruction(I32Const(trap as i32));+ self.instruction(Call(trap_func.as_u32()));self.instruction(Unreachable);}- /// Flushes out the current `code` instructions (and `traps` if there are- /// any) into the destination function.+ /// Flushes out the current `code` instructions into the destination+ /// function.////// This is a noop if no instructions have been encoded yet.fn flush_code(&mut self) {if self.code.is_empty() {return;}- self.module.funcs[self.result].body.push(Body::Raw(- mem::take(&mut self.code),- mem::take(&mut self.traps),- ));+ self.module.funcs[self.result]+ .body+ .push(Body::Raw(mem::take(&mut self.code)));}fn finish(mut self) {@@ -3503,7 +3504,7 @@ impl<'a, 'b> Compiler<'a, 'b> {self.instruction(I64ShrU);self.instruction(I32WrapI64);self.instruction(If(BlockType::Empty));- self.trap(Trap::AssertFailed("upper bits are unexpectedly set"));+ self.trap(Trap::DebugAssertUpperBitsUnset);self.instruction(End);}diff --git a/crates/environ/src/fact/traps.rs b/crates/environ/src/fact/traps.rsdeleted file mode 100644index 28f1057f04..0000000000--- a/crates/environ/src/fact/traps.rs+++ /dev/null@@ -1,116 +0,0 @@-//! Module used to encode failure messages associated with traps in an adapter-//! module.-//!-//! This module is a bit forward-looking in an attempt to help assist with-//! debugging issues with adapter modules and their implementation. This isn't-//! actually wired up to any decoder at this time and may end up getting deleted-//! entirely depending on how things go.-//!-//! Currently in core wasm the `unreachable` instruction and other traps have no-//! ability to assign failure messages with traps. This means that if an adapter-//! fails all you have is the program counter into the wasm function, but-//! there's not actually any source corresponding to wasm adapters either. This-//! module is an attempt to assign optional string messages to `unreachable`-//! trap instructions so, when sufficient debugging options are enabled, these-//! trap messages could be displayed instead of a bland "unreachable" trap-//! message.-//!-//! This information is currently encoded as a custom section in the wasm-//! module.--use crate::prelude::*;-use std::collections::HashMap;-use std::fmt;-use wasm_encoder::Encode;--#[derive(Hash, PartialEq, Eq, Copy, Clone)]-pub enum Trap {- CannotLeave,- CannotEnter,- UnalignedPointer,- InvalidDiscriminant,- InvalidChar,- ListByteLengthOverflow,- StringLengthTooBig,- StringLengthOverflow,- AssertFailed(&'static str),-}--#[derive(Default)]-pub struct TrapSection {- trap_to_index: HashMap<Trap, usize>,- trap_list: Vec<Trap>,- function_traps: Vec<(u32, Vec<(usize, usize)>)>,-}--impl TrapSection {- /// Appends a list of traps found within a function.- ///- /// The `func` is the core wasm function index that is being described. The- /// `traps` is a list of `(offset, trap)` where `offset` is the offset- /// within the function body itself and `trap` is the description of the- /// trap of the opcode at that offset.- pub fn append(&mut self, func: u32, traps: Vec<(usize, Trap)>) {- if traps.is_empty() {- return;- }-- // Deduplicate `Trap` annotations to avoid repeating the trap string- // internally within the custom section.- let traps = traps- .into_iter()- .map(|(offset, trap)| {- let trap = *self.trap_to_index.entry(trap).or_insert_with(|| {- let idx = self.trap_list.len();- self.trap_list.push(trap);- idx- });- (offset, trap)- })- .collect();- self.function_traps.push((func, traps));- }-- /// Creates the custom section payload of this section to be encoded into a- /// core wasm module.- pub fn finish(self) -> Vec<u8> {- let mut data = Vec::new();-- // First append all trap messages which will be indexed below.- self.trap_list.len().encode(&mut data);- for trap in self.trap_list.iter() {- trap.to_string().encode(&mut data);- }-- // Afterwards encode trap information for all known functions where- // offsets are relative to the body of the function index specified and- // the trap message is a pointer into the table built above this.- self.function_traps.len().encode(&mut data);- for (func, traps) in self.function_traps.iter() {- func.encode(&mut data);- traps.len().encode(&mut data);- for (func_offset, trap_message) in traps {- func_offset.encode(&mut data);- trap_message.encode(&mut data);- }- }-- data- }-}--impl fmt::Display for Trap {- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {- match self {- Trap::CannotLeave => "cannot leave instance".fmt(f),- Trap::CannotEnter => "cannot enter instance".fmt(f),- Trap::UnalignedPointer => "pointer not aligned correctly".fmt(f),- Trap::InvalidDiscriminant => "invalid variant discriminant".fmt(f),- Trap::InvalidChar => "invalid char value specified".fmt(f),- Trap::ListByteLengthOverflow => "byte size of list too large for i32".fmt(f),- Trap::StringLengthTooBig => "string byte size exceeds maximum".fmt(f),- Trap::StringLengthOverflow => "string byte size overflows i32".fmt(f),- Trap::AssertFailed(s) => write!(f, "assertion failure: {s}"),- }- }-}diff --git a/crates/environ/src/trap_encoding.rs b/crates/environ/src/trap_encoding.rsindex e81682e08f..95bc95c704 100644--- a/crates/environ/src/trap_encoding.rs+++ b/crates/environ/src/trap_encoding.rs@@ -113,8 +113,48 @@ pub enum Trap {/// when it wasn't allowed to, e.g. from a post-return function.CannotLeaveComponent,- /// A synchronous task attempted to make a potentially blocking call.+ /// A synchronous task attempted to make a potentially blocking call prior+ /// to returning.CannotBlockSyncTask,++ /// A component tried to lift a `char` with an invalid bit pattern.+ InvalidChar,++ /// Debug assertion generated for a fused adapter regarding the expected+ /// completion of a string encoding operation.+ DebugAssertStringEncodingFinished,++ /// Debug assertion generated for a fused adapter regarding a string+ /// encoding operation.+ DebugAssertEqualCodeUnits,++ /// Debug assertion generated for a fused adapter regarding the expected+ /// value of the `may_enter` flag for an instance.+ ///+ /// TODO: Remove this once+ /// https://github.com/bytecodealliance/wasmtime/pull/12153 has been merged.+ DebugAssertMayEnterUnset,++ /// Debug assertion generated for a fused adapter regarding the alignment of+ /// a pointer.+ DebugAssertPointerAligned,++ /// Debug assertion generated for a fused adapter regarding the upper bits+ /// of a 64-bit value.+ DebugAssertUpperBitsUnset,++ /// A component tried to lift or lower a string past the end of its memory.+ StringOutOfBounds,++ /// A component tried to lift or lower a list past the end of its memory.+ ListOutOfBounds,++ /// A component used an invalid discriminant when lowering a variant value.+ InvalidDiscriminant,++ /// A component passed an unaligned pointer when lifting or lowering a+ /// value.+ UnalignedPointer,// if adding a variant here be sure to update the `check!` macro below}@@ -158,6 +198,16 @@ impl Trap {AsyncDeadlockCannotLeaveComponentCannotBlockSyncTask+ InvalidChar+ DebugAssertStringEncodingFinished+ DebugAssertEqualCodeUnits+ DebugAssertMayEnterUnset+ DebugAssertPointerAligned+ DebugAssertUpperBitsUnset+ StringOutOfBounds+ ListOutOfBounds+ InvalidDiscriminant+ UnalignedPointer}None@@ -195,6 +245,16 @@ impl fmt::Display for Trap {AsyncDeadlock => "deadlock detected: event loop cannot make further progress",CannotLeaveComponent => "cannot leave component instance",CannotBlockSyncTask => "cannot block a synchronous task before returning",+ InvalidChar => "invalid `char` bit pattern",+ DebugAssertStringEncodingFinished => "should have finished string encoding",+ DebugAssertEqualCodeUnits => "code units should be equal",+ DebugAssertMayEnterUnset => "`may_enter` flag should be unset",+ DebugAssertPointerAligned => "pointer should be aligned",+ DebugAssertUpperBitsUnset => "upper bits should be unset",+ StringOutOfBounds => "string content out-of-bounds",+ ListOutOfBounds => "list content out-of-bounds",+ InvalidDiscriminant => "invalid variant discriminant",+ UnalignedPointer => "unaligned pointer",};write!(f, "wasm trap: {desc}")}diff --git a/crates/test-util/src/wast.rs b/crates/test-util/src/wast.rsindex 65ed54fa0c..69a7192cdc 100644--- a/crates/test-util/src/wast.rs+++ b/crates/test-util/src/wast.rs@@ -184,7 +184,11 @@ fn component_test_config(test: &Path) -> TestConfig {ret.multi_memory = Some(true);if let Some(parent) = test.parent() {- if parent.ends_with("async") {+ if parent.ends_with("async")+ || ["trap-in-post-return.wast"]+ .into_iter()+ .any(|name| Some(name) == test.file_name().and_then(|s| s.to_str()))+ {ret.component_model_async = Some(true);ret.component_model_async_stackful = Some(true);ret.component_model_async_builtins = Some(true);@@ -697,8 +701,7 @@ impl WastTest {}let failing_component_model_tests = [- // FIXME(#11683)- "component-model/test/values/trap-in-post-return.wast",+ // FIXME(#12214)"component-model/test/wasmtime/resources.wast","component-model/test/wasm-tools/naming.wast",// TODO: Remove this oncediff --git a/crates/wasmtime/src/runtime/vm/component/libcalls.rs b/crates/wasmtime/src/runtime/vm/component/libcalls.rsindex 0825ae2009..d7f8527c3e 100644--- a/crates/wasmtime/src/runtime/vm/component/libcalls.rs+++ b/crates/wasmtime/src/runtime/vm/component/libcalls.rs@@ -665,8 +665,10 @@ fn resource_exit_call(store: &mut dyn VMStore, instance: Instance) -> Result<()>instance.resource_exit_call(store)}-fn trap(_store: &mut dyn VMStore, _instance: Instance, code: u8) -> Result<()> {- Err(wasmtime_environ::Trap::from_u8(code).unwrap().into())+fn trap(_store: &mut dyn VMStore, _instance: Instance, code: u32) -> Result<()> {+ Err(wasmtime_environ::Trap::from_u8(u8::try_from(code).unwrap())+ .unwrap()+ .into())}#[cfg(feature = "component-model-async")]diff --git a/tests/all/component_model/strings.rs b/tests/all/component_model/strings.rsindex de6c87392e..a33dd960d2 100644--- a/tests/all/component_model/strings.rs+++ b/tests/all/component_model/strings.rs@@ -250,7 +250,7 @@ fn test_ptr_out_of_bounds(engine: &Engine, src: &str, dst: &str) -> Result<()> {.err().unwrap().downcast::<Trap>()?;- assert_eq!(trap, Trap::UnreachableCodeReached);+ assert_eq!(trap, Trap::StringOutOfBounds);Ok(())};@@ -324,7 +324,7 @@ fn test_ptr_overflow(engine: &Engine, src: &str, dst: &str) -> Result<()> {.call(&mut store, (size,)).unwrap_err().downcast::<Trap>()?;- assert_eq!(trap, Trap::UnreachableCodeReached);+ assert_eq!(trap, Trap::StringOutOfBounds);Ok(())};@@ -424,7 +424,7 @@ fn test_realloc_oob(engine: &Engine, src: &str, dst: &str) -> Result<()> {let instance = Linker::new(engine).instantiate(&mut store, &component)?;let func = instance.get_typed_func::<(), ()>(&mut store, "f")?;let trap = func.call(&mut store, ()).unwrap_err().downcast::<Trap>()?;- assert_eq!(trap, Trap::UnreachableCodeReached);+ assert_eq!(trap, Trap::StringOutOfBounds);Ok(())}diff --git a/tests/component-model b/tests/component-modelindex 7479890cb5..d336ed688a 160000--- a/tests/component-model+++ b/tests/component-model@@ -1 +1 @@-Subproject commit 7479890cb506d0f8f687595a4d41361ff8a2a194+Subproject commit d336ed688a85987dfb4f68df14fcf368808896a7diff --git a/tests/disas/component-model/direct-adapter-calls-inlining.wat b/tests/disas/component-model/direct-adapter-calls-inlining.watindex dab7c47b37..01717f76ae 100644--- a/tests/disas/component-model/direct-adapter-calls-inlining.wat+++ b/tests/disas/component-model/direct-adapter-calls-inlining.wat@@ -63,15 +63,16 @@;; gv5 = load.i64 notrap aligned readonly gv4+8;; gv6 = load.i64 notrap aligned gv5+16;; gv7 = vmctx-;; gv8 = load.i64 notrap aligned readonly can_move gv7+96-;; gv9 = load.i64 notrap aligned readonly can_move gv7+72+;; gv8 = load.i64 notrap aligned readonly can_move gv7+120+;; gv9 = load.i64 notrap aligned readonly can_move gv7+96;; gv10 = vmctx;; gv11 = load.i64 notrap aligned readonly gv10+8;; gv12 = load.i64 notrap aligned gv11+16;; sig0 = (i64 vmctx, i64, i32) -> i32 tail-;; sig1 = (i64 vmctx, i64, i32) -> i32 tail+;; sig1 = (i64 vmctx, i64, i32) tail+;; sig2 = (i64 vmctx, i64, i32) -> i32 tail;; fn0 = colocated u2:0 sig0-;; fn1 = colocated u0:0 sig1+;; fn1 = colocated u0:0 sig2;; stack_limit = gv2;;;; block0(v0: i64, v1: i64):@@ -79,38 +80,49 @@;;;; block2:;; @00ee v5 = load.i64 notrap aligned readonly can_move v0+64-;; v12 = load.i64 notrap aligned readonly can_move v5+96+;; v12 = load.i64 notrap aligned readonly can_move v5+120;; v13 = load.i32 notrap aligned table v12;; v14 = iconst.i32 1;; v15 = band v13, v14 ; v14 = 1;; v11 = iconst.i32 0;; v17 = icmp eq v15, v11 ; v11 = 0;; v18 = uextend.i32 v17-;; trapnz v18, user11-;; jump block5+;; brif v18, block4, block5+;;+;; block4:+;; v93 = load.i64 notrap aligned readonly can_move v5+72+;; v94 = load.i64 notrap aligned readonly can_move v5+88+;; v19 = iconst.i32 24+;; call_indirect sig1, v93(v94, v5, v19) ; v19 = 24+;; trap user11;;;; block5:-;; v19 = load.i64 notrap aligned readonly can_move v5+72-;; v20 = load.i32 notrap aligned table v19-;; v21 = iconst.i32 2-;; v22 = band v20, v21 ; v21 = 2-;; v79 = iconst.i32 0-;; v80 = icmp eq v22, v79 ; v79 = 0-;; v25 = uextend.i32 v80-;; trapnz v25, user11-;; jump block7+;; v22 = load.i64 notrap aligned readonly can_move v5+96+;; v23 = load.i32 notrap aligned table v22+;; v24 = iconst.i32 2+;; v25 = band v23, v24 ; v24 = 2+;; v85 = iconst.i32 0+;; v86 = icmp eq v25, v85 ; v85 = 0+;; v28 = uextend.i32 v86+;; brif v28, block6, block7+;;+;; block6:+;; v21 = load.i64 notrap aligned readonly can_move v5+72+;; v20 = load.i64 notrap aligned readonly can_move v5+88+;; v29 = iconst.i32 18+;; call_indirect sig1, v21(v20, v5, v29) ; v29 = 18+;; trap user11;;;; block7:-;; v27 = load.i32 notrap aligned table v19-;; v28 = iconst.i32 -3-;; v29 = band v27, v28 ; v28 = -3-;; store notrap aligned table v29, v19-;; v60 = iconst.i32 -4-;; v66 = band v27, v60 ; v60 = -4-;; store notrap aligned table v66, v19-;; v81 = iconst.i32 1-;; v82 = bor v29, v81 ; v81 = 1-;; store notrap aligned table v82, v19+;; v34 = iconst.i32 -3+;; v35 = band.i32 v23, v34 ; v34 = -3+;; store notrap aligned table v35, v22+;; v66 = iconst.i32 -4+;; v72 = band.i32 v23, v66 ; v66 = -4+;; store notrap aligned table v72, v22+;; v87 = iconst.i32 1+;; v88 = bor v35, v87 ; v87 = 1+;; store notrap aligned table v88, v22;; jump block8;;;; block8:@@ -120,17 +132,17 @@;; jump block10;;;; block10:-;; v45 = load.i32 notrap aligned table v12-;; v33 = iconst.i32 -2-;; v47 = band v45, v33 ; v33 = -2-;; store notrap aligned table v47, v12-;; v83 = iconst.i32 1-;; v84 = bor v45, v83 ; v83 = 1-;; store notrap aligned table v84, v12-;; v55 = load.i32 notrap aligned table v19-;; v85 = iconst.i32 2-;; v86 = bor v55, v85 ; v85 = 2-;; store notrap aligned table v86, v19+;; v51 = load.i32 notrap aligned table v12+;; v39 = iconst.i32 -2+;; v53 = band v51, v39 ; v39 = -2+;; store notrap aligned table v53, v12+;; v89 = iconst.i32 1+;; v90 = bor v51, v89 ; v89 = 1+;; store notrap aligned table v90, v12+;; v61 = load.i32 notrap aligned table v22+;; v91 = iconst.i32 2+;; v92 = bor v61, v91 ; v91 = 2+;; store notrap aligned table v92, v22;; jump block3;;;; block3:@@ -140,6 +152,6 @@;; @00f0 jump block1;;;; block1:-;; v70 = iconst.i32 1276-;; @00f0 return v70 ; v70 = 1276+;; v76 = iconst.i32 1276+;; @00f0 return v76 ; v76 = 1276;; }diff --git a/tests/disas/component-model/direct-adapter-calls-x64.wat b/tests/disas/component-model/direct-adapter-calls-x64.watindex c2062cbbe4..36096bbf26 100644--- a/tests/disas/component-model/direct-adapter-calls-x64.wat+++ b/tests/disas/component-model/direct-adapter-calls-x64.wat@@ -80,51 +80,57 @@;; retq;; 4f: ud2;;-;; wasm[2]::function[1]:+;; wasm[2]::function[2]:;; pushq %rbp;; movq %rsp, %rbp;; movq 8(%rdi), %r10;; movq 0x10(%r10), %r10;; addq $0x20, %r10;; cmpq %rsp, %r10-;; ja 0xfe+;; ja 0x120;; 79: subq $0x10, %rsp;; movq %rbx, (%rsp)-;; movq %r14, 8(%rsp)-;; movq 0x60(%rdi), %rbx-;; movl (%rbx), %r9d-;; testl $1, %r9d-;; je 0x100-;; 9a: movq 0x48(%rdi), %r14-;; movq %rdi, %r11-;; movl (%r14), %esi-;; testl $2, %esi-;; je 0x102-;; b0: movl (%r14), %ecx-;; movq %rcx, %rax-;; andl $0xfffffffd, %eax-;; movl %eax, (%r14)-;; andl $0xfffffffc, %ecx-;; movl %ecx, (%r14)-;; orl $1, %eax-;; movl %eax, (%r14)-;; movq %r11, %r10-;; movq 0x40(%r10), %rdi-;; movq %r10, %rsi+;; movq %r13, 8(%rsp)+;; movq 0x78(%rdi), %rbx+;; movl (%rbx), %eax+;; testl $1, %eax+;; je 0x10b+;; 97: movq 0x60(%rdi), %r13+;; movq %rdi, %rsi+;; movl (%r13), %eax+;; testl $2, %eax+;; je 0xf9+;; ad: movq %rax, %r8+;; andl $0xfffffffd, %r8d+;; movl %r8d, (%r13)+;; andl $0xfffffffc, %eax+;; movl %eax, (%r13)+;; orl $1, %r8d+;; movl %r8d, (%r13)+;; movq 0x40(%rsi), %rdi;; callq 0-;; movl (%rbx), %edx-;; movq %rdx, %r9-;; andl $0xfffffffe, %r9d-;; movl %r9d, (%rbx)-;; orl $1, %edx-;; movl %edx, (%rbx)-;; orl $2, (%r14)+;; movl (%rbx), %r10d+;; movq %r10, %rsi+;; andl $0xfffffffe, %esi+;; movl %esi, (%rbx)+;; orl $1, %r10d+;; movl %r10d, (%rbx)+;; orl $2, (%r13);; movq (%rsp), %rbx-;; movq 8(%rsp), %r14+;; movq 8(%rsp), %r13;; addq $0x10, %rsp;; movq %rbp, %rsp;; popq %rbp;; retq-;; fe: ud2-;; 100: ud2-;; 102: ud2+;; f9: movq 0x48(%rsi), %r8+;; fd: movq 0x58(%rsi), %rdi+;; 101: movl $0x12, %edx+;; 106: callq *%r8+;; 109: ud2+;; 10b: movq %rdi, %rsi+;; 10e: movq 0x48(%rsi), %r10+;; 112: movq 0x58(%rsi), %rdi+;; 116: movl $0x18, %edx+;; 11b: callq *%r10+;; 11e: ud2+;; 120: ud2diff --git a/tests/disas/component-model/direct-adapter-calls.wat b/tests/disas/component-model/direct-adapter-calls.watindex c342cfd0fe..2d95304311 100644--- a/tests/disas/component-model/direct-adapter-calls.wat+++ b/tests/disas/component-model/direct-adapter-calls.wat@@ -96,59 +96,71 @@;; gv1 = load.i64 notrap aligned readonly gv0+8;; gv2 = load.i64 notrap aligned gv1+16;; gv3 = vmctx-;; gv4 = load.i64 notrap aligned readonly can_move gv3+96-;; gv5 = load.i64 notrap aligned readonly can_move gv3+72-;; sig0 = (i64 vmctx, i64, i32) -> i32 tail-;; fn0 = colocated u0:0 sig0+;; gv4 = load.i64 notrap aligned readonly can_move gv3+120+;; gv5 = load.i64 notrap aligned readonly can_move gv3+96+;; sig0 = (i64 vmctx, i64, i32) tail+;; sig1 = (i64 vmctx, i64, i32) -> i32 tail+;; fn0 = colocated u0:0 sig1;; stack_limit = gv2;;;; block0(v0: i64, v1: i64, v2: i32):-;; @0064 v5 = load.i64 notrap aligned readonly can_move v0+96-;; @0064 v6 = load.i32 notrap aligned table v5-;; @0066 v7 = iconst.i32 1-;; @0068 v8 = band v6, v7 ; v7 = 1-;; @0062 v4 = iconst.i32 0-;; @0069 v9 = icmp eq v8, v4 ; v4 = 0-;; @0069 v10 = uextend.i32 v9-;; @006c trapnz v10, user11-;; @006a jump block3+;; @0077 v5 = load.i64 notrap aligned readonly can_move v0+120+;; @0077 v6 = load.i32 notrap aligned table v5+;; @0079 v7 = iconst.i32 1+;; @007b v8 = band v6, v7 ; v7 = 1+;; @0075 v4 = iconst.i32 0+;; @007c v9 = icmp eq v8, v4 ; v4 = 0+;; @007c v10 = uextend.i32 v9+;; @007d brif v10, block2, block3+;;+;; block2:+;; v94 = load.i64 notrap aligned readonly can_move v0+72+;; v95 = load.i64 notrap aligned readonly can_move v0+88+;; @007f v11 = iconst.i32 24+;; @0081 call_indirect sig0, v94(v95, v0, v11) ; v11 = 24+;; @0083 trap user11;;;; block3:-;; @006e v11 = load.i64 notrap aligned readonly can_move v0+72-;; @006e v12 = load.i32 notrap aligned table v11-;; @0070 v13 = iconst.i32 2-;; @0072 v14 = band v12, v13 ; v13 = 2-;; v79 = iconst.i32 0-;; v80 = icmp eq v14, v79 ; v79 = 0-;; @0073 v16 = uextend.i32 v80-;; @0076 trapnz v16, user11-;; @0074 jump block5+;; @0085 v15 = load.i64 notrap aligned readonly can_move v0+96+;; @0085 v16 = load.i32 notrap aligned table v15+;; @0087 v17 = iconst.i32 2+;; @0089 v18 = band v16, v17 ; v17 = 2+;; v87 = iconst.i32 0+;; v88 = icmp eq v18, v87 ; v87 = 0+;; @008a v20 = uextend.i32 v88+;; @008b brif v20, block4, block5+;;+;; block4:+;; @0081 v14 = load.i64 notrap aligned readonly can_move v0+72+;; @0081 v13 = load.i64 notrap aligned readonly can_move v0+88+;; @008d v21 = iconst.i32 18+;; @008f call_indirect sig0, v14(v13, v0, v21) ; v21 = 18+;; @0091 trap user11;;;; block5:-;; @0078 v18 = load.i32 notrap aligned table v11-;; @007a v19 = iconst.i32 -3-;; @007c v20 = band v18, v19 ; v19 = -3-;; @007d store notrap aligned table v20, v11-;; v67 = iconst.i32 -4-;; v73 = band v18, v67 ; v67 = -4-;; @0084 store notrap aligned table v73, v11-;; v81 = iconst.i32 1-;; v82 = bor v20, v81 ; v81 = 1-;; @008d store notrap aligned table v82, v11-;; @008f v33 = load.i64 notrap aligned readonly can_move v0+64-;; @008f v34 = call fn0(v33, v0, v2)-;; @0093 v36 = load.i32 notrap aligned table v5-;; @0081 v24 = iconst.i32 -2-;; @0097 v38 = band v36, v24 ; v24 = -2-;; @0098 store notrap aligned table v38, v5-;; v83 = bor v36, v81 ; v81 = 1-;; @00a1 store notrap aligned table v83, v5-;; @00a3 v46 = load.i32 notrap aligned table v11-;; v84 = iconst.i32 2-;; v85 = bor v46, v84 ; v84 = 2-;; @00a8 store notrap aligned table v85, v11-;; @00aa jump block1+;; @0095 v27 = iconst.i32 -3+;; @0097 v28 = band.i32 v16, v27 ; v27 = -3+;; @0098 store notrap aligned table v28, v15+;; v75 = iconst.i32 -4+;; v81 = band.i32 v16, v75 ; v75 = -4+;; @009f store notrap aligned table v81, v15+;; v89 = iconst.i32 1+;; v90 = bor v28, v89 ; v89 = 1+;; @00a8 store notrap aligned table v90, v15+;; @00aa v41 = load.i64 notrap aligned readonly can_move v0+64+;; @00aa v42 = call fn0(v41, v0, v2)+;; @00ae v44 = load.i32 notrap aligned table v5+;; @009c v32 = iconst.i32 -2+;; @00b2 v46 = band v44, v32 ; v32 = -2+;; @00b3 store notrap aligned table v46, v5+;; v91 = bor v44, v89 ; v89 = 1+;; @00bc store notrap aligned table v91, v5+;; @00be v54 = load.i32 notrap aligned table v15+;; v92 = iconst.i32 2+;; v93 = bor v54, v92 ; v92 = 2+;; @00c3 store notrap aligned table v93, v15+;; @00c5 jump block1;;;; block1:-;; @00aa return v34+;; @00c5 return v42;; }diff --git a/tests/disas/component-model/enum.wat b/tests/disas/component-model/enum.watindex e1ad99c9cc..29a1042786 100644--- a/tests/disas/component-model/enum.wat+++ b/tests/disas/component-model/enum.wat@@ -31,73 +31,3 @@(with "f" (func $i1 "f")))))-;; function u2:0(i64 vmctx, i64) -> i32 tail {-;; gv0 = vmctx-;; gv1 = load.i64 notrap aligned readonly gv0+8-;; gv2 = load.i64 notrap aligned gv1+16-;; gv3 = vmctx-;; gv4 = load.i64 notrap aligned readonly can_move gv3+96-;; gv5 = load.i64 notrap aligned readonly can_move gv3+72-;; sig0 = (i64 vmctx, i64) -> i32 tail-;; fn0 = colocated u0:0 sig0-;; stack_limit = gv2-;;-;; block0(v0: i64, v1: i64):-;; @0063 v4 = load.i64 notrap aligned readonly can_move v0+96-;; @0063 v5 = load.i32 notrap aligned table v4-;; @0065 v6 = iconst.i32 1-;; @0067 v7 = band v5, v6 ; v6 = 1-;; @0061 v3 = iconst.i32 0-;; @0068 v8 = icmp eq v7, v3 ; v3 = 0-;; @0068 v9 = uextend.i32 v8-;; @006b trapnz v9, user11-;; @0069 jump block3-;;-;; block3:-;; @006d v10 = load.i64 notrap aligned readonly can_move v0+72-;; @006d v11 = load.i32 notrap aligned table v10-;; @006f v12 = iconst.i32 2-;; @0071 v13 = band v11, v12 ; v12 = 2-;; v79 = iconst.i32 0-;; v80 = icmp eq v13, v79 ; v79 = 0-;; @0072 v15 = uextend.i32 v80-;; @0075 trapnz v15, user11-;; @0073 jump block5-;;-;; block5:-;; @0077 v17 = load.i32 notrap aligned table v10-;; @0079 v18 = iconst.i32 -3-;; @007b v19 = band v17, v18 ; v18 = -3-;; @007c store notrap aligned table v19, v10-;; v69 = iconst.i32 -4-;; v75 = band v17, v69 ; v69 = -4-;; @0083 store notrap aligned table v75, v10-;; v81 = iconst.i32 1-;; v82 = bor v19, v81 ; v81 = 1-;; @008a store notrap aligned table v82, v10-;; @008c v32 = load.i64 notrap aligned readonly can_move v0+64-;; @008c v33 = call fn0(v32, v0)-;; @0090 v35 = load.i32 notrap aligned table v4-;; @0080 v23 = iconst.i32 -2-;; @0094 v37 = band v35, v23 ; v23 = -2-;; @0095 store notrap aligned table v37, v4-;; @009b v39 = iconst.i32 3-;; @009d v40 = icmp ugt v33, v39 ; v39 = 3-;; @009d v41 = uextend.i32 v40-;; @00a0 trapnz v41, user11-;; @009e jump block7-;;-;; block7:-;; @00a4 v43 = load.i32 notrap aligned table v4-;; v83 = iconst.i32 1-;; v84 = bor v43, v83 ; v83 = 1-;; @00a9 store notrap aligned table v84, v4-;; @00ab v48 = load.i32 notrap aligned table v10-;; v85 = iconst.i32 2-;; v86 = bor v48, v85 ; v85 = 2-;; @00b0 store notrap aligned table v86, v10-;; @00b2 jump block1-;;-;; block1:-;; @00b2 return v33-;; }diff --git a/tests/misc_testsuite/component-model/async/trap-in-post-return.wast b/tests/misc_testsuite/component-model/async/trap-in-post-return.wastdeleted file mode 100644index be36491d29..0000000000--- a/tests/misc_testsuite/component-model/async/trap-in-post-return.wast+++ /dev/null@@ -1,257 +0,0 @@-;;! component_model_async = true-;;! reference_types = true-;;! gc_types = true--;; $D exports one function for each place in the spec where may_leave is-;; guarded to be true and ensures that the call traps before any other guard.-;; Since each trap tears down the instance, a fresh instance of $Tester is-;; created for each export call.-(component definition $Tester- (component $C- (core module $CM- (func (export "import"))- )- (core instance $cm (instantiate $CM))- (func (export "import") (canon lift (core func $cm "import")))- )- (component $D- (import "import" (func $import))-- (core module $Memory (memory (export "mem") 1))- (core instance $memory (instantiate $Memory))- (type $R (resource (rep i32)))- (type $ST (stream u32))- (type $FT (future u32))- (canon resource.new $R (core func $resource.new))- (canon resource.drop $R (core func $resource.drop))- (canon task.return (core func $task.return))- (canon task.cancel (core func $task.cancel))- (canon thread.yield (core func $yield))- (canon waitable-set.new (core func $waitable-set.new))- (canon waitable-set.wait (memory $memory "mem") (core func $waitable-set.wait))- (canon waitable-set.poll (memory $memory "mem") (core func $waitable-set.poll))- (canon waitable-set.drop (core func $waitable-set.drop))- (canon waitable.join (core func $waitable.join))- (canon subtask.cancel (core func $subtask.cancel))- (canon subtask.drop (core func $subtask.drop))- (canon stream.new $ST (core func $stream.new))- (canon stream.read $ST (memory $memory "mem") (core func $stream.read))- (canon stream.write $ST (memory $memory "mem") (core func $stream.write))- (canon stream.cancel-read $ST (core func $stream.cancel-read))- (canon stream.cancel-write $ST (core func $stream.cancel-write))- (canon stream.drop-readable $ST (core func $stream.drop-readable))- (canon stream.drop-writable $ST (core func $stream.drop-writable))- (canon future.new $FT (core func $future.new))- (canon future.read $FT (memory $memory "mem") (core func $future.read))- (canon future.write $FT (memory $memory "mem") (core func $future.write))- (canon future.cancel-read $FT (core func $future.cancel-read))- (canon future.cancel-write $FT (core func $future.cancel-write))- (canon future.drop-readable $FT (core func $future.drop-readable))- (canon future.drop-writable $FT (core func $future.drop-writable))- (core module $DM- (import "" "mem" (memory 1))- (import "" "import" (func $import))- (import "" "resource.new" (func $resource.new (param i32) (result i32)))- (import "" "resource.drop" (func $resource.drop (param i32)))- (import "" "task.return" (func $task.return))- (import "" "task.cancel" (func $task.cancel))- (import "" "yield" (func $yield (result i32)))- (import "" "waitable-set.new" (func $waitable-set.new (result i32)))- (import "" "waitable-set.wait" (func $waitable-set.wait (param i32 i32) (result i32)))- (import "" "waitable-set.poll" (func $waitable-set.poll (param i32 i32) (result i32)))- (import "" "waitable-set.drop" (func $waitable-set.drop (param i32)))- (import "" "waitable.join" (func $waitable.join (param i32 i32)))- (import "" "subtask.cancel" (func $subtask.cancel (param i32) (result i32)))- (import "" "subtask.drop" (func $subtask.drop (param i32)))- (import "" "stream.new" (func $stream.new (result i64)))- (import "" "stream.read" (func $stream.read (param i32 i32 i32) (result i32)))- (import "" "stream.write" (func $stream.write (param i32 i32 i32) (result i32)))- (import "" "stream.cancel-read" (func $stream.cancel-read (param i32) (result i32)))- (import "" "stream.cancel-write" (func $stream.cancel-write (param i32) (result i32)))- (import "" "stream.drop-readable" (func $stream.drop-readable (param i32)))- (import "" "stream.drop-writable" (func $stream.drop-writable (param i32)))- (import "" "future.new" (func $future.new (result i64)))- (import "" "future.read" (func $future.read (param i32 i32) (result i32)))- (import "" "future.write" (func $future.write (param i32 i32) (result i32)))- (import "" "future.cancel-read" (func $future.cancel-read (param i32) (result i32)))- (import "" "future.cancel-write" (func $future.cancel-write (param i32) (result i32)))- (import "" "future.drop-readable" (func $future.drop-readable (param i32)))- (import "" "future.drop-writable" (func $future.drop-writable (param i32)))-- (func (export "noop"))- (func (export "trap-calling-import") (call $import))- (func (export "trap-calling-resource-new") (drop (call $resource.new (i32.const 0))))- (func (export "trap-calling-resource-drop") (call $resource.drop (i32.const 0)))- (func (export "trap-calling-task-return") (call $task.return))- (func (export "trap-calling-task-cancel") (call $task.cancel))- (func (export "trap-calling-yield") (drop (call $yield)))- (func (export "trap-calling-waitable-set-new") (drop (call $waitable-set.new)))- (func (export "trap-calling-waitable-set-wait") (drop (call $waitable-set.wait (i32.const 0) (i32.const 0))))- (func (export "trap-calling-waitable-set-poll") (drop (call $waitable-set.poll (i32.const 0) (i32.const 0))))- (func (export "trap-calling-waitable-set-drop") (call $waitable-set.drop (i32.const 0)))- (func (export "trap-calling-waitable-join") (call $waitable.join (i32.const 0) (i32.const 0)))- (func (export "trap-calling-subtask-cancel") (drop (call $subtask.cancel (i32.const 0))))- (func (export "trap-calling-subtask-drop") (call $subtask.drop (i32.const 0)))- (func (export "trap-calling-stream-new") (drop (call $stream.new)))- (func (export "trap-calling-stream-read") (drop (call $stream.read (i32.const 0) (i32.const 0) (i32.const 0))))- (func (export "trap-calling-stream-write") (drop (call $stream.write (i32.const 0) (i32.const 0) (i32.const 0))))- (func (export "trap-calling-stream-cancel-read") (drop (call $stream.cancel-read (i32.const 0))))- (func (export "trap-calling-stream-cancel-write") (drop (call $stream.cancel-write (i32.const 0))))- (func (export "trap-calling-stream-drop-readable") (call $stream.drop-readable (i32.const 0)))- (func (export "trap-calling-stream-drop-writable") (call $stream.drop-writable (i32.const 0)))- (func (export "trap-calling-future-new") (drop (call $future.new)))- (func (export "trap-calling-future-read") (drop (call $future.read (i32.const 0) (i32.const 0))))- (func (export "trap-calling-future-write") (drop (call $future.write (i32.const 0) (i32.const 0))))- (func (export "trap-calling-future-cancel-read") (drop (call $future.cancel-read (i32.const 0))))- (func (export "trap-calling-future-cancel-write") (drop (call $future.cancel-write (i32.const 0))))- (func (export "trap-calling-future-drop-readable") (call $future.drop-readable (i32.const 0)))- (func (export "trap-calling-future-drop-writable") (call $future.drop-writable (i32.const 0)))- )- (canon lower (func $import) (core func $import'))- (core instance $dm (instantiate $DM (with "" (instance- (export "mem" (memory $memory "mem"))- (export "import" (func $import'))- (export "resource.new" (func $resource.new))- (export "resource.drop" (func $resource.drop))- (export "task.return" (func $task.return))- (export "task.cancel" (func $task.cancel))- (export "yield" (func $yield))- (export "waitable-set.new" (func $waitable-set.new))- (export "waitable-set.wait" (func $waitable-set.wait))- (export "waitable-set.poll" (func $waitable-set.poll))- (export "waitable-set.drop" (func $waitable-set.drop))- (export "waitable.join" (func $waitable.join))- (export "subtask.cancel" (func $subtask.cancel))- (export "subtask.drop" (func $subtask.drop))- (export "stream.new" (func $stream.new))- (export "stream.read" (func $stream.read))- (export "stream.write" (func $stream.write))- (export "stream.cancel-read" (func $stream.cancel-read))- (export "stream.cancel-write" (func $stream.cancel-write))- (export "stream.drop-readable" (func $stream.drop-readable))- (export "stream.drop-writable" (func $stream.drop-writable))- (export "future.new" (func $future.new))- (export "future.read" (func $future.read))- (export "future.write" (func $future.write))- (export "future.cancel-read" (func $future.cancel-read))- (export "future.cancel-write" (func $future.cancel-write))- (export "future.drop-readable" (func $future.drop-readable))- (export "future.drop-writable" (func $future.drop-writable))- ))))- (func (export "trap-calling-import") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-import"))))- (func (export "trap-calling-resource-new") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-resource-new"))))- (func (export "trap-calling-resource-drop") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-resource-drop"))))- (func (export "trap-calling-task-return") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-task-return"))))- (func (export "trap-calling-task-cancel") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-task-cancel"))))- (func (export "trap-calling-yield") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-yield"))))- (func (export "trap-calling-waitable-set-new") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-waitable-set-new"))))- (func (export "trap-calling-waitable-set-wait") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-waitable-set-wait"))))- (func (export "trap-calling-waitable-set-poll") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-waitable-set-poll"))))- (func (export "trap-calling-waitable-set-drop") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-waitable-set-drop"))))- (func (export "trap-calling-waitable-join") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-waitable-join"))))- (func (export "trap-calling-subtask-cancel") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-subtask-cancel"))))- (func (export "trap-calling-subtask-drop") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-subtask-drop"))))- (func (export "trap-calling-stream-new") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-stream-new"))))- (func (export "trap-calling-stream-read") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-stream-read"))))- (func (export "trap-calling-stream-write") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-stream-write"))))- (func (export "trap-calling-stream-cancel-read") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-stream-cancel-read"))))- (func (export "trap-calling-stream-cancel-write") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-stream-cancel-write"))))- (func (export "trap-calling-stream-drop-readable") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-stream-drop-readable"))))- (func (export "trap-calling-stream-drop-writable") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-stream-drop-writable"))))- (func (export "trap-calling-future-new") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-future-new"))))- (func (export "trap-calling-future-read") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-future-read"))))- (func (export "trap-calling-future-write") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-future-write"))))- (func (export "trap-calling-future-cancel-read") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-future-cancel-read"))))- (func (export "trap-calling-future-cancel-write") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-future-cancel-write"))))- (func (export "trap-calling-future-drop-readable") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-future-drop-readable"))))- (func (export "trap-calling-future-drop-writable") (canon lift (core func $dm "noop") (post-return (func $dm "trap-calling-future-drop-writable"))))- )- (instance $c (instantiate $C))- (instance $d (instantiate $D (with "import" (func $c "import"))))- (func (export "trap-calling-import") (alias export $d "trap-calling-import"))- (func (export "trap-calling-resource-new") (alias export $d "trap-calling-resource-new"))- (func (export "trap-calling-resource-drop") (alias export $d "trap-calling-resource-drop"))- (func (export "trap-calling-task-return") (alias export $d "trap-calling-task-return"))- (func (export "trap-calling-task-cancel") (alias export $d "trap-calling-task-cancel"))- (func (export "trap-calling-yield") (alias export $d "trap-calling-yield"))- (func (export "trap-calling-waitable-set-new") (alias export $d "trap-calling-waitable-set-new"))- (func (export "trap-calling-waitable-set-wait") (alias export $d "trap-calling-waitable-set-wait"))- (func (export "trap-calling-waitable-set-poll") (alias export $d "trap-calling-waitable-set-poll"))- (func (export "trap-calling-waitable-set-drop") (alias export $d "trap-calling-waitable-set-drop"))- (func (export "trap-calling-waitable-join") (alias export $d "trap-calling-waitable-join"))- (func (export "trap-calling-subtask-cancel") (alias export $d "trap-calling-subtask-cancel"))- (func (export "trap-calling-subtask-drop") (alias export $d "trap-calling-subtask-drop"))- (func (export "trap-calling-stream-new") (alias export $d "trap-calling-stream-new"))- (func (export "trap-calling-stream-read") (alias export $d "trap-calling-stream-read"))- (func (export "trap-calling-stream-write") (alias export $d "trap-calling-stream-write"))- (func (export "trap-calling-stream-cancel-read") (alias export $d "trap-calling-stream-cancel-read"))- (func (export "trap-calling-stream-cancel-write") (alias export $d "trap-calling-stream-cancel-write"))- (func (export "trap-calling-stream-drop-readable") (alias export $d "trap-calling-stream-drop-readable"))- (func (export "trap-calling-stream-drop-writable") (alias export $d "trap-calling-stream-drop-writable"))- (func (export "trap-calling-future-new") (alias export $d "trap-calling-future-new"))- (func (export "trap-calling-future-read") (alias export $d "trap-calling-future-read"))- (func (export "trap-calling-future-write") (alias export $d "trap-calling-future-write"))- (func (export "trap-calling-future-cancel-read") (alias export $d "trap-calling-future-cancel-read"))- (func (export "trap-calling-future-cancel-write") (alias export $d "trap-calling-future-cancel-write"))- (func (export "trap-calling-future-drop-readable") (alias export $d "trap-calling-future-drop-readable"))- (func (export "trap-calling-future-drop-writable") (alias export $d "trap-calling-future-drop-writable"))-)--(component instance $i1 $Tester)-;; FIXME(#11683): This should also be "cannot leave component instance". Once-;; that issue is fixed, this whole file can be removed in favor of the upstream-;; version in `tests/component-model`. See also the FIXME in-;; `crates/test-util/src/wast.rs` regarding this file.-(assert_trap (invoke "trap-calling-import") "wasm `unreachable` instruction executed")-(component instance $i2 $Tester)-(assert_trap (invoke "trap-calling-resource-new") "cannot leave component instance")-(component instance $i3 $Tester)-(assert_trap (invoke "trap-calling-resource-drop") "cannot leave component instance")-(component instance $i4 $Tester)-(assert_trap (invoke "trap-calling-task-return") "cannot leave component instance")-(component instance $i5 $Tester)-(assert_trap (invoke "trap-calling-task-cancel") "cannot leave component instance")-(component instance $i6 $Tester)-(assert_trap (invoke "trap-calling-yield") "cannot leave component instance")-(component instance $i7 $Tester)-(assert_trap (invoke "trap-calling-waitable-set-new") "cannot leave component instance")-(component instance $i8 $Tester)-(assert_trap (invoke "trap-calling-waitable-set-wait") "cannot leave component instance")-(component instance $i9 $Tester)-(assert_trap (invoke "trap-calling-waitable-set-poll") "cannot leave component instance")-(component instance $i10 $Tester)-(assert_trap (invoke "trap-calling-waitable-set-drop") "cannot leave component instance")-(component instance $i11 $Tester)-(assert_trap (invoke "trap-calling-waitable-join") "cannot leave component instance")-(component instance $i12 $Tester)-(assert_trap (invoke "trap-calling-subtask-cancel") "cannot leave component instance")-(component instance $i13 $Tester)-(assert_trap (invoke "trap-calling-subtask-drop") "cannot leave component instance")-(component instance $i14 $Tester)-(assert_trap (invoke "trap-calling-stream-new") "cannot leave component instance")-(component instance $i15 $Tester)-(assert_trap (invoke "trap-calling-stream-read") "cannot leave component instance")-(component instance $i16 $Tester)-(assert_trap (invoke "trap-calling-stream-write") "cannot leave component instance")-(component instance $i17 $Tester)-(assert_trap (invoke "trap-calling-stream-cancel-read") "cannot leave component instance")-(component instance $i18 $Tester)-(assert_trap (invoke "trap-calling-stream-cancel-write") "cannot leave component instance")-(component instance $i19 $Tester)-(assert_trap (invoke "trap-calling-stream-drop-readable") "cannot leave component instance")-(component instance $i20 $Tester)-(assert_trap (invoke "trap-calling-stream-drop-writable") "cannot leave component instance")-(component instance $i21 $Tester)-(assert_trap (invoke "trap-calling-future-new") "cannot leave component instance")-(component instance $i22 $Tester)-(assert_trap (invoke "trap-calling-future-read") "cannot leave component instance")-(component instance $i23 $Tester)-(assert_trap (invoke "trap-calling-future-write") "cannot leave component instance")-(component instance $i24 $Tester)-(assert_trap (invoke "trap-calling-future-cancel-read") "cannot leave component instance")-(component instance $i25 $Tester)-(assert_trap (invoke "trap-calling-future-cancel-write") "cannot leave component instance")-(component instance $i26 $Tester)-(assert_trap (invoke "trap-calling-future-drop-readable") "cannot leave component instance")-(component instance $i27 $Tester)-(assert_trap (invoke "trap-calling-future-drop-writable") "cannot leave component instance")diff --git a/tests/misc_testsuite/component-model/fused.wast b/tests/misc_testsuite/component-model/fused.wastdeleted file mode 100644index 90f2ed4a1c..0000000000--- a/tests/misc_testsuite/component-model/fused.wast+++ /dev/null@@ -1,1359 +0,0 @@-;;! multi_memory = true--;; smoke test with no arguments and no results-(component- (core module $m- (func (export ""))- )- (core instance $m (instantiate $m))- (func $foo (canon lift (core func $m "")))-- (component $c- (import "a" (func $foo))-- (core func $foo (canon lower (func $foo)))- (core module $m2- (import "" "" (func))- (start 0)- )- (core instance $m2 (instantiate $m2 (with "" (instance (export "" (func $foo))))))- )-- (instance $c (instantiate $c (with "a" (func $foo))))-)--;; boolean parameters-(component- (core module $m- (func (export "assert_true") (param i32)- local.get 0- i32.const 1- i32.eq- i32.eqz- if unreachable end- )- (func (export "assert_false") (param i32)- local.get 0- if unreachable end- )- (func (export "ret-bool") (param i32) (result i32)- local.get 0- )- )- (core instance $m (instantiate $m))- (func $assert_true (param "a" bool) (canon lift (core func $m "assert_true")))- (func $assert_false (param "a" bool) (canon lift (core func $m "assert_false")))- (func $ret_bool (param "a" u32) (result bool) (canon lift (core func $m "ret-bool")))-- (component $c- (import "assert-true" (func $assert_true (param "a" bool)))- (import "assert-false" (func $assert_false (param "a" bool)))- (import "ret-bool" (func $ret_bool (param "a" u32) (result bool)))-- (core func $assert_true (canon lower (func $assert_true)))- (core func $assert_false (canon lower (func $assert_false)))- (core func $ret_bool (canon lower (func $ret_bool)))-- (core module $m2- (import "" "assert-true" (func $assert_true (param i32)))- (import "" "assert-false" (func $assert_false (param i32)))- (import "" "ret-bool" (func $ret_bool (param i32) (result i32)))-- (func $start- (call $assert_true (i32.const 1))- (call $assert_true (i32.const 2))- (call $assert_true (i32.const -1))- (call $assert_false (i32.const 0))-- (if (i32.ne (call $ret_bool (i32.const 1)) (i32.const 1))- (then (unreachable)))- (if (i32.ne (call $ret_bool (i32.const 2)) (i32.const 1))- (then (unreachable)))- (if (i32.ne (call $ret_bool (i32.const -1)) (i32.const 1))- (then (unreachable)))- (if (i32.ne (call $ret_bool (i32.const 0)) (i32.const 0))- (then (unreachable)))- )- (start $start)- )- (core instance $m2 (instantiate $m2- (with "" (instance- (export "assert-true" (func $assert_true))- (export "assert-false" (func $assert_false))- (export "ret-bool" (func $ret_bool))- ))- ))- )-- (instance $c (instantiate $c- (with "assert-true" (func $assert_true))- (with "assert-false" (func $assert_false))- (with "ret-bool" (func $ret_bool))- ))-)--;; lots of parameters and results-(component- (type $roundtrip (func- ;; 20 u32 params- (param "a1" u32) (param "a2" u32) (param "a3" u32) (param "a4" u32) (param "a5" u32)- (param "a6" u32) (param "a7" u32) (param "a8" u32) (param "a9" u32) (param "a10" u32)- (param "a11" u32) (param "a12" u32) (param "a13" u32) (param "a14" u32) (param "a15" u32)- (param "a16" u32) (param "a17" u32) (param "a18" u32) (param "a19" u32) (param "a20" u32)-- ;; 10 u32 results- (result (tuple u32 u32 u32 u32 u32 u32 u32 u32 u32 u32))- ))-- (core module $m- (memory (export "memory") 1)- (func (export "roundtrip") (param $src i32) (result i32)- (local $dst i32)- (if (i32.ne (local.get $src) (i32.const 16))- (then (unreachable)))-- (if (i32.ne (i32.load offset=0 (local.get $src)) (i32.const 1)) (then (unreachable)))- (if (i32.ne (i32.load offset=4 (local.get $src)) (i32.const 2)) (then (unreachable)))- (if (i32.ne (i32.load offset=8 (local.get $src)) (i32.const 3)) (then (unreachable)))- (if (i32.ne (i32.load offset=12 (local.get $src)) (i32.const 4)) (then (unreachable)))- (if (i32.ne (i32.load offset=16 (local.get $src)) (i32.const 5)) (then (unreachable)))- (if (i32.ne (i32.load offset=20 (local.get $src)) (i32.const 6)) (then (unreachable)))- (if (i32.ne (i32.load offset=24 (local.get $src)) (i32.const 7)) (then (unreachable)))- (if (i32.ne (i32.load offset=28 (local.get $src)) (i32.const 8)) (then (unreachable)))- (if (i32.ne (i32.load offset=32 (local.get $src)) (i32.const 9)) (then (unreachable)))- (if (i32.ne (i32.load offset=36 (local.get $src)) (i32.const 10)) (then (unreachable)))- (if (i32.ne (i32.load offset=40 (local.get $src)) (i32.const 11)) (then (unreachable)))- (if (i32.ne (i32.load offset=44 (local.get $src)) (i32.const 12)) (then (unreachable)))- (if (i32.ne (i32.load offset=48 (local.get $src)) (i32.const 13)) (then (unreachable)))- (if (i32.ne (i32.load offset=52 (local.get $src)) (i32.const 14)) (then (unreachable)))- (if (i32.ne (i32.load offset=56 (local.get $src)) (i32.const 15)) (then (unreachable)))- (if (i32.ne (i32.load offset=60 (local.get $src)) (i32.const 16)) (then (unreachable)))- (if (i32.ne (i32.load offset=64 (local.get $src)) (i32.const 17)) (then (unreachable)))- (if (i32.ne (i32.load offset=68 (local.get $src)) (i32.const 18)) (then (unreachable)))- (if (i32.ne (i32.load offset=72 (local.get $src)) (i32.const 19)) (then (unreachable)))- (if (i32.ne (i32.load offset=76 (local.get $src)) (i32.const 20)) (then (unreachable)))-- (local.set $dst (i32.const 500))-- (i32.store offset=0 (local.get $dst) (i32.const 21))- (i32.store offset=4 (local.get $dst) (i32.const 22))- (i32.store offset=8 (local.get $dst) (i32.const 23))- (i32.store offset=12 (local.get $dst) (i32.const 24))- (i32.store offset=16 (local.get $dst) (i32.const 25))- (i32.store offset=20 (local.get $dst) (i32.const 26))- (i32.store offset=24 (local.get $dst) (i32.const 27))- (i32.store offset=28 (local.get $dst) (i32.const 28))- (i32.store offset=32 (local.get $dst) (i32.const 29))- (i32.store offset=36 (local.get $dst) (i32.const 30))-- local.get $dst- )-- (func (export "realloc") (param i32 i32 i32 i32) (result i32)- i32.const 16)- )- (core instance $m (instantiate $m))-- (func $roundtrip (type $roundtrip)- (canon lift (core func $m "roundtrip") (memory $m "memory")- (realloc (func $m "realloc")))- )-- (component $c- (import "roundtrip" (func $roundtrip (type $roundtrip)))-- (core module $libc- (memory (export "memory") 1)- (func (export "realloc") (param i32 i32 i32 i32) (result i32) unreachable)- )- (core instance $libc (instantiate $libc))- (core func $roundtrip- (canon lower (func $roundtrip)- (memory $libc "memory")- (realloc (func $libc "realloc")) ;; FIXME(wasm-tools#693) should not be necessary- )- )-- (core module $m2- (import "libc" "memory" (memory 1))- (import "" "roundtrip" (func $roundtrip (param i32 i32)))-- (func $start- (local $addr i32)- (local $retaddr i32)-- (local.set $addr (i32.const 100))- (call $store_many (i32.const 20) (local.get $addr))-- (local.set $retaddr (i32.const 200))- (call $roundtrip (local.get $addr) (local.get $retaddr))-- (if (i32.ne (i32.load offset=0 (local.get $retaddr)) (i32.const 21)) (then (unreachable)))- (if (i32.ne (i32.load offset=4 (local.get $retaddr)) (i32.const 22)) (then (unreachable)))- (if (i32.ne (i32.load offset=8 (local.get $retaddr)) (i32.const 23)) (then (unreachable)))- (if (i32.ne (i32.load offset=12 (local.get $retaddr)) (i32.const 24)) (then (unreachable)))- (if (i32.ne (i32.load offset=16 (local.get $retaddr)) (i32.const 25)) (then (unreachable)))- (if (i32.ne (i32.load offset=20 (local.get $retaddr)) (i32.const 26)) (then (unreachable)))- (if (i32.ne (i32.load offset=24 (local.get $retaddr)) (i32.const 27)) (then (unreachable)))- (if (i32.ne (i32.load offset=28 (local.get $retaddr)) (i32.const 28)) (then (unreachable)))- (if (i32.ne (i32.load offset=32 (local.get $retaddr)) (i32.const 29)) (then (unreachable)))- (if (i32.ne (i32.load offset=36 (local.get $retaddr)) (i32.const 30)) (then (unreachable)))- )-- (func $store_many (param $amt i32) (param $addr i32)- (local $c i32)- (loop $loop- (local.set $c (i32.add (local.get $c) (i32.const 1)))- (i32.store (local.get $addr) (local.get $c))- (local.set $addr (i32.add (local.get $addr) (i32.const 4)))-- (if (i32.ne (local.get $amt) (local.get $c)) (then (br $loop)))- )- )- (start $start)- )- (core instance $m2 (instantiate $m2- (with "libc" (instance $libc))- (with "" (instance (export "roundtrip" (func $roundtrip))))- ))- )-- (instance $c (instantiate $c- (with "roundtrip" (func $roundtrip))- ))-)--;; this will require multiple adapter modules to get generated-(component- (core module $root (func (export "") (result i32)- i32.const 0- ))- (core instance $root (instantiate $root))- (func $root (result u32) (canon lift (core func $root "")))-- (component $c- (import "thunk" (func $import (result u32)))- (core func $import (canon lower (func $import)))- (core module $reexport- (import "" "" (func $thunk (result i32)))- (func (export "thunk") (result i32)- call $thunk- i32.const 1- i32.add)- )- (core instance $reexport (instantiate $reexport- (with "" (instance- (export "" (func $import))- ))- ))- (func $export (export "thunk2") (result u32)- (canon lift (core func $reexport "thunk"))- )- )-- (instance $c1 (instantiate $c (with "thunk" (func $root))))- (instance $c2 (instantiate $c (with "thunk" (func $c1 "thunk2"))))- (instance $c3 (instantiate $c (with "thunk" (func $c2 "thunk2"))))- (instance $c4 (instantiate $c (with "thunk" (func $c3 "thunk2"))))- (instance $c5 (instantiate $c (with "thunk" (func $c4 "thunk2"))))- (instance $c6 (instantiate $c (with "thunk" (func $c5 "thunk2"))))-- (component $verify- (import "thunk" (func $thunk (result u32)))- (core func $thunk (canon lower (func $thunk)))- (core module $verify- (import "" "" (func $thunk (result i32)))-- (func $start- call $thunk- i32.const 6- i32.ne- if unreachable end- )- (start $start)- )- (core instance (instantiate $verify- (with "" (instance- (export "" (func $thunk))- ))- ))- )- (instance (instantiate $verify (with "thunk" (func $c6 "thunk2"))))-)--;; Fancy case of an adapter using an adapter. Note that this is silly and-;; doesn't actually make any sense at runtime, we just shouldn't panic on a-;; valid component.-(component- (type $tuple20 (tuple- u32 u32 u32 u32 u32- u32 u32 u32 u32 u32- u32 u32 u32 u32 u32- u32 u32 u32 u32 u32))-- (component $realloc- (core module $realloc- (memory (export "memory") 1)- (func (export "realloc") (param i32 i32 i32 i32) (result i32)- unreachable)- )- (core instance $realloc (instantiate $realloc))- (func $realloc (param "a" (tuple u32 u32 u32 u32)) (result u32)- (canon lift (core func $realloc "realloc"))- )- (export "realloc" (func $realloc))- )- (instance $realloc (instantiate $realloc))- (core func $realloc (canon lower (func $realloc "realloc")))-- (core module $m- (memory (export "memory") 1)- (func (export "foo") (param i32))- )- (core instance $m (instantiate $m))- (func $foo (param "a" $tuple20)- (canon lift- (core func $m "foo")- (memory $m "memory")- (realloc (func $realloc))- )- )-- (component $c- (import "foo" (func $foo (param "a" $tuple20)))-- (core module $libc- (memory (export "memory") 1)- (func (export "realloc") (param i32 i32 i32 i32) (result i32)- unreachable)- )- (core instance $libc (instantiate $libc))- (core func $foo- (canon lower (func $foo)- (memory $libc "memory")- (realloc (func $libc "realloc")) ;; FIXME(wasm-tools#693) should not be necessary- )- )- (core module $something- (import "" "foo" (func (param i32)))- )- (core instance (instantiate $something- (with "" (instance- (export "foo" (func $foo))- ))- ))- )- (instance (instantiate $c- (with "foo" (func $foo))- ))-)--;; Don't panic or otherwise create extraneous adapter modules when the same-;; adapter is used twice for a module's argument.-(component- (core module $m- (func (export "foo") (param))- )- (core instance $m (instantiate $m))- (func $foo (canon lift (core func $m "foo")))-- (component $c- (import "foo" (func $foo))- (core func $foo (canon lower (func $foo)))-- (core module $something- (import "" "a" (func))- (import "" "b" (func))- )- (core instance (instantiate $something- (with "" (instance- (export "a" (func $foo))- (export "b" (func $foo))- ))- ))- )- (instance (instantiate $c (with "foo" (func $foo))))-)--;; post-return should get invoked by the generated adapter, if specified-(component- (core module $m- (global $post_called (mut i32) (i32.const 0))- (func (export "foo")- ;; assert `foo-post` not called yet- global.get $post_called- i32.const 1- i32.eq- if unreachable end- )- (func (export "foo-post")- ;; assert `foo-post` not called before- global.get $post_called- i32.const 1- i32.eq- if unreachable end- ;; ... then flag as called- i32.const 1- global.set $post_called- )- (func (export "assert-post")- global.get $post_called- i32.const 1- i32.ne- if unreachable end- )- )- (core instance $m (instantiate $m))- (func $foo (canon lift (core func $m "foo") (post-return (func $m "foo-post"))))- (func $assert_post (canon lift (core func $m "assert-post")))-- (component $c- (import "foo" (func $foo))- (import "assert-post" (func $assert_post))- (core func $foo (canon lower (func $foo)))- (core func $assert_post (canon lower (func $assert_post)))-- (core module $something- (import "" "foo" (func $foo))- (import "" "assert-post" (func $assert_post))-- (func $start- call $foo- call $assert_post- )- (start $start)- )- (core instance (instantiate $something- (with "" (instance- (export "foo" (func $foo))- (export "assert-post" (func $assert_post))- ))- ))- )- (instance (instantiate $c- (with "foo" (func $foo))- (with "assert-post" (func $assert_post))- ))-)--;; post-return passes the results-(component- (core module $m- (func (export "foo") (result i32) i32.const 100)- (func (export "foo-post") (param i32)- (if (i32.ne (local.get 0) (i32.const 100)) (then (unreachable))))- )- (core instance $m (instantiate $m))- (func $foo (result u32)- (canon lift (core func $m "foo") (post-return (func $m "foo-post"))))-- (component $c- (import "foo" (func $foo (result u32)))- (core func $foo (canon lower (func $foo)))-- (core module $something- (import "" "foo" (func $foo (result i32)))- (func $start- (if (i32.ne (call $foo) (i32.const 100)) (then (unreachable))))- (start $start)- )- (core instance (instantiate $something- (with "" (instance- (export "foo" (func $foo))- ))- ))- )- (instance (instantiate $c- (with "foo" (func $foo))- ))-)--;; callee retptr misaligned-(assert_trap- (component- (component $c1- (core module $m- (memory (export "memory") 1)- (func (export "r") (result i32) i32.const 1)- )- (core instance $m (instantiate $m))- (func (export "r") (result (tuple u32 u32))- (canon lift (core func $m "r") (memory $m "memory"))- )- )- (component $c2- (import "r" (func $r (result (tuple u32 u32))))- (core module $libc (memory (export "memory") 1))- (core instance $libc (instantiate $libc))- (core func $r (canon lower (func $r) (memory $libc "memory")))-- (core module $m- (import "" "r" (func $r (param i32)))- (func $start- i32.const 4- call $r- )- (start $start)- )- (core instance (instantiate $m- (with "" (instance (export "r" (func $r))))- ))- )- (instance $c1 (instantiate $c1))- (instance $c2 (instantiate $c2 (with "r" (func $c1 "r"))))- )- "unreachable")--;; caller retptr misaligned-(assert_trap- (component- (component $c1- (core module $m- (memory (export "memory") 1)- (func (export "r") (result i32) i32.const 0)- )- (core instance $m (instantiate $m))- (func (export "r") (result (tuple u32 u32))- (canon lift (core func $m "r") (memory $m "memory"))- )- )- (component $c2- (import "r" (func $r (result (tuple u32 u32))))- (core module $libc (memory (export "memory") 1))- (core instance $libc (instantiate $libc))- (core func $r (canon lower (func $r) (memory $libc "memory")))-- (core module $m- (import "" "r" (func $r (param i32)))- (func $start- i32.const 1- call $r- )- (start $start)- )- (core instance (instantiate $m- (with "" (instance (export "r" (func $r))))- ))- )- (instance $c1 (instantiate $c1))- (instance $c2 (instantiate $c2 (with "r" (func $c1 "r"))))- )- "unreachable")--;; callee argptr misaligned-(assert_trap- (component- (type $big (tuple u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32))-- (component $c1- (core module $m- (memory (export "memory") 1)- (func (export "r") (param i32))- (func (export "realloc") (param i32 i32 i32 i32) (result i32)- i32.const 1)- )- (core instance $m (instantiate $m))- (func (export "r") (param "a" $big)- (canon lift (core func $m "r") (memory $m "memory") (realloc (func $m "realloc")))- )- )- (component $c2- (import "r" (func $r (param "a" $big)))- (core module $libc- (memory (export "memory") 1)- (func (export "realloc") (param i32 i32 i32 i32) (result i32) unreachable)- )- (core instance $libc (instantiate $libc))- (core func $r- (canon lower (func $r)- (memory $libc "memory")- (realloc (func $libc "realloc")) ;; FIXME(wasm-tools#693) should not be necessary- )- )-- (core module $m- (import "" "r" (func $r (param i32)))- (func $start- i32.const 4- call $r- )- (start $start)- )- (core instance (instantiate $m- (with "" (instance (export "r" (func $r))))- ))- )- (instance $c1 (instantiate $c1))- (instance $c2 (instantiate $c2 (with "r" (func $c1 "r"))))- )- "unreachable")--;; caller argptr misaligned-(assert_trap- (component- (type $big (tuple u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32 u32))-- (component $c1- (core module $m- (memory (export "memory") 1)- (func (export "r") (param i32))- (func (export "realloc") (param i32 i32 i32 i32) (result i32)- i32.const 4)- )- (core instance $m (instantiate $m))- (func (export "r") (param "a" $big)- (canon lift (core func $m "r") (memory $m "memory") (realloc (func $m "realloc")))- )- )- (component $c2- (import "r" (func $r (param "a" $big)))- (core module $libc- (memory (export "memory") 1)- (func (export "realloc") (param i32 i32 i32 i32) (result i32) unreachable)- )- (core instance $libc (instantiate $libc))- (core func $r- (canon lower (func $r)- (memory $libc "memory")- (realloc (func $libc "realloc")) ;; FIXME(wasm-tools#693) should not be necessary- )- )--- (core module $m- (import "" "r" (func $r (param i32)))- (func $start- i32.const 1- call $r- )- (start $start)- )- (core instance (instantiate $m- (with "" (instance (export "r" (func $r))))- ))- )- (instance $c1 (instantiate $c1))- (instance $c2 (instantiate $c2 (with "r" (func $c1 "r"))))- )- "unreachable")--;; simple variant translation-(component- (component $c1- (type $a' (variant (case "x")))- (export $a "a" (type $a'))- (type $b' (variant (case "y")))- (export $b "b" (type $b'))-- (core module $m- (func (export "r") (param i32) (result i32)- (if (i32.ne (local.get 0) (i32.const 0)) (then (unreachable)))- i32.const 0- )- )- (core instance $m (instantiate $m))- (func (export "r") (param "a" $a) (result $b) (canon lift (core func $m "r")))- )- (component $c2- (type $a' (variant (case "x")))- (import "a" (type $a (eq $a')))- (type $b' (variant (case "y")))- (import "b" (type $b (eq $b')))-- (import "r" (func $r (param "a" $a) (result $b)))- (core func $r (canon lower (func $r)))-- (core module $m- (import "" "r" (func $r (param i32) (result i32)))- (func $start- i32.const 0- call $r- i32.const 0- i32.ne- if unreachable end- )- (start $start)- )- (core instance (instantiate $m- (with "" (instance (export "r" (func $r))))- ))- )- (instance $c1 (instantiate $c1))- (instance $c2 (instantiate $c2- (with "a" (type $c1 "a"))- (with "b" (type $c1 "b"))- (with "r" (func $c1 "r"))- ))-)--;; invalid variant discriminant in a parameter-(assert_trap- (component- (component $c1- (type $a' (variant (case "x")))- (export $a "a" (type $a'))- (core module $m- (func (export "r") (param i32))- )- (core instance $m (instantiate $m))- (func (export "r") (param "a" $a) (canon lift (core func $m "r")))- )- (component $c2- (type $a' (variant (case "x")))- (import "a" (type $a (eq $a')))- (import "r" (func $r (param "a" $a)))- (core func $r (canon lower (func $r)))-- (core module $m- (import "" "r" (func $r (param i32)))- (func $start- i32.const 1- call $r- )- (start $start)- )- (core instance (instantiate $m- (with "" (instance (export "r" (func $r))))- ))- )- (instance $c1 (instantiate $c1))- (instance $c2 (instantiate $c2- (with "a" (type $c1 "a"))- (with "r" (func $c1 "r"))- ))- )- "unreachable")--;; invalid variant discriminant in a result-(assert_trap- (component- (component $c1- (type $a' (variant (case "x")))- (export $a "a" (type $a'))- (core module $m- (func (export "r") (result i32) i32.const 1)- )- (core instance $m (instantiate $m))- (func (export "r") (result $a) (canon lift (core func $m "r")))- )- (component $c2- (type $a' (variant (case "x")))- (import "a" (type $a (eq $a')))- (import "r" (func $r (result $a)))- (core func $r (canon lower (func $r)))-- (core module $m- (import "" "r" (func $r (result i32)))- (func $start call $r drop)- (start $start)- )- (core instance (instantiate $m- (with "" (instance (export "r" (func $r))))- ))- )- (instance $c1 (instantiate $c1))- (instance $c2 (instantiate $c2- (with "a" (type $c1 "a"))- (with "r" (func $c1 "r"))- ))- )- "unreachable")---;; extra bits are chopped off-(component- (component $c1- (core module $m- (func (export "u") (param i32)- (if (i32.ne (local.get 0) (i32.const 0)) (then (unreachable)))- )- (func (export "s") (param i32)- (if (i32.ne (local.get 0) (i32.const -1)) (then (unreachable)))- )- )- (core instance $m (instantiate $m))- (func (export "u8") (param "a" u8) (canon lift (core func $m "u")))- (func (export "u16") (param "a" u16) (canon lift (core func $m "u")))- (func (export "s8") (param "a" s8) (canon lift (core func $m "s")))- (func (export "s16") (param "a" s16) (canon lift (core func $m "s")))- )- (component $c2- (import "a" (instance $i- (export "u8" (func (param "a" u8)))- (export "s8" (func (param "a" s8)))- (export "u16" (func (param "a" u16)))- (export "s16" (func (param "a" s16)))- ))-- (core func $u8 (canon lower (func $i "u8")))- (core func $s8 (canon lower (func $i "s8")))- (core func $u16 (canon lower (func $i "u16")))- (core func $s16 (canon lower (func $i "s16")))-- (core module $m- (import "" "u8" (func $u8 (param i32)))- (import "" "s8" (func $s8 (param i32)))- (import "" "u16" (func $u16 (param i32)))- (import "" "s16" (func $s16 (param i32)))-- (func $start- (call $u8 (i32.const 0))- (call $u8 (i32.const 0xff00))- (call $s8 (i32.const -1))- (call $s8 (i32.const 0xff))- (call $s8 (i32.const 0xffff))-- (call $u16 (i32.const 0))- (call $u16 (i32.const 0xff0000))- (call $s16 (i32.const -1))- (call $s16 (i32.const 0xffff))- (call $s16 (i32.const 0xffffff))- )- (start $start)- )- (core instance (instantiate $m- (with "" (instance- (export "u8" (func $u8))- (export "s8" (func $s8))- (export "u16" (func $u16))- (export "s16" (func $s16))- ))- ))- )- (instance $c1 (instantiate $c1))- (instance $c2 (instantiate $c2 (with "a" (instance $c1))))-)--;; translation of locals between different types-(component- (component $c1- (type $a' (variant (case "a" u8) (case "b" float32)))- (type $b' (variant (case "a" u16) (case "b" s64)))- (type $c' (variant (case "a" u64) (case "b" float64)))- (type $d' (variant (case "a" float32) (case "b" float64)))- (type $e' (variant (case "a" float32) (case "b" s64)))- (export $a "t-a" (type $a'))- (export $b "t-b" (type $b'))- (export $c "t-c" (type $c'))- (export $d "t-d" (type $d'))- (export $e "t-e" (type $e'))-- (type $func_a (func (param "x" bool) (param "a" $a)))- (type $func_b (func (param "x" bool) (param "b" $b)))- (type $func_c (func (param "x" bool) (param "c" $c)))- (type $func_d (func (param "x" bool) (param "d" $d)))- (type $func_e (func (param "x" bool) (param "e" $d)))-- (core module $m- (func (export "a") (param i32 i32 i32)- (i32.eqz (local.get 0))- if- (if (i32.ne (local.get 1) (i32.const 0)) (then (unreachable)))- (if (i32.ne (local.get 2) (i32.const 2)) (then (unreachable)))- else- (if (i32.ne (local.get 1) (i32.const 1)) (then (unreachable)))- (if (f32.ne (f32.reinterpret_i32 (local.get 2)) (f32.const 3)) (then (unreachable)))- end- )- (func (export "b") (param i32 i32 i64)- (i32.eqz (local.get 0))- if- (if (i32.ne (local.get 1) (i32.const 0)) (then (unreachable)))- (if (i64.ne (local.get 2) (i64.const 4)) (then (unreachable)))- else- (if (i32.ne (local.get 1) (i32.const 1)) (then (unreachable)))- (if (i64.ne (local.get 2) (i64.const 5)) (then (unreachable)))- end- )- (func (export "c") (param i32 i32 i64)- (i32.eqz (local.get 0))- if- (if (i32.ne (local.get 1) (i32.const 0)) (then (unreachable)))- (if (i64.ne (local.get 2) (i64.const 6)) (then (unreachable)))- else- (if (i32.ne (local.get 1) (i32.const 1)) (then (unreachable)))- (if (f64.ne (f64.reinterpret_i64 (local.get 2)) (f64.const 7)) (then (unreachable)))- end- )- (func (export "d") (param i32 i32 i64)- (i32.eqz (local.get 0))- if- (if (i32.ne (local.get 1) (i32.const 0)) (then (unreachable)))- (if (f32.ne (f32.reinterpret_i32 (i32.wrap_i64 (local.get 2))) (f32.const 8)) (then (unreachable)))- else- (if (i32.ne (local.get 1) (i32.const 1)) (then (unreachable)))- (if (f64.ne (f64.reinterpret_i64 (local.get 2)) (f64.const 9)) (then (unreachable)))- end- )- (func (export "e") (param i32 i32 i64)- (i32.eqz (local.get 0))- if- (if (i32.ne (local.get 1) (i32.const 0)) (then (unreachable)))- (if (f32.ne (f32.reinterpret_i32 (i32.wrap_i64 (local.get 2))) (f32.const 10)) (then (unreachable)))- else- (if (i32.ne (local.get 1) (i32.const 1)) (then (unreachable)))- (if (i64.ne (local.get 2) (i64.const 11)) (then (unreachable)))- end- )- )- (core instance $m (instantiate $m))- (func (export "a") (type $func_a) (canon lift (core func $m "a")))- (func (export "b") (type $func_b) (canon lift (core func $m "b")))- (func (export "c") (type $func_c) (canon lift (core func $m "c")))- (func (export "d") (type $func_d) (canon lift (core func $m "d")))- (func (export "e") (type $func_e) (canon lift (core func $m "e")))- )- (component $c2- (import "a" (instance $i- (type $a' (variant (case "a" u8) (case "b" float32)))- (type $b' (variant (case "a" u16) (case "b" s64)))- (type $c' (variant (case "a" u64) (case "b" float64)))- (type $d' (variant (case "a" float32) (case "b" float64)))- (type $e' (variant (case "a" float32) (case "b" s64)))- (export "t-a" (type $a (eq $a')))- (export "t-b" (type $b (eq $b')))- (export "t-c" (type $c (eq $c')))- (export "t-d" (type $d (eq $d')))- (export "t-e" (type $e (eq $e')))- (type $func_a (func (param "x" bool) (param "a" $a)))- (type $func_b (func (param "x" bool) (param "b" $b)))- (type $func_c (func (param "x" bool) (param "c" $c)))- (type $func_d (func (param "x" bool) (param "d" $d)))- (type $func_e (func (param "x" bool) (param "e" $d)))-- (export "a" (func (type $func_a)))- (export "b" (func (type $func_b)))- (export "c" (func (type $func_c)))- (export "d" (func (type $func_d)))- (export "e" (func (type $func_e)))- ))-- (core func $a (canon lower (func $i "a")))- (core func $b (canon lower (func $i "b")))- (core func $c (canon lower (func $i "c")))- (core func $d (canon lower (func $i "d")))- (core func $e (canon lower (func $i "e")))-- (core module $m- (import "" "a" (func $a (param i32 i32 i32)))- (import "" "b" (func $b (param i32 i32 i64)))- (import "" "c" (func $c (param i32 i32 i64)))- (import "" "d" (func $d (param i32 i32 i64)))- (import "" "e" (func $e (param i32 i32 i64)))-- (func $start- ;; upper bits should get masked- (call $a (i32.const 0) (i32.const 0) (i32.const 0xff_02))- (call $a (i32.const 1) (i32.const 1) (i32.reinterpret_f32 (f32.const 3)))-- ;; upper bits should get masked- (call $b (i32.const 0) (i32.const 0) (i64.const 0xff_00_04))- (call $b (i32.const 1) (i32.const 1) (i64.const 5))-- (call $c (i32.const 0) (i32.const 0) (i64.const 6))- (call $c (i32.const 1) (i32.const 1) (i64.reinterpret_f64 (f64.const 7)))-- (call $d (i32.const 0) (i32.const 0) (i64.extend_i32_u (i32.reinterpret_f32 (f32.const 8))))- (call $d (i32.const 1) (i32.const 1) (i64.reinterpret_f64 (f64.const 9)))-- (call $e (i32.const 0) (i32.const 0) (i64.extend_i32_u (i32.reinterpret_f32 (f32.const 10))))- (call $e (i32.const 1) (i32.const 1) (i64.const 11))- )- (start $start)- )- (core instance (instantiate $m- (with "" (instance- (export "a" (func $a))- (export "b" (func $b))- (export "c" (func $c))- (export "d" (func $d))- (export "e" (func $e))- ))- ))- )- (instance $c1 (instantiate $c1))- (instance $c2 (instantiate $c2 (with "a" (instance $c1))))-)--;; different size variants-(component- (component $c1- (type $a' (variant- (case "a")- (case "b" float32)- (case "c" (tuple float32 u32))- (case "d" (tuple float32 u64 u8))- ))- (export $a "t-a" (type $a'))-- (core module $m- (func (export "a") (param i32 i32 f32 i64 i32)- (if (i32.eq (local.get 0) (i32.const 0))- (then (block- (if (i32.ne (local.get 1) (i32.const 0)) (then (unreachable)))- (if (f32.ne (local.get 2) (f32.const 0)) (then (unreachable)))- (if (i64.ne (local.get 3) (i64.const 0)) (then (unreachable)))- (if (i32.ne (local.get 4) (i32.const 0)) (then (unreachable)))- ))- )- (if (i32.eq (local.get 0) (i32.const 1))- (then (block- (if (i32.ne (local.get 1) (i32.const 1)) (then (unreachable)))- (if (f32.ne (local.get 2) (f32.const 1)) (then (unreachable)))- (if (i64.ne (local.get 3) (i64.const 0)) (then (unreachable)))- (if (i32.ne (local.get 4) (i32.const 0)) (then (unreachable)))- ))- )- (if (i32.eq (local.get 0) (i32.const 2))- (then (block- (if (i32.ne (local.get 1) (i32.const 2)) (then (unreachable)))- (if (f32.ne (local.get 2) (f32.const 2)) (then (unreachable)))- (if (i64.ne (local.get 3) (i64.const 2)) (then (unreachable)))- (if (i32.ne (local.get 4) (i32.const 0)) (then (unreachable)))- ))- )- (if (i32.eq (local.get 0) (i32.const 3))- (then (block- (if (i32.ne (local.get 1) (i32.const 3)) (then (unreachable)))- (if (f32.ne (local.get 2) (f32.const 3)) (then (unreachable)))- (if (i64.ne (local.get 3) (i64.const 3)) (then (unreachable)))- (if (i32.ne (local.get 4) (i32.const 3)) (then (unreachable)))- ))- )- (if (i32.gt_u (local.get 0) (i32.const 3))- (then (unreachable)))- )- )- (core instance $m (instantiate $m))- (func (export "a") (param "x" u8) (param "a" $a) (canon lift (core func $m "a")))- )- (component $c2- (import "a" (instance $i- (type $a' (variant- (case "a")- (case "b" float32)- (case "c" (tuple float32 u32))- (case "d" (tuple float32 u64 u8))- ))- (export "t-a" (type $a (eq $a')))- (export "a" (func (param "x" u8) (param "a" $a)))- ))-- (core func $a (canon lower (func $i "a")))-- (core module $m- (import "" "a" (func $a (param i32 i32 f32 i64 i32)))-- (func $start- ;; variant a- (call $a- (i32.const 0)- (i32.const 0)- (f32.const 0)- (i64.const 0)- (i32.const 0))- ;; variant b- (call $a- (i32.const 1)- (i32.const 1)- (f32.const 1)- (i64.const 0)- (i32.const 0))- ;; variant c- (call $a- (i32.const 2)- (i32.const 2)- (f32.const 2)- (i64.const 2)- (i32.const 0))- ;; variant d- (call $a- (i32.const 3)- (i32.const 3)- (f32.const 3)- (i64.const 3)- (i32.const 3))- )- (start $start)- )- (core instance (instantiate $m- (with "" (instance- (export "a" (func $a))- ))- ))- )- (instance $c1 (instantiate $c1))- (instance $c2 (instantiate $c2 (with "a" (instance $c1))))-)--;; roundtrip some valid chars-(component- (component $c1- (core module $m- (func (export "a") (param i32) (result i32) local.get 0)- )- (core instance $m (instantiate $m))- (func (export "a") (param "a" char) (result char) (canon lift (core func $m "a")))- )- (component $c2- (import "a" (instance $i- (export "a" (func (param "a" char) (result char)))- ))-- (core func $a (canon lower (func $i "a")))-- (core module $m- (import "" "a" (func $a (param i32) (result i32)))-- (func $start- (call $roundtrip (i32.const 0))- (call $roundtrip (i32.const 0xab))- (call $roundtrip (i32.const 0xd7ff))- (call $roundtrip (i32.const 0xe000))- (call $roundtrip (i32.const 0x10ffff))- )- (func $roundtrip (export "roundtrip") (param i32)- local.get 0- call $a- local.get 0- i32.ne- if unreachable end- )- (start $start)- )- (core instance $m (instantiate $m- (with "" (instance- (export "a" (func $a))- ))- ))-- (func (export "roundtrip") (param "a" char) (canon lift (core func $m "roundtrip")))- )- (instance $c1 (instantiate $c1))- (instance $c2 (instantiate $c2 (with "a" (instance $c1))))-- (export "roundtrip" (func $c2 "roundtrip"))-)--(assert_return (invoke "roundtrip" (char.const "x")))-(assert_return (invoke "roundtrip" (char.const "⛳")))-(assert_return (invoke "roundtrip" (char.const "🍰")))--;; invalid chars-(assert_trap- (component- (component $c1- (core module $m (func (export "a") (param i32)))- (core instance $m (instantiate $m))- (func (export "a") (param "a" char) (canon lift (core func $m "a")))- )- (component $c2- (import "a" (instance $i (export "a" (func (param "a" char)))))- (core func $a (canon lower (func $i "a")))- (core module $m- (import "" "a" (func $a (param i32)))- (func $start (call $a (i32.const 0xd800)))- (start $start)- )- (core instance (instantiate $m (with "" (instance (export "a" (func $a))))))- )- (instance $c1 (instantiate $c1))- (instance $c2 (instantiate $c2 (with "a" (instance $c1))))- )- "unreachable")-(assert_trap- (component- (component $c1- (core module $m (func (export "a") (param i32)))- (core instance $m (instantiate $m))- (func (export "a") (param "a" char) (canon lift (core func $m "a")))- )- (component $c2- (import "a" (instance $i (export "a" (func (param "a" char)))))- (core func $a (canon lower (func $i "a")))- (core module $m- (import "" "a" (func $a (param i32)))- (func $start (call $a (i32.const 0xdfff)))- (start $start)- )- (core instance (instantiate $m (with "" (instance (export "a" (func $a))))))- )- (instance $c1 (instantiate $c1))- (instance $c2 (instantiate $c2 (with "a" (instance $c1))))- )- "unreachable")-(assert_trap- (component- (component $c1- (core module $m (func (export "a") (param i32)))- (core instance $m (instantiate $m))- (func (export "a") (param "a" char) (canon lift (core func $m "a")))- )- (component $c2- (import "a" (instance $i (export "a" (func (param "a" char)))))- (core func $a (canon lower (func $i "a")))- (core module $m- (import "" "a" (func $a (param i32)))- (func $start (call $a (i32.const 0x110000)))- (start $start)- )- (core instance (instantiate $m (with "" (instance (export "a" (func $a))))))- )- (instance $c1 (instantiate $c1))- (instance $c2 (instantiate $c2 (with "a" (instance $c1))))- )- "unreachable")--;; test that flags get their upper bits all masked off-(component- (type $f1' (flags "f1"))- (type $f8' (flags "f1" "f2" "f3" "f4" "f5" "f6" "f7" "f8"))- (type $f9' (flags "f1" "f2" "f3" "f4" "f5" "f6" "f7" "f8" "f9"))- (type $f16' (flags- "f1" "f2" "f3" "f4" "f5" "f6" "f7" "f8"- "g1" "g2" "g3" "g4" "g5" "g6" "g7" "g8"- ))- (type $f17' (flags- "f1" "f2" "f3" "f4" "f5" "f6" "f7" "f8"- "g1" "g2" "g3" "g4" "g5" "g6" "g7" "g8"- "g9"- ))- (type $f32' (flags- "f1" "f2" "f3" "f4" "f5" "f6" "f7" "f8"- "g1" "g2" "g3" "g4" "g5" "g6" "g7" "g8"- "h1" "h2" "h3" "h4" "h5" "h6" "h7" "h8"- "i1" "i2" "i3" "i4" "i5" "i6" "i7" "i8"- ))-- (component $c1- (export $f1 "t-f1" (type $f1'))- (export $f8 "t-f8" (type $f8'))- (export $f9 "t-f9" (type $f9'))- (export $f16 "t-f16" (type $f16'))- (export $f17 "t-f17" (type $f17'))- (export $f32 "t-f32" (type $f32'))- (core module $m- (func (export "f1") (param i32)- (if (i32.ne (local.get 0) (i32.const 0x1)) (then (unreachable)))- )- (func (export "f8") (param i32)- (if (i32.ne (local.get 0) (i32.const 0x11)) (then (unreachable)))- )- (func (export "f9") (param i32)- (if (i32.ne (local.get 0) (i32.const 0x111)) (then (unreachable)))- )- (func (export "f16") (param i32)- (if (i32.ne (local.get 0) (i32.const 0x1111)) (then (unreachable)))- )- (func (export "f17") (param i32)- (if (i32.ne (local.get 0) (i32.const 0x11111)) (then (unreachable)))- )- (func (export "f32") (param i32)- (if (i32.ne (local.get 0) (i32.const 0x11111111)) (then (unreachable)))- )- )- (core instance $m (instantiate $m))- (func (export "f1") (param "a" $f1) (canon lift (core func $m "f1")))- (func (export "f8") (param "a" $f8) (canon lift (core func $m "f8")))- (func (export "f9") (param "a" $f9) (canon lift (core func $m "f9")))- (func (export "f16") (param "a" $f16) (canon lift (core func $m "f16")))- (func (export "f17") (param "a" $f17) (canon lift (core func $m "f17")))- (func (export "f32") (param "a" $f32) (canon lift (core func $m "f32")))- )- (instance $c1 (instantiate $c1))-- (component $c2- (import "a" (instance $i- (export "t-f1" (type $f1 (eq $f1')))- (export "t-f8" (type $f8 (eq $f8')))- (export "t-f9" (type $f9 (eq $f9')))- (export "t-f16" (type $f16 (eq $f16')))- (export "t-f17" (type $f17 (eq $f17')))- (export "t-f32" (type $f32 (eq $f32')))- (export "f1" (func (param "a" $f1)))- (export "f8" (func (param "a" $f8)))- (export "f9" (func (param "a" $f9)))- (export "f16" (func (param "a" $f16)))- (export "f17" (func (param "a" $f17)))- (export "f32" (func (param "a" $f32)))- ))- (core func $f1 (canon lower (func $i "f1")))- (core func $f8 (canon lower (func $i "f8")))- (core func $f9 (canon lower (func $i "f9")))- (core func $f16 (canon lower (func $i "f16")))- (core func $f17 (canon lower (func $i "f17")))- (core func $f32 (canon lower (func $i "f32")))-- (core module $m- (import "" "f1" (func $f1 (param i32)))- (import "" "f8" (func $f8 (param i32)))- (import "" "f9" (func $f9 (param i32)))- (import "" "f16" (func $f16 (param i32)))- (import "" "f17" (func $f17 (param i32)))- (import "" "f32" (func $f32 (param i32)))-- (func $start- (call $f1 (i32.const 0xffffff01))- (call $f8 (i32.const 0xffffff11))- (call $f9 (i32.const 0xffffff11))- (call $f16 (i32.const 0xffff1111))- (call $f17 (i32.const 0xffff1111))- (call $f32 (i32.const 0x11111111))- )-- (start $start)- )- (core instance $m (instantiate $m- (with "" (instance- (export "f1" (func $f1))- (export "f8" (func $f8))- (export "f9" (func $f9))- (export "f16" (func $f16))- (export "f17" (func $f17))- (export "f32" (func $f32))- ))- ))- )- (instance (instantiate $c2 (with "a" (instance $c1))))-)--;; Adapters are used slightly out-of-order here to stress the internals of-;; dependencies between adapters.-(component- (core module $m- (func (export "execute"))- (func (export "realloc") (param i32 i32 i32 i32) (result i32) unreachable)- (memory (export "memory") 1)- )-- (component $root- (core instance $m (instantiate $m))- (func (export "execute")- (canon lift (core func $m "execute"))- )- )- (component $c- (import "backend" (instance $i- (export "execute" (func))- ))- (core module $shim2 (import "" "0" (func)))- (core instance $m (instantiate $m))-- ;; This adapter, when fused with itself on the second instantiation of this- ;; component, will depended on the prior instance `$m` so it which means- ;; that the adapter module containing this must be placed in the right- ;; location.- (core func $execute- (canon lower (func $i "execute") (memory $m "memory") (realloc (func $m "realloc")))- )- (core instance (instantiate $shim2- (with "" (instance- (export "0" (func $execute))- ))- ))- (func (export "execute") (canon lift (core func $m "execute")))- )- (instance $root (instantiate $root))- (instance $c1 (instantiate $c (with "backend" (instance $root))))- (instance $c2 (instantiate $c (with "backend" (instance $c1))))-)diff --git a/tests/misc_testsuite/component-model/strings.wast b/tests/misc_testsuite/component-model/strings.wastdeleted file mode 100644index e53caa3573..0000000000--- a/tests/misc_testsuite/component-model/strings.wast+++ /dev/null@@ -1,110 +0,0 @@-;;! multi_memory = true--;; unaligned utf16 string-(assert_trap- (component- (component $c- (core module $m- (func (export "") (param i32 i32))- (func (export "realloc") (param i32 i32 i32 i32) (result i32) i32.const 0)- (memory (export "memory") 1)- )- (core instance $m (instantiate $m))- (func (export "a") (param "a" string)- (canon lift (core func $m "") (realloc (func $m "realloc")) (memory $m "memory"))- )- )-- (component $c2- (import "a" (func $f (param "a" string)))- (core module $libc- (memory (export "memory") 1)- )- (core instance $libc (instantiate $libc))- (core func $f (canon lower (func $f) string-encoding=utf16 (memory $libc "memory")))- (core module $m- (import "" "" (func $f (param i32 i32)))-- (func $start (call $f (i32.const 1) (i32.const 0)))- (start $start)- )- (core instance (instantiate $m (with "" (instance (export "" (func $f))))))- )-- (instance $c (instantiate $c))- (instance $c2 (instantiate $c2 (with "a" (func $c "a"))))- )- "unreachable")--;; unaligned latin1+utf16 string, even with the latin1 encoding-(assert_trap- (component- (component $c- (core module $m- (func (export "") (param i32 i32))- (func (export "realloc") (param i32 i32 i32 i32) (result i32) i32.const 0)- (memory (export "memory") 1)- )- (core instance $m (instantiate $m))- (func (export "a") (param "a" string)- (canon lift (core func $m "") (realloc (func $m "realloc")) (memory $m "memory"))- )- )-- (component $c2- (import "a" (func $f (param "a" string)))- (core module $libc- (memory (export "memory") 1)- )- (core instance $libc (instantiate $libc))- (core func $f (canon lower (func $f) string-encoding=latin1+utf16 (memory $libc "memory")))- (core module $m- (import "" "" (func $f (param i32 i32)))-- (func $start (call $f (i32.const 1) (i32.const 0)))- (start $start)- )- (core instance (instantiate $m (with "" (instance (export "" (func $f))))))- )-- (instance $c (instantiate $c))- (instance $c2 (instantiate $c2 (with "a" (func $c "a"))))- )- "unreachable")--;; out of bounds utf8->utf8 string-(assert_trap- (component- (component $c- (core module $m- (func (export "") (param i32 i32))- (func (export "realloc") (param i32 i32 i32 i32) (result i32) i32.const 0)- (memory (export "memory") 1)- )- (core instance $m (instantiate $m))- (func (export "a") (param "a" string)- (canon lift (core func $m "") (realloc (func $m "realloc")) (memory $m "memory")- string-encoding=utf8)- )- )-- (component $c2- (import "a" (func $f (param "a" string)))- (core module $libc- (memory (export "memory") 1)- )- (core instance $libc (instantiate $libc))- (core func $f (canon lower (func $f) string-encoding=utf8 (memory $libc "memory")))- (core module $m- (import "" "" (func $f (param i32 i32)))-- (func $start (call $f (i32.const 0x8000_0000) (i32.const 1)))- (start $start)- )- (core instance (instantiate $m (with "" (instance (export "" (func $f))))))- )-- (instance $c (instantiate $c))- (instance $c2 (instantiate $c2 (with "a" (func $c "a"))))- )- "unreachable")