A lightweight WebAssembly runtime that is fast, secure, and standards-compliant
disallow exiting a component instance during a post-return call (#11688)
Joel Dice6751ea797721
diff --git a/crates/cranelift/src/compiler/component.rs b/crates/cranelift/src/compiler/component.rsindex 40f28dacd1..fb6b6eb636 100644--- a/crates/cranelift/src/compiler/component.rs+++ b/crates/cranelift/src/compiler/component.rs@@ -197,7 +197,7 @@ impl<'a> TrampolineCompiler<'a> {},);}- Trampoline::ResourceNew(ty) => {+ Trampoline::ResourceNew { instance, ty } => {// Currently this only supports resources represented by `i32`assert_eq!(self.types[self.signature].unwrap_func().params()[0],@@ -208,11 +208,12 @@ impl<'a> TrampolineCompiler<'a> {TrapSentinel::NegativeOne,WasmArgs::InRegisters,|me, params| {+ params.push(me.index_value(*instance));params.push(me.index_value(*ty));},);}- Trampoline::ResourceRep(ty) => {+ Trampoline::ResourceRep { instance, ty } => {// Currently this only supports resources represented by `i32`assert_eq!(self.types[self.signature].unwrap_func().returns()[0],@@ -223,12 +224,13 @@ impl<'a> TrampolineCompiler<'a> {TrapSentinel::NegativeOne,WasmArgs::InRegisters,|me, params| {+ params.push(me.index_value(*instance));params.push(me.index_value(*ty));},);}- Trampoline::ResourceDrop(ty) => {- self.translate_resource_drop(*ty);+ Trampoline::ResourceDrop { instance, ty } => {+ self.translate_resource_drop(*instance, *ty);}Trampoline::BackpressureSet { instance } => {self.translate_libcall(@@ -262,12 +264,17 @@ impl<'a> TrampolineCompiler<'a> {},);}- Trampoline::TaskReturn { results, options } => {+ Trampoline::TaskReturn {+ instance,+ results,+ options,+ } => {self.translate_libcall(host::task_return,TrapSentinel::Falsy,WasmArgs::ValRawList,|me, params| {+ params.push(me.index_value(*instance));params.push(me.index_value(*results));params.push(me.index_value(*options));},@@ -293,22 +300,24 @@ impl<'a> TrampolineCompiler<'a> {},);}- Trampoline::WaitableSetWait { options } => {+ Trampoline::WaitableSetWait { instance, options } => {self.translate_libcall(host::waitable_set_wait,TrapSentinel::NegativeOne,WasmArgs::InRegisters,|me, params| {+ params.push(me.index_value(*instance));params.push(me.index_value(*options));},);}- Trampoline::WaitableSetPoll { options } => {+ Trampoline::WaitableSetPoll { instance, options } => {self.translate_libcall(host::waitable_set_poll,TrapSentinel::NegativeOne,WasmArgs::InRegisters,|me, params| {+ params.push(me.index_value(*instance));params.push(me.index_value(*options));},);@@ -333,12 +342,16 @@ impl<'a> TrampolineCompiler<'a> {},);}- Trampoline::ThreadYield { cancellable } => {+ Trampoline::ThreadYield {+ instance,+ cancellable,+ } => {self.translate_libcall(host::thread_yield,TrapSentinel::NegativeOne,WasmArgs::InRegisters,|me, params| {+ params.push(me.index_value(*instance));params.push(me.builder.ins()@@ -368,17 +381,22 @@ impl<'a> TrampolineCompiler<'a> {},);}- Trampoline::StreamNew { ty } => {+ Trampoline::StreamNew { instance, ty } => {self.translate_libcall(host::stream_new,TrapSentinel::NegativeOne,WasmArgs::InRegisters,|me, params| {+ params.push(me.index_value(*instance));params.push(me.index_value(*ty));},);}- Trampoline::StreamRead { ty, options } => {+ Trampoline::StreamRead {+ instance,+ ty,+ options,+ } => {if let Some(info) = self.flat_stream_element_info(*ty).cloned() {self.translate_libcall(host::flat_stream_read,@@ -386,6 +404,7 @@ impl<'a> TrampolineCompiler<'a> {WasmArgs::InRegisters,|me, params| {params.extend([+ me.index_value(*instance),me.index_value(*ty),me.index_value(*options),me.builder@@ -403,13 +422,18 @@ impl<'a> TrampolineCompiler<'a> {TrapSentinel::NegativeOne,WasmArgs::InRegisters,|me, params| {+ params.push(me.index_value(*instance));params.push(me.index_value(*ty));params.push(me.index_value(*options));},);}}- Trampoline::StreamWrite { ty, options } => {+ Trampoline::StreamWrite {+ instance,+ ty,+ options,+ } => {if let Some(info) = self.flat_stream_element_info(*ty).cloned() {self.translate_libcall(host::flat_stream_write,@@ -417,6 +441,7 @@ impl<'a> TrampolineCompiler<'a> {WasmArgs::InRegisters,|me, params| {params.extend([+ me.index_value(*instance),me.index_value(*ty),me.index_value(*options),me.builder@@ -434,156 +459,203 @@ impl<'a> TrampolineCompiler<'a> {TrapSentinel::NegativeOne,WasmArgs::InRegisters,|me, params| {+ params.push(me.index_value(*instance));params.push(me.index_value(*ty));params.push(me.index_value(*options));},);}}- Trampoline::StreamCancelRead { ty, async_ } => {+ Trampoline::StreamCancelRead {+ instance,+ ty,+ async_,+ } => {self.translate_libcall(host::stream_cancel_read,TrapSentinel::NegativeOne,WasmArgs::InRegisters,|me, params| {+ params.push(me.index_value(*instance));params.push(me.index_value(*ty));params.push(me.builder.ins().iconst(ir::types::I8, i64::from(*async_)));},);}- Trampoline::StreamCancelWrite { ty, async_ } => {+ Trampoline::StreamCancelWrite {+ instance,+ ty,+ async_,+ } => {self.translate_libcall(host::stream_cancel_write,TrapSentinel::NegativeOne,WasmArgs::InRegisters,|me, params| {+ params.push(me.index_value(*instance));params.push(me.index_value(*ty));params.push(me.builder.ins().iconst(ir::types::I8, i64::from(*async_)));},);}- Trampoline::StreamDropReadable { ty } => {+ Trampoline::StreamDropReadable { instance, ty } => {self.translate_libcall(host::stream_drop_readable,TrapSentinel::Falsy,WasmArgs::InRegisters,|me, params| {+ params.push(me.index_value(*instance));params.push(me.index_value(*ty));},);}- Trampoline::StreamDropWritable { ty } => {+ Trampoline::StreamDropWritable { instance, ty } => {self.translate_libcall(host::stream_drop_writable,TrapSentinel::Falsy,WasmArgs::InRegisters,|me, params| {+ params.push(me.index_value(*instance));params.push(me.index_value(*ty));},);}- Trampoline::FutureNew { ty } => {+ Trampoline::FutureNew { instance, ty } => {self.translate_libcall(host::future_new,TrapSentinel::NegativeOne,WasmArgs::InRegisters,|me, params| {+ params.push(me.index_value(*instance));params.push(me.index_value(*ty));},);}- Trampoline::FutureRead { ty, options } => {+ Trampoline::FutureRead {+ instance,+ ty,+ options,+ } => {self.translate_libcall(host::future_read,TrapSentinel::NegativeOne,WasmArgs::InRegisters,|me, params| {+ params.push(me.index_value(*instance));params.push(me.index_value(*ty));params.push(me.index_value(*options));},);}- Trampoline::FutureWrite { ty, options } => {+ Trampoline::FutureWrite {+ instance,+ ty,+ options,+ } => {self.translate_libcall(host::future_write,TrapSentinel::NegativeOne,WasmArgs::InRegisters,|me, params| {+ params.push(me.index_value(*instance));params.push(me.index_value(*ty));params.push(me.index_value(*options));},);}- Trampoline::FutureCancelRead { ty, async_ } => {+ Trampoline::FutureCancelRead {+ instance,+ ty,+ async_,+ } => {self.translate_libcall(host::future_cancel_read,TrapSentinel::NegativeOne,WasmArgs::InRegisters,|me, params| {+ params.push(me.index_value(*instance));params.push(me.index_value(*ty));params.push(me.builder.ins().iconst(ir::types::I8, i64::from(*async_)));},);}- Trampoline::FutureCancelWrite { ty, async_ } => {+ Trampoline::FutureCancelWrite {+ instance,+ ty,+ async_,+ } => {self.translate_libcall(host::future_cancel_write,TrapSentinel::NegativeOne,WasmArgs::InRegisters,|me, params| {+ params.push(me.index_value(*instance));params.push(me.index_value(*ty));params.push(me.builder.ins().iconst(ir::types::I8, i64::from(*async_)));},);}- Trampoline::FutureDropReadable { ty } => {+ Trampoline::FutureDropReadable { instance, ty } => {self.translate_libcall(host::future_drop_readable,TrapSentinel::Falsy,WasmArgs::InRegisters,|me, params| {+ params.push(me.index_value(*instance));params.push(me.index_value(*ty));},);}- Trampoline::FutureDropWritable { ty } => {+ Trampoline::FutureDropWritable { instance, ty } => {self.translate_libcall(host::future_drop_writable,TrapSentinel::Falsy,WasmArgs::InRegisters,|me, params| {+ params.push(me.index_value(*instance));params.push(me.index_value(*ty));},);}- Trampoline::ErrorContextNew { ty, options } => {+ Trampoline::ErrorContextNew {+ instance,+ ty,+ options,+ } => {self.translate_libcall(host::error_context_new,TrapSentinel::NegativeOne,WasmArgs::InRegisters,|me, params| {+ params.push(me.index_value(*instance));params.push(me.index_value(*ty));params.push(me.index_value(*options));},);}- Trampoline::ErrorContextDebugMessage { ty, options } => {+ Trampoline::ErrorContextDebugMessage {+ instance,+ ty,+ options,+ } => {self.translate_libcall(host::error_context_debug_message,TrapSentinel::Falsy,WasmArgs::InRegisters,|me, params| {+ params.push(me.index_value(*instance));params.push(me.index_value(*ty));params.push(me.index_value(*options));},);}- Trampoline::ErrorContextDrop { ty } => {+ Trampoline::ErrorContextDrop { instance, ty } => {self.translate_libcall(host::error_context_drop,TrapSentinel::Falsy,WasmArgs::InRegisters,|me, params| {+ params.push(me.index_value(*instance));params.push(me.index_value(*ty));},);@@ -699,23 +771,25 @@ impl<'a> TrampolineCompiler<'a> {|_, _| {},);}- Trampoline::ContextGet(i) => {+ Trampoline::ContextGet { instance, slot } => {self.translate_libcall(host::context_get,TrapSentinel::NegativeOne,WasmArgs::InRegisters,|me, params| {- params.push(me.builder.ins().iconst(ir::types::I32, i64::from(*i)));+ params.push(me.index_value(*instance));+ params.push(me.builder.ins().iconst(ir::types::I32, i64::from(*slot)));},);}- Trampoline::ContextSet(i) => {+ Trampoline::ContextSet { instance, slot } => {self.translate_libcall(host::context_set,TrapSentinel::Falsy,WasmArgs::InRegisters,|me, params| {- params.push(me.builder.ins().iconst(ir::types::I32, i64::from(*i)));+ params.push(me.index_value(*instance));+ params.push(me.builder.ins().iconst(ir::types::I32, i64::from(*slot)));},);}@@ -952,7 +1026,11 @@ impl<'a> TrampolineCompiler<'a> {.iconst(ir::types::I32, i64::try_from(index.index()).unwrap())}- fn translate_resource_drop(&mut self, resource: TypeResourceTableIndex) {+ fn translate_resource_drop(+ &mut self,+ instance: RuntimeComponentInstanceIndex,+ resource: TypeResourceTableIndex,+ ) {let args = self.abi_load_params();let vmctx = args[0];let caller_vmctx = args[1];@@ -961,10 +1039,16 @@ impl<'a> TrampolineCompiler<'a> {// The arguments this shim passes along to the libcall are://// * the vmctx+ // * the calling component instance index// * a constant value for this `ResourceDrop` intrinsic// * the wasm handle index to droplet mut host_args = Vec::new();host_args.push(vmctx);+ host_args.push(+ self.builder+ .ins()+ .iconst(ir::types::I32, i64::from(instance.as_u32())),+ );host_args.push(self.builder.ins()diff --git a/crates/environ/src/component.rs b/crates/environ/src/component.rsindex 4519c3141f..3c7087728a 100644--- a/crates/environ/src/component.rs+++ b/crates/environ/src/component.rs@@ -83,14 +83,14 @@ pub use self::types_builder::*;macro_rules! foreach_builtin_component_function {($mac:ident) => {$mac! {- resource_new32(vmctx: vmctx, resource: u32, rep: u32) -> u64;- resource_rep32(vmctx: vmctx, resource: u32, idx: u32) -> u64;+ resource_new32(vmctx: vmctx, caller_instance: u32, resource: u32, rep: u32) -> u64;+ resource_rep32(vmctx: vmctx, caller_instance: u32, resource: u32, idx: u32) -> u64;// Returns an `Option<u32>` where `None` is "no destructor needed"// and `Some(val)` is "run the destructor on this rep". The option// is encoded as a 64-bit integer where the low bit is Some/None// and bits 1-33 are the payload.- resource_drop(vmctx: vmctx, resource: u32, idx: u32) -> u64;+ resource_drop(vmctx: vmctx, caller_instance: u32, resource: u32, idx: u32) -> u64;resource_transfer_own(vmctx: vmctx, src_idx: u32, src_table: u32, dst_table: u32) -> u64;resource_transfer_borrow(vmctx: vmctx, src_idx: u32, src_table: u32, dst_table: u32) -> u64;@@ -102,21 +102,21 @@ macro_rules! foreach_builtin_component_function {#[cfg(feature = "component-model-async")]backpressure_modify(vmctx: vmctx, caller_instance: u32, increment: u8) -> bool;#[cfg(feature = "component-model-async")]- task_return(vmctx: vmctx, ty: u32, options: u32, storage: ptr_u8, storage_len: size) -> bool;+ task_return(vmctx: vmctx, caller_instance: u32, ty: u32, options: u32, storage: ptr_u8, storage_len: size) -> bool;#[cfg(feature = "component-model-async")]task_cancel(vmctx: vmctx, caller_instance: u32) -> bool;#[cfg(feature = "component-model-async")]waitable_set_new(vmctx: vmctx, caller_instance: u32) -> u64;#[cfg(feature = "component-model-async")]- waitable_set_wait(vmctx: vmctx, options: u32, set: u32, payload: u32) -> u64;+ waitable_set_wait(vmctx: vmctx, caller_instance: u32, options: u32, set: u32, payload: u32) -> u64;#[cfg(feature = "component-model-async")]- waitable_set_poll(vmctx: vmctx, options: u32, set: u32, payload: u32) -> u64;+ waitable_set_poll(vmctx: vmctx, caller_instance: u32, options: u32, set: u32, payload: u32) -> u64;#[cfg(feature = "component-model-async")]waitable_set_drop(vmctx: vmctx, caller_instance: u32, set: u32) -> bool;#[cfg(feature = "component-model-async")]waitable_join(vmctx: vmctx, caller_instance: u32, set: u32, waitable: u32) -> bool;#[cfg(feature = "component-model-async")]- thread_yield(vmctx: vmctx, cancellable: u8) -> u32;+ thread_yield(vmctx: vmctx, caller_instance: u32, cancellable: u8) -> u32;#[cfg(feature = "component-model-async")]subtask_drop(vmctx: vmctx, caller_instance: u32, task_id: u32) -> bool;#[cfg(feature = "component-model-async")]@@ -140,43 +140,43 @@ macro_rules! foreach_builtin_component_function {#[cfg(feature = "component-model-async")]async_start(vmctx: vmctx, callback: ptr_u8, post_return: ptr_u8, callee: ptr_u8, param_count: u32, result_count: u32, flags: u32) -> u64;#[cfg(feature = "component-model-async")]- future_new(vmctx: vmctx, ty: u32) -> u64;+ future_new(vmctx: vmctx, caller_instance: u32, ty: u32) -> u64;#[cfg(feature = "component-model-async")]- future_write(vmctx: vmctx, ty: u32, options: u32, future: u32, address: u32) -> u64;+ future_write(vmctx: vmctx, caller_instance: u32, ty: u32, options: u32, future: u32, address: u32) -> u64;#[cfg(feature = "component-model-async")]- future_read(vmctx: vmctx, ty: u32, options: u32, future: u32, address: u32) -> u64;+ future_read(vmctx: vmctx, caller_instance: u32, ty: u32, options: u32, future: u32, address: u32) -> u64;#[cfg(feature = "component-model-async")]- future_cancel_write(vmctx: vmctx, ty: u32, async_: u8, writer: u32) -> u64;+ future_cancel_write(vmctx: vmctx, caller_instance: u32, ty: u32, async_: u8, writer: u32) -> u64;#[cfg(feature = "component-model-async")]- future_cancel_read(vmctx: vmctx, ty: u32, async_: u8, reader: u32) -> u64;+ future_cancel_read(vmctx: vmctx, caller_instance: u32, ty: u32, async_: u8, reader: u32) -> u64;#[cfg(feature = "component-model-async")]- future_drop_writable(vmctx: vmctx, ty: u32, writer: u32) -> bool;+ future_drop_writable(vmctx: vmctx, caller_instance: u32, ty: u32, writer: u32) -> bool;#[cfg(feature = "component-model-async")]- future_drop_readable(vmctx: vmctx, ty: u32, reader: u32) -> bool;+ future_drop_readable(vmctx: vmctx, caller_instance: u32, ty: u32, reader: u32) -> bool;#[cfg(feature = "component-model-async")]- stream_new(vmctx: vmctx, ty: u32) -> u64;+ stream_new(vmctx: vmctx, caller_instance: u32, ty: u32) -> u64;#[cfg(feature = "component-model-async")]- stream_write(vmctx: vmctx, ty: u32, options: u32, stream: u32, address: u32, count: u32) -> u64;+ stream_write(vmctx: vmctx, caller_instance: u32, ty: u32, options: u32, stream: u32, address: u32, count: u32) -> u64;#[cfg(feature = "component-model-async")]- stream_read(vmctx: vmctx, ty: u32, options: u32, stream: u32, address: u32, count: u32) -> u64;+ stream_read(vmctx: vmctx, caller_instance: u32, ty: u32, options: u32, stream: u32, address: u32, count: u32) -> u64;#[cfg(feature = "component-model-async")]- stream_cancel_write(vmctx: vmctx, ty: u32, async_: u8, writer: u32) -> u64;+ stream_cancel_write(vmctx: vmctx, caller_instance: u32, ty: u32, async_: u8, writer: u32) -> u64;#[cfg(feature = "component-model-async")]- stream_cancel_read(vmctx: vmctx, ty: u32, async_: u8, reader: u32) -> u64;+ stream_cancel_read(vmctx: vmctx, caller_instance: u32, ty: u32, async_: u8, reader: u32) -> u64;#[cfg(feature = "component-model-async")]- stream_drop_writable(vmctx: vmctx, ty: u32, writer: u32) -> bool;+ stream_drop_writable(vmctx: vmctx, caller_instance: u32, ty: u32, writer: u32) -> bool;#[cfg(feature = "component-model-async")]- stream_drop_readable(vmctx: vmctx, ty: u32, reader: u32) -> bool;+ stream_drop_readable(vmctx: vmctx, caller_instance: u32, ty: u32, reader: u32) -> bool;#[cfg(feature = "component-model-async")]- flat_stream_write(vmctx: vmctx, ty: u32, options:u32, payload_size: u32, payload_align: u32, stream: u32, address: u32, count: u32) -> u64;+ flat_stream_write(vmctx: vmctx, caller_instance: u32, ty: u32, options:u32, payload_size: u32, payload_align: u32, stream: u32, address: u32, count: u32) -> u64;#[cfg(feature = "component-model-async")]- flat_stream_read(vmctx: vmctx, ty: u32, options: u32, payload_size: u32, payload_align: u32, stream: u32, address: u32, count: u32) -> u64;+ flat_stream_read(vmctx: vmctx, caller_instance: u32, ty: u32, options: u32, payload_size: u32, payload_align: u32, stream: u32, address: u32, count: u32) -> u64;#[cfg(feature = "component-model-async")]- error_context_new(vmctx: vmctx, ty: u32, options: u32, debug_msg_address: u32, debug_msg_len: u32) -> u64;+ error_context_new(vmctx: vmctx, caller_instance: u32, ty: u32, options: u32, debug_msg_address: u32, debug_msg_len: u32) -> u64;#[cfg(feature = "component-model-async")]- error_context_debug_message(vmctx: vmctx, ty: u32, options: u32, err_ctx_handle: u32, debug_msg_address: u32) -> bool;+ error_context_debug_message(vmctx: vmctx, caller_instance: u32, ty: u32, options: u32, err_ctx_handle: u32, debug_msg_address: u32) -> bool;#[cfg(feature = "component-model-async")]- error_context_drop(vmctx: vmctx, ty: u32, err_ctx_handle: u32) -> bool;+ error_context_drop(vmctx: vmctx, caller_instance: u32, ty: u32, err_ctx_handle: u32) -> bool;#[cfg(feature = "component-model-async")]future_transfer(vmctx: vmctx, src_idx: u32, src_table: u32, dst_table: u32) -> u64;#[cfg(feature = "component-model-async")]@@ -184,9 +184,9 @@ macro_rules! foreach_builtin_component_function {#[cfg(feature = "component-model-async")]error_context_transfer(vmctx: vmctx, src_idx: u32, src_table: u32, dst_table: u32) -> u64;#[cfg(feature = "component-model-async")]- context_get(vmctx: vmctx, slot: u32) -> u64;+ context_get(vmctx: vmctx, caller_instance: u32, slot: u32) -> u64;#[cfg(feature = "component-model-async")]- context_set(vmctx: vmctx, slot: u32, val: u32) -> bool;+ context_set(vmctx: vmctx, caller_instance: u32, slot: u32, val: u32) -> bool;trap(vmctx: vmctx, code: u8) -> bool;diff --git a/crates/environ/src/component/dfg.rs b/crates/environ/src/component/dfg.rsindex b4149d5fd5..a85a80cea0 100644--- a/crates/environ/src/component/dfg.rs+++ b/crates/environ/src/component/dfg.rs@@ -316,9 +316,18 @@ pub enum Trampoline {to64: bool,},AlwaysTrap,- ResourceNew(TypeResourceTableIndex),- ResourceRep(TypeResourceTableIndex),- ResourceDrop(TypeResourceTableIndex),+ ResourceNew {+ instance: RuntimeComponentInstanceIndex,+ ty: TypeResourceTableIndex,+ },+ ResourceRep {+ instance: RuntimeComponentInstanceIndex,+ ty: TypeResourceTableIndex,+ },+ ResourceDrop {+ instance: RuntimeComponentInstanceIndex,+ ty: TypeResourceTableIndex,+ },BackpressureSet {instance: RuntimeComponentInstanceIndex,},@@ -329,6 +338,7 @@ pub enum Trampoline {instance: RuntimeComponentInstanceIndex,},TaskReturn {+ instance: RuntimeComponentInstanceIndex,results: TypeTupleIndex,options: OptionsId,},@@ -339,9 +349,11 @@ pub enum Trampoline {instance: RuntimeComponentInstanceIndex,},WaitableSetWait {+ instance: RuntimeComponentInstanceIndex,options: OptionsId,},WaitableSetPoll {+ instance: RuntimeComponentInstanceIndex,options: OptionsId,},WaitableSetDrop {@@ -351,6 +363,7 @@ pub enum Trampoline {instance: RuntimeComponentInstanceIndex,},ThreadYield {+ instance: RuntimeComponentInstanceIndex,cancellable: bool,},SubtaskDrop {@@ -361,64 +374,81 @@ pub enum Trampoline {async_: bool,},StreamNew {+ instance: RuntimeComponentInstanceIndex,ty: TypeStreamTableIndex,},StreamRead {+ instance: RuntimeComponentInstanceIndex,ty: TypeStreamTableIndex,options: OptionsId,},StreamWrite {+ instance: RuntimeComponentInstanceIndex,ty: TypeStreamTableIndex,options: OptionsId,},StreamCancelRead {+ instance: RuntimeComponentInstanceIndex,ty: TypeStreamTableIndex,async_: bool,},StreamCancelWrite {+ instance: RuntimeComponentInstanceIndex,ty: TypeStreamTableIndex,async_: bool,},StreamDropReadable {+ instance: RuntimeComponentInstanceIndex,ty: TypeStreamTableIndex,},StreamDropWritable {+ instance: RuntimeComponentInstanceIndex,ty: TypeStreamTableIndex,},FutureNew {+ instance: RuntimeComponentInstanceIndex,ty: TypeFutureTableIndex,},FutureRead {+ instance: RuntimeComponentInstanceIndex,ty: TypeFutureTableIndex,options: OptionsId,},FutureWrite {+ instance: RuntimeComponentInstanceIndex,ty: TypeFutureTableIndex,options: OptionsId,},FutureCancelRead {+ instance: RuntimeComponentInstanceIndex,ty: TypeFutureTableIndex,async_: bool,},FutureCancelWrite {+ instance: RuntimeComponentInstanceIndex,ty: TypeFutureTableIndex,async_: bool,},FutureDropReadable {+ instance: RuntimeComponentInstanceIndex,ty: TypeFutureTableIndex,},FutureDropWritable {+ instance: RuntimeComponentInstanceIndex,ty: TypeFutureTableIndex,},ErrorContextNew {+ instance: RuntimeComponentInstanceIndex,ty: TypeComponentLocalErrorContextTableIndex,options: OptionsId,},ErrorContextDebugMessage {+ instance: RuntimeComponentInstanceIndex,ty: TypeComponentLocalErrorContextTableIndex,options: OptionsId,},ErrorContextDrop {+ instance: RuntimeComponentInstanceIndex,ty: TypeComponentLocalErrorContextTableIndex,},ResourceTransferOwn,@@ -438,8 +468,14 @@ pub enum Trampoline {FutureTransfer,StreamTransfer,ErrorContextTransfer,- ContextGet(u32),- ContextSet(u32),+ ContextGet {+ instance: RuntimeComponentInstanceIndex,+ slot: u32,+ },+ ContextSet {+ instance: RuntimeComponentInstanceIndex,+ slot: u32,+ },}#[derive(Copy, Clone, Hash, Eq, PartialEq)]@@ -860,9 +896,18 @@ impl LinearizeDfg<'_> {to64: *to64,},Trampoline::AlwaysTrap => info::Trampoline::AlwaysTrap,- Trampoline::ResourceNew(ty) => info::Trampoline::ResourceNew(*ty),- Trampoline::ResourceDrop(ty) => info::Trampoline::ResourceDrop(*ty),- Trampoline::ResourceRep(ty) => info::Trampoline::ResourceRep(*ty),+ Trampoline::ResourceNew { instance, ty } => info::Trampoline::ResourceNew {+ instance: *instance,+ ty: *ty,+ },+ Trampoline::ResourceDrop { instance, ty } => info::Trampoline::ResourceDrop {+ instance: *instance,+ ty: *ty,+ },+ Trampoline::ResourceRep { instance, ty } => info::Trampoline::ResourceRep {+ instance: *instance,+ ty: *ty,+ },Trampoline::BackpressureSet { instance } => info::Trampoline::BackpressureSet {instance: *instance,},@@ -872,7 +917,12 @@ impl LinearizeDfg<'_> {Trampoline::BackpressureDec { instance } => info::Trampoline::BackpressureDec {instance: *instance,},- Trampoline::TaskReturn { results, options } => info::Trampoline::TaskReturn {+ Trampoline::TaskReturn {+ instance,+ results,+ options,+ } => info::Trampoline::TaskReturn {+ instance: *instance,results: *results,options: self.options(*options),},@@ -882,19 +932,29 @@ impl LinearizeDfg<'_> {Trampoline::WaitableSetNew { instance } => info::Trampoline::WaitableSetNew {instance: *instance,},- Trampoline::WaitableSetWait { options } => info::Trampoline::WaitableSetWait {- options: self.options(*options),- },- Trampoline::WaitableSetPoll { options } => info::Trampoline::WaitableSetPoll {- options: self.options(*options),- },+ Trampoline::WaitableSetWait { instance, options } => {+ info::Trampoline::WaitableSetWait {+ instance: *instance,+ options: self.options(*options),+ }+ }+ Trampoline::WaitableSetPoll { instance, options } => {+ info::Trampoline::WaitableSetPoll {+ instance: *instance,+ options: self.options(*options),+ }+ }Trampoline::WaitableSetDrop { instance } => info::Trampoline::WaitableSetDrop {instance: *instance,},Trampoline::WaitableJoin { instance } => info::Trampoline::WaitableJoin {instance: *instance,},- Trampoline::ThreadYield { cancellable } => info::Trampoline::ThreadYield {+ Trampoline::ThreadYield {+ instance,+ cancellable,+ } => info::Trampoline::ThreadYield {+ instance: *instance,cancellable: *cancellable,},Trampoline::SubtaskDrop { instance } => info::Trampoline::SubtaskDrop {@@ -904,63 +964,132 @@ impl LinearizeDfg<'_> {instance: *instance,async_: *async_,},- Trampoline::StreamNew { ty } => info::Trampoline::StreamNew { ty: *ty },- Trampoline::StreamRead { ty, options } => info::Trampoline::StreamRead {+ Trampoline::StreamNew { instance, ty } => info::Trampoline::StreamNew {+ instance: *instance,+ ty: *ty,+ },+ Trampoline::StreamRead {+ instance,+ ty,+ options,+ } => info::Trampoline::StreamRead {+ instance: *instance,ty: *ty,options: self.options(*options),},- Trampoline::StreamWrite { ty, options } => info::Trampoline::StreamWrite {+ Trampoline::StreamWrite {+ instance,+ ty,+ options,+ } => info::Trampoline::StreamWrite {+ instance: *instance,ty: *ty,options: self.options(*options),},- Trampoline::StreamCancelRead { ty, async_ } => info::Trampoline::StreamCancelRead {+ Trampoline::StreamCancelRead {+ instance,+ ty,+ async_,+ } => info::Trampoline::StreamCancelRead {+ instance: *instance,ty: *ty,async_: *async_,},- Trampoline::StreamCancelWrite { ty, async_ } => info::Trampoline::StreamCancelWrite {+ Trampoline::StreamCancelWrite {+ instance,+ ty,+ async_,+ } => info::Trampoline::StreamCancelWrite {+ instance: *instance,ty: *ty,async_: *async_,},- Trampoline::StreamDropReadable { ty } => {- info::Trampoline::StreamDropReadable { ty: *ty }+ Trampoline::StreamDropReadable { instance, ty } => {+ info::Trampoline::StreamDropReadable {+ instance: *instance,+ ty: *ty,+ }}- Trampoline::StreamDropWritable { ty } => {- info::Trampoline::StreamDropWritable { ty: *ty }+ Trampoline::StreamDropWritable { instance, ty } => {+ info::Trampoline::StreamDropWritable {+ instance: *instance,+ ty: *ty,+ }}- Trampoline::FutureNew { ty } => info::Trampoline::FutureNew { ty: *ty },- Trampoline::FutureRead { ty, options } => info::Trampoline::FutureRead {+ Trampoline::FutureNew { instance, ty } => info::Trampoline::FutureNew {+ instance: *instance,+ ty: *ty,+ },+ Trampoline::FutureRead {+ instance,+ ty,+ options,+ } => info::Trampoline::FutureRead {+ instance: *instance,ty: *ty,options: self.options(*options),},- Trampoline::FutureWrite { ty, options } => info::Trampoline::FutureWrite {+ Trampoline::FutureWrite {+ instance,+ ty,+ options,+ } => info::Trampoline::FutureWrite {+ instance: *instance,ty: *ty,options: self.options(*options),},- Trampoline::FutureCancelRead { ty, async_ } => info::Trampoline::FutureCancelRead {+ Trampoline::FutureCancelRead {+ instance,+ ty,+ async_,+ } => info::Trampoline::FutureCancelRead {+ instance: *instance,ty: *ty,async_: *async_,},- Trampoline::FutureCancelWrite { ty, async_ } => info::Trampoline::FutureCancelWrite {+ Trampoline::FutureCancelWrite {+ instance,+ ty,+ async_,+ } => info::Trampoline::FutureCancelWrite {+ instance: *instance,ty: *ty,async_: *async_,},- Trampoline::FutureDropReadable { ty } => {- info::Trampoline::FutureDropReadable { ty: *ty }+ Trampoline::FutureDropReadable { instance, ty } => {+ info::Trampoline::FutureDropReadable {+ instance: *instance,+ ty: *ty,+ }}- Trampoline::FutureDropWritable { ty } => {- info::Trampoline::FutureDropWritable { ty: *ty }+ Trampoline::FutureDropWritable { instance, ty } => {+ info::Trampoline::FutureDropWritable {+ instance: *instance,+ ty: *ty,+ }}- Trampoline::ErrorContextNew { ty, options } => info::Trampoline::ErrorContextNew {+ Trampoline::ErrorContextNew {+ instance,+ ty,+ options,+ } => info::Trampoline::ErrorContextNew {+ instance: *instance,ty: *ty,options: self.options(*options),},- Trampoline::ErrorContextDebugMessage { ty, options } => {- info::Trampoline::ErrorContextDebugMessage {- ty: *ty,- options: self.options(*options),- }- }- Trampoline::ErrorContextDrop { ty } => info::Trampoline::ErrorContextDrop { ty: *ty },+ Trampoline::ErrorContextDebugMessage {+ instance,+ ty,+ options,+ } => info::Trampoline::ErrorContextDebugMessage {+ instance: *instance,+ ty: *ty,+ options: self.options(*options),+ },+ Trampoline::ErrorContextDrop { instance, ty } => info::Trampoline::ErrorContextDrop {+ instance: *instance,+ ty: *ty,+ },Trampoline::ResourceTransferOwn => info::Trampoline::ResourceTransferOwn,Trampoline::ResourceTransferBorrow => info::Trampoline::ResourceTransferBorrow,Trampoline::ResourceEnterCall => info::Trampoline::ResourceEnterCall,@@ -981,8 +1110,14 @@ impl LinearizeDfg<'_> {Trampoline::FutureTransfer => info::Trampoline::FutureTransfer,Trampoline::StreamTransfer => info::Trampoline::StreamTransfer,Trampoline::ErrorContextTransfer => info::Trampoline::ErrorContextTransfer,- Trampoline::ContextGet(i) => info::Trampoline::ContextGet(*i),- Trampoline::ContextSet(i) => info::Trampoline::ContextSet(*i),+ Trampoline::ContextGet { instance, slot } => info::Trampoline::ContextGet {+ instance: *instance,+ slot: *slot,+ },+ Trampoline::ContextSet { instance, slot } => info::Trampoline::ContextSet {+ instance: *instance,+ slot: *slot,+ },};let i1 = self.trampolines.push(*signature);let i2 = self.trampoline_defs.push(trampoline);diff --git a/crates/environ/src/component/info.rs b/crates/environ/src/component/info.rsindex 52d369d14f..d825c9a51e 100644--- a/crates/environ/src/component/info.rs+++ b/crates/environ/src/component/info.rs@@ -719,13 +719,28 @@ pub enum Trampoline {/// A `resource.new` intrinsic which will inject a new resource into the/// table specified.- ResourceNew(TypeResourceTableIndex),+ ResourceNew {+ /// The specific component instance which is calling the intrinsic.+ instance: RuntimeComponentInstanceIndex,+ /// The type of the resource.+ ty: TypeResourceTableIndex,+ },/// Same as `ResourceNew`, but for the `resource.rep` intrinsic.- ResourceRep(TypeResourceTableIndex),+ ResourceRep {+ /// The specific component instance which is calling the intrinsic.+ instance: RuntimeComponentInstanceIndex,+ /// The type of the resource.+ ty: TypeResourceTableIndex,+ },/// Same as `ResourceNew`, but for the `resource.drop` intrinsic.- ResourceDrop(TypeResourceTableIndex),+ ResourceDrop {+ /// The specific component instance which is calling the intrinsic.+ instance: RuntimeComponentInstanceIndex,+ /// The type of the resource.+ ty: TypeResourceTableIndex,+ },/// A `backpressure.set` intrinsic, which tells the host to enable or/// disable backpressure for the caller's instance.@@ -750,9 +765,10 @@ pub enum Trampoline {/// lifted export function. This allows the callee to continue executing/// after returning a result.TaskReturn {+ /// The specific component instance which is calling the intrinsic.+ instance: RuntimeComponentInstanceIndex,/// Tuple representing the result types this intrinsic accepts.results: TypeTupleIndex,-/// The canonical ABI options specified for this intrinsic.options: OptionsIndex,},@@ -775,6 +791,8 @@ pub enum Trampoline {/// outstanding async task/stream/future to make progress, returning the/// first such event.WaitableSetWait {+ /// The specific component instance which is calling the intrinsic.+ instance: RuntimeComponentInstanceIndex,/// Configuration options for this intrinsic call.options: OptionsIndex,},@@ -783,6 +801,8 @@ pub enum Trampoline {/// async task/stream/future has made progress. Unlike `task.wait`, this/// does not block and may return nothing if no such event has occurred.WaitableSetPoll {+ /// The specific component instance which is calling the intrinsic.+ instance: RuntimeComponentInstanceIndex,/// Configuration options for this intrinsic call.options: OptionsIndex,},@@ -802,7 +822,10 @@ pub enum Trampoline {/// A `thread.yield` intrinsic, which yields control to the host so that other/// tasks are able to make progress, if any.ThreadYield {- /// If `true`, indicates the caller instance maybe reentered.+ /// The specific component instance which is calling the intrinsic.+ instance: RuntimeComponentInstanceIndex,+ /// If `true`, indicates the caller instance maybe receive notification+ /// of task cancellation.cancellable: bool,},@@ -824,15 +847,18 @@ pub enum Trampoline {/// A `stream.new` intrinsic to create a new `stream` handle of the/// specified type.StreamNew {+ /// The specific component instance which is calling the intrinsic.+ instance: RuntimeComponentInstanceIndex,/// The table index for the specific `stream` type and caller instance.ty: TypeStreamTableIndex,},/// A `stream.read` intrinsic to read from a `stream` of the specified type.StreamRead {+ /// The specific component instance which is calling the intrinsic.+ instance: RuntimeComponentInstanceIndex,/// The table index for the specific `stream` type and caller instance.ty: TypeStreamTableIndex,-/// Any options (e.g. string encoding) to use when storing values to/// memory.options: OptionsIndex,@@ -840,9 +866,10 @@ pub enum Trampoline {/// A `stream.write` intrinsic to write to a `stream` of the specified type.StreamWrite {+ /// The specific component instance which is calling the intrinsic.+ instance: RuntimeComponentInstanceIndex,/// The table index for the specific `stream` type and caller instance.ty: TypeStreamTableIndex,-/// Any options (e.g. string encoding) to use when storing values to/// memory.options: OptionsIndex,@@ -851,6 +878,8 @@ pub enum Trampoline {/// A `stream.cancel-read` intrinsic to cancel an in-progress read from a/// `stream` of the specified type.StreamCancelRead {+ /// The specific component instance which is calling the intrinsic.+ instance: RuntimeComponentInstanceIndex,/// The table index for the specific `stream` type and caller instance.ty: TypeStreamTableIndex,/// If `false`, block until cancellation completes rather than return@@ -861,6 +890,8 @@ pub enum Trampoline {/// A `stream.cancel-write` intrinsic to cancel an in-progress write from a/// `stream` of the specified type.StreamCancelWrite {+ /// The specific component instance which is calling the intrinsic.+ instance: RuntimeComponentInstanceIndex,/// The table index for the specific `stream` type and caller instance.ty: TypeStreamTableIndex,/// If `false`, block until cancellation completes rather than return@@ -871,6 +902,8 @@ pub enum Trampoline {/// A `stream.drop-readable` intrinsic to drop the readable end of a/// `stream` of the specified type.StreamDropReadable {+ /// The specific component instance which is calling the intrinsic.+ instance: RuntimeComponentInstanceIndex,/// The table index for the specific `stream` type and caller instance.ty: TypeStreamTableIndex,},@@ -878,6 +911,8 @@ pub enum Trampoline {/// A `stream.drop-writable` intrinsic to drop the writable end of a/// `stream` of the specified type.StreamDropWritable {+ /// The specific component instance which is calling the intrinsic.+ instance: RuntimeComponentInstanceIndex,/// The table index for the specific `stream` type and caller instance.ty: TypeStreamTableIndex,},@@ -885,15 +920,18 @@ pub enum Trampoline {/// A `future.new` intrinsic to create a new `future` handle of the/// specified type.FutureNew {+ /// The specific component instance which is calling the intrinsic.+ instance: RuntimeComponentInstanceIndex,/// The table index for the specific `future` type and caller instance.ty: TypeFutureTableIndex,},/// A `future.read` intrinsic to read from a `future` of the specified type.FutureRead {+ /// The specific component instance which is calling the intrinsic.+ instance: RuntimeComponentInstanceIndex,/// The table index for the specific `future` type and caller instance.ty: TypeFutureTableIndex,-/// Any options (e.g. string encoding) to use when storing values to/// memory.options: OptionsIndex,@@ -901,9 +939,10 @@ pub enum Trampoline {/// A `future.write` intrinsic to write to a `future` of the specified type.FutureWrite {+ /// The specific component instance which is calling the intrinsic.+ instance: RuntimeComponentInstanceIndex,/// The table index for the specific `future` type and caller instance.ty: TypeFutureTableIndex,-/// Any options (e.g. string encoding) to use when storing values to/// memory.options: OptionsIndex,@@ -912,6 +951,8 @@ pub enum Trampoline {/// A `future.cancel-read` intrinsic to cancel an in-progress read from a/// `future` of the specified type.FutureCancelRead {+ /// The specific component instance which is calling the intrinsic.+ instance: RuntimeComponentInstanceIndex,/// The table index for the specific `future` type and caller instance.ty: TypeFutureTableIndex,/// If `false`, block until cancellation completes rather than return@@ -922,6 +963,8 @@ pub enum Trampoline {/// A `future.cancel-write` intrinsic to cancel an in-progress write from a/// `future` of the specified type.FutureCancelWrite {+ /// The specific component instance which is calling the intrinsic.+ instance: RuntimeComponentInstanceIndex,/// The table index for the specific `future` type and caller instance.ty: TypeFutureTableIndex,/// If `false`, block until cancellation completes rather than return@@ -932,6 +975,8 @@ pub enum Trampoline {/// A `future.drop-readable` intrinsic to drop the readable end of a/// `future` of the specified type.FutureDropReadable {+ /// The specific component instance which is calling the intrinsic.+ instance: RuntimeComponentInstanceIndex,/// The table index for the specific `future` type and caller instance.ty: TypeFutureTableIndex,},@@ -939,6 +984,8 @@ pub enum Trampoline {/// A `future.drop-writable` intrinsic to drop the writable end of a/// `future` of the specified type.FutureDropWritable {+ /// The specific component instance which is calling the intrinsic.+ instance: RuntimeComponentInstanceIndex,/// The table index for the specific `future` type and caller instance.ty: TypeFutureTableIndex,},@@ -946,6 +993,8 @@ pub enum Trampoline {/// A `error-context.new` intrinsic to create a new `error-context` with a/// specified debug message.ErrorContextNew {+ /// The specific component instance which is calling the intrinsic.+ instance: RuntimeComponentInstanceIndex,/// The table index for the `error-context` type in the caller instance.ty: TypeComponentLocalErrorContextTableIndex,/// String encoding, memory, etc. to use when loading debug message.@@ -958,6 +1007,8 @@ pub enum Trampoline {/// Note that the debug message might not necessarily match what was passed/// to `error.new`.ErrorContextDebugMessage {+ /// The specific component instance which is calling the intrinsic.+ instance: RuntimeComponentInstanceIndex,/// The table index for the `error-context` type in the caller instance.ty: TypeComponentLocalErrorContextTableIndex,/// String encoding, memory, etc. to use when storing debug message.@@ -966,6 +1017,8 @@ pub enum Trampoline {/// A `error-context.drop` intrinsic to drop a specified `error-context`.ErrorContextDrop {+ /// The specific component instance which is calling the intrinsic.+ instance: RuntimeComponentInstanceIndex,/// The table index for the `error-context` type in the caller instance.ty: TypeComponentLocalErrorContextTableIndex,},@@ -1014,7 +1067,6 @@ pub enum Trampoline {AsyncStartCall {/// The callee's callback, if any.callback: Option<RuntimeCallbackIndex>,-/// The callee's post-return function, if any.post_return: Option<RuntimePostReturnIndex>,},@@ -1047,13 +1099,23 @@ pub enum Trampoline {////// The payload here represents that this is accessing the Nth slot of local/// storage.- ContextGet(u32),+ ContextGet {+ /// The specific component instance which is calling the intrinsic.+ instance: RuntimeComponentInstanceIndex,+ /// Which slot to access.+ slot: u32,+ },/// Intrinsic used to implement the `context.set` component model builtin.////// The payload here represents that this is accessing the Nth slot of local/// storage.- ContextSet(u32),+ ContextSet {+ /// The specific component instance which is calling the intrinsic.+ instance: RuntimeComponentInstanceIndex,+ /// Which slot to update.+ slot: u32,+ },}impl Trampoline {@@ -1074,9 +1136,9 @@ impl Trampoline {format!("component-transcode-{op}-m{from}-m{to}")}AlwaysTrap => format!("component-always-trap"),- ResourceNew(i) => format!("component-resource-new[{}]", i.as_u32()),- ResourceRep(i) => format!("component-resource-rep[{}]", i.as_u32()),- ResourceDrop(i) => format!("component-resource-drop[{}]", i.as_u32()),+ ResourceNew { ty, .. } => format!("component-resource-new[{}]", ty.as_u32()),+ ResourceRep { ty, .. } => format!("component-resource-rep[{}]", ty.as_u32()),+ ResourceDrop { ty, .. } => format!("component-resource-drop[{}]", ty.as_u32()),BackpressureSet { .. } => format!("backpressure-set"),BackpressureInc { .. } => format!("backpressure-inc"),BackpressureDec { .. } => format!("backpressure-dec"),@@ -1117,8 +1179,8 @@ impl Trampoline {FutureTransfer => format!("future-transfer"),StreamTransfer => format!("stream-transfer"),ErrorContextTransfer => format!("error-context-transfer"),- ContextGet(_) => format!("context-get"),- ContextSet(_) => format!("context-set"),+ ContextGet { .. } => format!("context-get"),+ ContextSet { .. } => format!("context-set"),}}}diff --git a/crates/environ/src/component/translate/inline.rs b/crates/environ/src/component/translate/inline.rsindex f898321c7c..62e7d28ad8 100644--- a/crates/environ/src/component/translate/inline.rs+++ b/crates/environ/src/component/translate/inline.rs@@ -650,26 +650,35 @@ impl<'a> Inliner<'a> {// information and then new entries for each intrinsic are recorded.ResourceNew(id, ty) => {let id = types.resource_id(id.resource());- let index = self- .result- .trampolines- .push((*ty, dfg::Trampoline::ResourceNew(id)));+ let index = self.result.trampolines.push((+ *ty,+ dfg::Trampoline::ResourceNew {+ instance: frame.instance,+ ty: id,+ },+ ));frame.funcs.push((*ty, dfg::CoreDef::Trampoline(index)));}ResourceRep(id, ty) => {let id = types.resource_id(id.resource());- let index = self- .result- .trampolines- .push((*ty, dfg::Trampoline::ResourceRep(id)));+ let index = self.result.trampolines.push((+ *ty,+ dfg::Trampoline::ResourceRep {+ instance: frame.instance,+ ty: id,+ },+ ));frame.funcs.push((*ty, dfg::CoreDef::Trampoline(index)));}ResourceDrop(id, ty) => {let id = types.resource_id(id.resource());- let index = self- .result- .trampolines- .push((*ty, dfg::Trampoline::ResourceDrop(id)));+ let index = self.result.trampolines.push((+ *ty,+ dfg::Trampoline::ResourceDrop {+ instance: frame.instance,+ ty: id,+ },+ ));frame.funcs.push((*ty, dfg::CoreDef::Trampoline(index)));}BackpressureSet { func } => {@@ -708,10 +717,14 @@ impl<'a> Inliner<'a> {let func = options.core_type;let options = self.adapter_options(frame, types, options);let options = self.canonical_options(options);- let index = self- .result- .trampolines- .push((func, dfg::Trampoline::TaskReturn { results, options }));+ let index = self.result.trampolines.push((+ func,+ dfg::Trampoline::TaskReturn {+ instance: frame.instance,+ results,+ options,+ },+ ));frame.funcs.push((func, dfg::CoreDef::Trampoline(index)));}TaskCancel { func } => {@@ -736,20 +749,26 @@ impl<'a> Inliner<'a> {let func = options.core_type;let options = self.adapter_options(frame, types, options);let options = self.canonical_options(options);- let index = self- .result- .trampolines- .push((func, dfg::Trampoline::WaitableSetWait { options }));+ let index = self.result.trampolines.push((+ func,+ dfg::Trampoline::WaitableSetWait {+ instance: frame.instance,+ options,+ },+ ));frame.funcs.push((func, dfg::CoreDef::Trampoline(index)));}WaitableSetPoll { options } => {let func = options.core_type;let options = self.adapter_options(frame, types, options);let options = self.canonical_options(options);- let index = self- .result- .trampolines- .push((func, dfg::Trampoline::WaitableSetPoll { options }));+ let index = self.result.trampolines.push((+ func,+ dfg::Trampoline::WaitableSetPoll {+ instance: frame.instance,+ options,+ },+ ));frame.funcs.push((func, dfg::CoreDef::Trampoline(index)));}WaitableSetDrop { func } => {@@ -774,6 +793,7 @@ impl<'a> Inliner<'a> {let index = self.result.trampolines.push((*func,dfg::Trampoline::ThreadYield {+ instance: frame.instance,cancellable: *cancellable,},));@@ -804,10 +824,13 @@ impl<'a> Inliner<'a> {else {unreachable!()};- let index = self- .result- .trampolines- .push((*func, dfg::Trampoline::StreamNew { ty }));+ let index = self.result.trampolines.push((+ *func,+ dfg::Trampoline::StreamNew {+ instance: frame.instance,+ ty,+ },+ ));frame.funcs.push((*func, dfg::CoreDef::Trampoline(index)));}StreamRead { ty, options } => {@@ -819,10 +842,14 @@ impl<'a> Inliner<'a> {let func = options.core_type;let options = self.adapter_options(frame, types, options);let options = self.canonical_options(options);- let index = self- .result- .trampolines- .push((func, dfg::Trampoline::StreamRead { ty, options }));+ let index = self.result.trampolines.push((+ func,+ dfg::Trampoline::StreamRead {+ instance: frame.instance,+ ty,+ options,+ },+ ));frame.funcs.push((func, dfg::CoreDef::Trampoline(index)));}StreamWrite { ty, options } => {@@ -834,10 +861,14 @@ impl<'a> Inliner<'a> {let func = options.core_type;let options = self.adapter_options(frame, types, options);let options = self.canonical_options(options);- let index = self- .result- .trampolines- .push((func, dfg::Trampoline::StreamWrite { ty, options }));+ let index = self.result.trampolines.push((+ func,+ dfg::Trampoline::StreamWrite {+ instance: frame.instance,+ ty,+ options,+ },+ ));frame.funcs.push((func, dfg::CoreDef::Trampoline(index)));}StreamCancelRead { ty, func, async_ } => {@@ -849,6 +880,7 @@ impl<'a> Inliner<'a> {let index = self.result.trampolines.push((*func,dfg::Trampoline::StreamCancelRead {+ instance: frame.instance,ty,async_: *async_,},@@ -864,6 +896,7 @@ impl<'a> Inliner<'a> {let index = self.result.trampolines.push((*func,dfg::Trampoline::StreamCancelWrite {+ instance: frame.instance,ty,async_: *async_,},@@ -876,10 +909,13 @@ impl<'a> Inliner<'a> {else {unreachable!()};- let index = self- .result- .trampolines- .push((*func, dfg::Trampoline::StreamDropReadable { ty }));+ let index = self.result.trampolines.push((+ *func,+ dfg::Trampoline::StreamDropReadable {+ instance: frame.instance,+ ty,+ },+ ));frame.funcs.push((*func, dfg::CoreDef::Trampoline(index)));}StreamDropWritable { ty, func } => {@@ -888,10 +924,13 @@ impl<'a> Inliner<'a> {else {unreachable!()};- let index = self- .result- .trampolines- .push((*func, dfg::Trampoline::StreamDropWritable { ty }));+ let index = self.result.trampolines.push((+ *func,+ dfg::Trampoline::StreamDropWritable {+ instance: frame.instance,+ ty,+ },+ ));frame.funcs.push((*func, dfg::CoreDef::Trampoline(index)));}FutureNew { ty, func } => {@@ -900,10 +939,13 @@ impl<'a> Inliner<'a> {else {unreachable!()};- let index = self- .result- .trampolines- .push((*func, dfg::Trampoline::FutureNew { ty }));+ let index = self.result.trampolines.push((+ *func,+ dfg::Trampoline::FutureNew {+ instance: frame.instance,+ ty,+ },+ ));frame.funcs.push((*func, dfg::CoreDef::Trampoline(index)));}FutureRead { ty, options } => {@@ -915,10 +957,14 @@ impl<'a> Inliner<'a> {let func = options.core_type;let options = self.adapter_options(frame, types, options);let options = self.canonical_options(options);- let index = self- .result- .trampolines- .push((func, dfg::Trampoline::FutureRead { ty, options }));+ let index = self.result.trampolines.push((+ func,+ dfg::Trampoline::FutureRead {+ instance: frame.instance,+ ty,+ options,+ },+ ));frame.funcs.push((func, dfg::CoreDef::Trampoline(index)));}FutureWrite { ty, options } => {@@ -930,10 +976,14 @@ impl<'a> Inliner<'a> {let func = options.core_type;let options = self.adapter_options(frame, types, options);let options = self.canonical_options(options);- let index = self- .result- .trampolines- .push((func, dfg::Trampoline::FutureWrite { ty, options }));+ let index = self.result.trampolines.push((+ func,+ dfg::Trampoline::FutureWrite {+ instance: frame.instance,+ ty,+ options,+ },+ ));frame.funcs.push((func, dfg::CoreDef::Trampoline(index)));}FutureCancelRead { ty, func, async_ } => {@@ -945,6 +995,7 @@ impl<'a> Inliner<'a> {let index = self.result.trampolines.push((*func,dfg::Trampoline::FutureCancelRead {+ instance: frame.instance,ty,async_: *async_,},@@ -960,6 +1011,7 @@ impl<'a> Inliner<'a> {let index = self.result.trampolines.push((*func,dfg::Trampoline::FutureCancelWrite {+ instance: frame.instance,ty,async_: *async_,},@@ -972,10 +1024,13 @@ impl<'a> Inliner<'a> {else {unreachable!()};- let index = self- .result- .trampolines- .push((*func, dfg::Trampoline::FutureDropReadable { ty }));+ let index = self.result.trampolines.push((+ *func,+ dfg::Trampoline::FutureDropReadable {+ instance: frame.instance,+ ty,+ },+ ));frame.funcs.push((*func, dfg::CoreDef::Trampoline(index)));}FutureDropWritable { ty, func } => {@@ -984,10 +1039,13 @@ impl<'a> Inliner<'a> {else {unreachable!()};- let index = self- .result- .trampolines- .push((*func, dfg::Trampoline::FutureDropWritable { ty }));+ let index = self.result.trampolines.push((+ *func,+ dfg::Trampoline::FutureDropWritable {+ instance: frame.instance,+ ty,+ },+ ));frame.funcs.push((*func, dfg::CoreDef::Trampoline(index)));}ErrorContextNew { options } => {@@ -995,10 +1053,14 @@ impl<'a> Inliner<'a> {let func = options.core_type;let options = self.adapter_options(frame, types, options);let options = self.canonical_options(options);- let index = self- .result- .trampolines- .push((func, dfg::Trampoline::ErrorContextNew { ty, options }));+ let index = self.result.trampolines.push((+ func,+ dfg::Trampoline::ErrorContextNew {+ instance: frame.instance,+ ty,+ options,+ },+ ));frame.funcs.push((func, dfg::CoreDef::Trampoline(index)));}ErrorContextDebugMessage { options } => {@@ -1008,30 +1070,43 @@ impl<'a> Inliner<'a> {let options = self.canonical_options(options);let index = self.result.trampolines.push((func,- dfg::Trampoline::ErrorContextDebugMessage { ty, options },+ dfg::Trampoline::ErrorContextDebugMessage {+ instance: frame.instance,+ ty,+ options,+ },));frame.funcs.push((func, dfg::CoreDef::Trampoline(index)));}ErrorContextDrop { func } => {let ty = types.error_context_table_type()?;- let index = self- .result- .trampolines- .push((*func, dfg::Trampoline::ErrorContextDrop { ty }));+ let index = self.result.trampolines.push((+ *func,+ dfg::Trampoline::ErrorContextDrop {+ instance: frame.instance,+ ty,+ },+ ));frame.funcs.push((*func, dfg::CoreDef::Trampoline(index)));}ContextGet { func, i } => {- let index = self- .result- .trampolines- .push((*func, dfg::Trampoline::ContextGet(*i)));+ let index = self.result.trampolines.push((+ *func,+ dfg::Trampoline::ContextGet {+ instance: frame.instance,+ slot: *i,+ },+ ));frame.funcs.push((*func, dfg::CoreDef::Trampoline(index)));}ContextSet { func, i } => {- let index = self- .result- .trampolines- .push((*func, dfg::Trampoline::ContextSet(*i)));+ let index = self.result.trampolines.push((+ *func,+ dfg::Trampoline::ContextSet {+ instance: frame.instance,+ slot: *i,+ },+ ));frame.funcs.push((*func, dfg::CoreDef::Trampoline(index)));}diff --git a/crates/environ/src/trap_encoding.rs b/crates/environ/src/trap_encoding.rsindex 169a27212d..15efa99b40 100644--- a/crates/environ/src/trap_encoding.rs+++ b/crates/environ/src/trap_encoding.rs@@ -107,6 +107,11 @@ pub enum Trap {/// that all host tasks have completed and any/all host-owned stream/future/// handles have been dropped.AsyncDeadlock,++ /// When the `component-model` feature is enabled this trap represents a+ /// scenario where a component instance tried to call an import or intrinsic+ /// when it wasn't allowed to, e.g. from a post-return function.+ CannotLeaveComponent,// if adding a variant here be sure to update the `check!` macro below}@@ -148,6 +153,7 @@ impl Trap {ContinuationAlreadyConsumedDisabledOpcodeAsyncDeadlock+ CannotLeaveComponent}None@@ -183,6 +189,7 @@ impl fmt::Display for Trap {ContinuationAlreadyConsumed => "continuation already consumed",DisabledOpcode => "pulley opcode disabled at compile time was executed",AsyncDeadlock => "deadlock detected: event loop cannot make further progress",+ CannotLeaveComponent => "cannot leave component instance",};write!(f, "wasm trap: {desc}")}diff --git a/crates/test-util/src/wast.rs b/crates/test-util/src/wast.rsindex 8467b786a7..7517f91998 100644--- a/crates/test-util/src/wast.rs+++ b/crates/test-util/src/wast.rs@@ -661,7 +661,7 @@ impl WastTest {}let failing_component_model_tests = [- // FIXME(#11676)+ // FIXME(#11683)"component-model/test/values/trap-in-post-return.wast",];if failing_component_model_testsdiff --git a/crates/wasmtime/src/runtime/component/concurrent.rs b/crates/wasmtime/src/runtime/component/concurrent.rsindex 832d95fe97..6ea9f69a9d 100644--- a/crates/wasmtime/src/runtime/component/concurrent.rs+++ b/crates/wasmtime/src/runtime/component/concurrent.rs@@ -882,6 +882,7 @@ impl ComponentInstance {mut self: Pin<&mut Self>,caller_instance: RuntimeComponentInstanceIndex,) -> Result<u32> {+ self.check_may_leave(caller_instance)?;let set = self.as_mut().concurrent_state_mut()@@ -897,6 +898,7 @@ impl ComponentInstance {caller_instance: RuntimeComponentInstanceIndex,set: u32,) -> Result<()> {+ self.check_may_leave(caller_instance)?;let rep = self.as_mut().guest_tables().0[caller_instance].waitable_set_remove(set)?;log::trace!("drop waitable set {rep} (handle {set})");@@ -919,6 +921,7 @@ impl ComponentInstance {waitable_handle: u32,set_handle: u32,) -> Result<()> {+ self.check_may_leave(caller_instance)?;let waitable = Waitable::from_instance(self.as_mut(), caller_instance, waitable_handle)?;let set = if set_handle == 0 {@@ -943,6 +946,7 @@ impl ComponentInstance {caller_instance: RuntimeComponentInstanceIndex,task_id: u32,) -> Result<()> {+ self.check_may_leave(caller_instance)?;self.as_mut().waitable_join(caller_instance, task_id, 0)?;let (rep, is_host) =@@ -1841,7 +1845,10 @@ impl Instance {.get_mut(guest_task)?.call_post_return_automatically(){- unsafe { flags.set_needs_post_return(false) }+ unsafe {+ flags.set_may_leave(false);+ flags.set_needs_post_return(false);+ }if let Some(func) = post_return {let mut store = token.as_context_mut(store);@@ -1860,7 +1867,10 @@ impl Instance {}}- unsafe { flags.set_may_enter(true) }+ unsafe {+ flags.set_may_leave(true);+ flags.set_may_enter(true);+ }}instance.task_complete(@@ -1928,6 +1938,8 @@ impl Instance {string_encoding: u8,caller_info: CallerInfo,) -> Result<()> {+ self.id().get(store.0).check_may_leave(caller_instance)?;+enum ResultInfo {Heap { results: u32 },Stack { result_count: u32 },@@ -2580,10 +2592,12 @@ impl Instance {pub(crate) fn task_return(self,store: &mut dyn VMStore,+ caller: RuntimeComponentInstanceIndex,ty: TypeTupleIndex,options: OptionsIndex,storage: &[ValRaw],) -> Result<()> {+ self.id().get(store).check_may_leave(caller)?;let state = self.concurrent_state_mut(store);let CanonicalOptions {string_encoding,@@ -2632,8 +2646,9 @@ impl Instance {pub(crate) fn task_cancel(self,store: &mut dyn VMStore,- _caller_instance: RuntimeComponentInstanceIndex,+ caller: RuntimeComponentInstanceIndex,) -> Result<()> {+ self.id().get(store).check_may_leave(caller)?;let state = self.concurrent_state_mut(store);let guest_task = state.guest_task.unwrap();let task = state.get_mut(guest_task)?;@@ -2719,10 +2734,12 @@ impl Instance {pub(crate) fn waitable_set_wait(self,store: &mut dyn VMStore,+ caller: RuntimeComponentInstanceIndex,options: OptionsIndex,set: u32,payload: u32,) -> Result<u32> {+ self.id().get(store).check_may_leave(caller)?;let opts = self.concurrent_state_mut(store).options(options);let cancellable = opts.cancellable;let caller_instance = opts.instance;@@ -2744,10 +2761,12 @@ impl Instance {pub(crate) fn waitable_set_poll(self,store: &mut dyn VMStore,+ caller: RuntimeComponentInstanceIndex,options: OptionsIndex,set: u32,payload: u32,) -> Result<u32> {+ self.id().get(store).check_may_leave(caller)?;let opts = self.concurrent_state_mut(store).options(options);let cancellable = opts.cancellable;let caller_instance = opts.instance;@@ -2766,7 +2785,13 @@ impl Instance {}/// Implements the `thread.yield` intrinsic.- pub(crate) fn thread_yield(self, store: &mut dyn VMStore, cancellable: bool) -> Result<bool> {+ pub(crate) fn thread_yield(+ self,+ store: &mut dyn VMStore,+ caller: RuntimeComponentInstanceIndex,+ cancellable: bool,+ ) -> Result<bool> {+ self.id().get(store).check_may_leave(caller)?;self.waitable_check(store, cancellable, WaitableCheck::Yield).map(|_| {if cancellable {@@ -2890,6 +2915,7 @@ impl Instance {async_: bool,task_id: u32,) -> Result<u32> {+ self.id().get(store).check_may_leave(caller_instance)?;let (rep, is_host) =self.id().get_mut(store).guest_tables().0[caller_instance].subtask_rep(task_id)?;let (waitable, expected_caller_instance) = if is_host {@@ -3037,6 +3063,27 @@ impl Instance {) -> &'a mut ConcurrentState {self.id().get_mut(store).concurrent_state_mut()}++ pub(crate) fn context_get(+ self,+ store: &mut dyn VMStore,+ caller: RuntimeComponentInstanceIndex,+ slot: u32,+ ) -> Result<u32> {+ self.id().get(store).check_may_leave(caller)?;+ self.concurrent_state_mut(store).context_get(slot)+ }++ pub(crate) fn context_set(+ self,+ store: &mut dyn VMStore,+ caller: RuntimeComponentInstanceIndex,+ slot: u32,+ value: u32,+ ) -> Result<()> {+ self.id().get(store).check_may_leave(caller)?;+ self.concurrent_state_mut(store).context_set(slot, value)+ }}/// Trait representing component model ABI async intrinsics and fused adapter@@ -3096,6 +3143,7 @@ pub trait VMComponentAsyncStore {fn future_write(&mut self,instance: Instance,+ caller: RuntimeComponentInstanceIndex,ty: TypeFutureTableIndex,options: OptionsIndex,future: u32,@@ -3106,6 +3154,7 @@ pub trait VMComponentAsyncStore {fn future_read(&mut self,instance: Instance,+ caller: RuntimeComponentInstanceIndex,ty: TypeFutureTableIndex,options: OptionsIndex,future: u32,@@ -3116,6 +3165,7 @@ pub trait VMComponentAsyncStore {fn future_drop_writable(&mut self,instance: Instance,+ caller: RuntimeComponentInstanceIndex,ty: TypeFutureTableIndex,writer: u32,) -> Result<()>;@@ -3124,6 +3174,7 @@ pub trait VMComponentAsyncStore {fn stream_write(&mut self,instance: Instance,+ caller: RuntimeComponentInstanceIndex,ty: TypeStreamTableIndex,options: OptionsIndex,stream: u32,@@ -3135,6 +3186,7 @@ pub trait VMComponentAsyncStore {fn stream_read(&mut self,instance: Instance,+ caller: RuntimeComponentInstanceIndex,ty: TypeStreamTableIndex,options: OptionsIndex,stream: u32,@@ -3147,6 +3199,7 @@ pub trait VMComponentAsyncStore {fn flat_stream_write(&mut self,instance: Instance,+ caller: RuntimeComponentInstanceIndex,ty: TypeStreamTableIndex,options: OptionsIndex,payload_size: u32,@@ -3161,6 +3214,7 @@ pub trait VMComponentAsyncStore {fn flat_stream_read(&mut self,instance: Instance,+ caller: RuntimeComponentInstanceIndex,ty: TypeStreamTableIndex,options: OptionsIndex,payload_size: u32,@@ -3174,6 +3228,7 @@ pub trait VMComponentAsyncStore {fn stream_drop_writable(&mut self,instance: Instance,+ caller: RuntimeComponentInstanceIndex,ty: TypeStreamTableIndex,writer: u32,) -> Result<()>;@@ -3182,6 +3237,7 @@ pub trait VMComponentAsyncStore {fn error_context_debug_message(&mut self,instance: Instance,+ caller: RuntimeComponentInstanceIndex,ty: TypeComponentLocalErrorContextTableIndex,options: OptionsIndex,err_ctx_handle: u32,@@ -3293,11 +3349,13 @@ impl<T: 'static> VMComponentAsyncStore for StoreInner<T> {fn future_write(&mut self,instance: Instance,+ caller: RuntimeComponentInstanceIndex,ty: TypeFutureTableIndex,options: OptionsIndex,future: u32,address: u32,) -> Result<u32> {+ instance.id().get(self).check_may_leave(caller)?;instance.guest_write(StoreContextMut(self),@@ -3314,11 +3372,13 @@ impl<T: 'static> VMComponentAsyncStore for StoreInner<T> {fn future_read(&mut self,instance: Instance,+ caller: RuntimeComponentInstanceIndex,ty: TypeFutureTableIndex,options: OptionsIndex,future: u32,address: u32,) -> Result<u32> {+ instance.id().get(self).check_may_leave(caller)?;instance.guest_read(StoreContextMut(self),@@ -3335,12 +3395,14 @@ impl<T: 'static> VMComponentAsyncStore for StoreInner<T> {fn stream_write(&mut self,instance: Instance,+ caller: RuntimeComponentInstanceIndex,ty: TypeStreamTableIndex,options: OptionsIndex,stream: u32,address: u32,count: u32,) -> Result<u32> {+ instance.id().get(self).check_may_leave(caller)?;instance.guest_write(StoreContextMut(self),@@ -3357,12 +3419,14 @@ impl<T: 'static> VMComponentAsyncStore for StoreInner<T> {fn stream_read(&mut self,instance: Instance,+ caller: RuntimeComponentInstanceIndex,ty: TypeStreamTableIndex,options: OptionsIndex,stream: u32,address: u32,count: u32,) -> Result<u32> {+ instance.id().get(self).check_may_leave(caller)?;instance.guest_read(StoreContextMut(self),@@ -3379,15 +3443,18 @@ impl<T: 'static> VMComponentAsyncStore for StoreInner<T> {fn future_drop_writable(&mut self,instance: Instance,+ caller: RuntimeComponentInstanceIndex,ty: TypeFutureTableIndex,writer: u32,) -> Result<()> {+ instance.id().get(self).check_may_leave(caller)?;instance.guest_drop_writable(StoreContextMut(self), TransmitIndex::Future(ty), writer)}fn flat_stream_write(&mut self,instance: Instance,+ caller: RuntimeComponentInstanceIndex,ty: TypeStreamTableIndex,options: OptionsIndex,payload_size: u32,@@ -3396,6 +3463,7 @@ impl<T: 'static> VMComponentAsyncStore for StoreInner<T> {address: u32,count: u32,) -> Result<u32> {+ instance.id().get(self).check_may_leave(caller)?;instance.guest_write(StoreContextMut(self),@@ -3415,6 +3483,7 @@ impl<T: 'static> VMComponentAsyncStore for StoreInner<T> {fn flat_stream_read(&mut self,instance: Instance,+ caller: RuntimeComponentInstanceIndex,ty: TypeStreamTableIndex,options: OptionsIndex,payload_size: u32,@@ -3423,6 +3492,7 @@ impl<T: 'static> VMComponentAsyncStore for StoreInner<T> {address: u32,count: u32,) -> Result<u32> {+ instance.id().get(self).check_may_leave(caller)?;instance.guest_read(StoreContextMut(self),@@ -3442,20 +3512,24 @@ impl<T: 'static> VMComponentAsyncStore for StoreInner<T> {fn stream_drop_writable(&mut self,instance: Instance,+ caller: RuntimeComponentInstanceIndex,ty: TypeStreamTableIndex,writer: u32,) -> Result<()> {+ instance.id().get(self).check_may_leave(caller)?;instance.guest_drop_writable(StoreContextMut(self), TransmitIndex::Stream(ty), writer)}fn error_context_debug_message(&mut self,instance: Instance,+ caller: RuntimeComponentInstanceIndex,ty: TypeComponentLocalErrorContextTableIndex,options: OptionsIndex,err_ctx_handle: u32,debug_msg_address: u32,) -> Result<()> {+ instance.id().get(self).check_may_leave(caller)?;instance.error_context_debug_message(StoreContextMut(self),ty,diff --git a/crates/wasmtime/src/runtime/component/concurrent/futures_and_streams.rs b/crates/wasmtime/src/runtime/component/concurrent/futures_and_streams.rsindex 78d9390e69..ee0ee17549 100644--- a/crates/wasmtime/src/runtime/component/concurrent/futures_and_streams.rs+++ b/crates/wasmtime/src/runtime/component/concurrent/futures_and_streams.rs@@ -26,7 +26,7 @@ use std::sync::{Arc, Mutex};use std::task::{self, Context, Poll, Waker};use std::vec::Vec;use wasmtime_environ::component::{- CanonicalAbiInfo, ComponentTypes, InterfaceType, OptionsIndex,+ CanonicalAbiInfo, ComponentTypes, InterfaceType, OptionsIndex, RuntimeComponentInstanceIndex,TypeComponentGlobalErrorContextTableIndex, TypeComponentLocalErrorContextTableIndex,TypeFutureTableIndex, TypeStreamTableIndex,};@@ -3498,11 +3498,13 @@ impl Instance {pub(crate) fn error_context_new(self,store: &mut StoreOpaque,+ caller: RuntimeComponentInstanceIndex,ty: TypeComponentLocalErrorContextTableIndex,options: OptionsIndex,debug_msg_address: u32,debug_msg_len: u32,) -> Result<u32> {+ self.id().get(store).check_may_leave(caller)?;let options = Options::new_index(store, self, options);let lift_ctx = &mut LiftContext::new(store, &options, self);// Read string from guest memory@@ -3590,10 +3592,12 @@ impl Instance {pub(crate) fn future_cancel_read(self,store: &mut dyn VMStore,+ caller: RuntimeComponentInstanceIndex,ty: TypeFutureTableIndex,async_: bool,reader: u32,) -> Result<u32> {+ self.id().get(store).check_may_leave(caller)?;self.guest_cancel_read(store, TransmitIndex::Future(ty), async_, reader).map(|v| v.encode())}@@ -3602,10 +3606,12 @@ impl Instance {pub(crate) fn future_cancel_write(self,store: &mut dyn VMStore,+ caller: RuntimeComponentInstanceIndex,ty: TypeFutureTableIndex,async_: bool,writer: u32,) -> Result<u32> {+ self.id().get(store).check_may_leave(caller)?;self.guest_cancel_write(store, TransmitIndex::Future(ty), async_, writer).map(|v| v.encode())}@@ -3614,10 +3620,12 @@ impl Instance {pub(crate) fn stream_cancel_read(self,store: &mut dyn VMStore,+ caller: RuntimeComponentInstanceIndex,ty: TypeStreamTableIndex,async_: bool,reader: u32,) -> Result<u32> {+ self.id().get(store).check_may_leave(caller)?;self.guest_cancel_read(store, TransmitIndex::Stream(ty), async_, reader).map(|v| v.encode())}@@ -3626,10 +3634,12 @@ impl Instance {pub(crate) fn stream_cancel_write(self,store: &mut dyn VMStore,+ caller: RuntimeComponentInstanceIndex,ty: TypeStreamTableIndex,async_: bool,writer: u32,) -> Result<u32> {+ self.id().get(store).check_may_leave(caller)?;self.guest_cancel_write(store, TransmitIndex::Stream(ty), async_, writer).map(|v| v.encode())}@@ -3638,9 +3648,11 @@ impl Instance {pub(crate) fn future_drop_readable(self,store: &mut dyn VMStore,+ caller: RuntimeComponentInstanceIndex,ty: TypeFutureTableIndex,reader: u32,) -> Result<()> {+ self.id().get(store).check_may_leave(caller)?;self.guest_drop_readable(store, TransmitIndex::Future(ty), reader)}@@ -3648,9 +3660,11 @@ impl Instance {pub(crate) fn stream_drop_readable(self,store: &mut dyn VMStore,+ caller: RuntimeComponentInstanceIndex,ty: TypeStreamTableIndex,reader: u32,) -> Result<()> {+ self.id().get(store).check_may_leave(caller)?;self.guest_drop_readable(store, TransmitIndex::Stream(ty), reader)}}@@ -3713,9 +3727,12 @@ impl ComponentInstance {/// Drop the specified error context.pub(crate) fn error_context_drop(mut self: Pin<&mut Self>,+ caller: RuntimeComponentInstanceIndex,ty: TypeComponentLocalErrorContextTableIndex,error_context: u32,) -> Result<()> {+ self.check_may_leave(caller)?;+let local_handle_table = self.as_mut().table_for_error_context(ty);let rep = local_handle_table.error_context_drop(error_context)?;@@ -3775,16 +3792,20 @@ impl ComponentInstance {/// Implements the `future.new` intrinsic.pub(crate) fn future_new(self: Pin<&mut Self>,+ caller: RuntimeComponentInstanceIndex,ty: TypeFutureTableIndex,) -> Result<ResourcePair> {+ self.check_may_leave(caller)?;self.guest_new(TransmitIndex::Future(ty))}/// Implements the `stream.new` intrinsic.pub(crate) fn stream_new(self: Pin<&mut Self>,+ caller: RuntimeComponentInstanceIndex,ty: TypeStreamTableIndex,) -> Result<ResourcePair> {+ self.check_may_leave(caller)?;self.guest_new(TransmitIndex::Stream(ty))}diff --git a/crates/wasmtime/src/runtime/component/func.rs b/crates/wasmtime/src/runtime/component/func.rsindex 30fc79c51b..9a5f4b5565 100644--- a/crates/wasmtime/src/runtime/component/func.rs+++ b/crates/wasmtime/src/runtime/component/func.rs@@ -734,6 +734,10 @@ impl Func {// panic, even if the function call below traps.flags.set_needs_post_return(false);+ // Post return functions are forbidden from calling imports or+ // intrinsics.+ flags.set_may_leave(false);+// If the function actually had a `post-return` configured in its// canonical options that's executed here.//@@ -750,9 +754,10 @@ impl Func {}// And finally if everything completed successfully then the "may- // enter" flag is set to `true` again here which enables further use- // of the component.+ // enter" and "may leave" flags are set to `true` again here which+ // enables further use of the component.flags.set_may_enter(true);+ flags.set_may_leave(true);let (calls, host_table, _, instance) = store.0diff --git a/crates/wasmtime/src/runtime/component/func/host.rs b/crates/wasmtime/src/runtime/component/func/host.rsindex 4758da01f8..fc6eedffdf 100644--- a/crates/wasmtime/src/runtime/component/func/host.rs+++ b/crates/wasmtime/src/runtime/component/func/host.rs@@ -250,7 +250,7 @@ where// the component is disallowed, for example, when the `realloc` function// calls a canonical import.if unsafe { !flags.may_leave() } {- bail!("cannot leave component instance");+ return Err(anyhow!(crate::Trap::CannotLeaveComponent));}let types = vminstance.component().types().clone();@@ -724,7 +724,7 @@ where// the component is disallowed, for example, when the `realloc` function// calls a canonical import.if unsafe { !flags.may_leave() } {- bail!("cannot leave component instance");+ return Err(anyhow!(crate::Trap::CannotLeaveComponent));}let types = instance.id().get(store.0).component().types().clone();diff --git a/crates/wasmtime/src/runtime/component/instance.rs b/crates/wasmtime/src/runtime/component/instance.rsindex 6f78c47aef..a7aa6f1624 100644--- a/crates/wasmtime/src/runtime/component/instance.rs+++ b/crates/wasmtime/src/runtime/component/instance.rs@@ -378,9 +378,11 @@ impl Instance {pub(crate) fn resource_new32(self,store: &mut StoreOpaque,+ caller: RuntimeComponentInstanceIndex,ty: TypeResourceTableIndex,rep: u32,) -> Result<u32> {+ self.id().get(store).check_may_leave(caller)?;let (calls, _, _, instance) = store.component_resource_state_with_instance(self);resource_tables(calls, instance).resource_new(TypedResource::Component { ty, rep })}@@ -390,9 +392,11 @@ impl Instance {pub(crate) fn resource_rep32(self,store: &mut StoreOpaque,+ caller: RuntimeComponentInstanceIndex,ty: TypeResourceTableIndex,index: u32,) -> Result<u32> {+ self.id().get(store).check_may_leave(caller)?;let (calls, _, _, instance) = store.component_resource_state_with_instance(self);resource_tables(calls, instance).resource_rep(TypedResourceIndex::Component { ty, index })}@@ -401,9 +405,11 @@ impl Instance {pub(crate) fn resource_drop(self,store: &mut StoreOpaque,+ caller: RuntimeComponentInstanceIndex,ty: TypeResourceTableIndex,index: u32,) -> Result<Option<u32>> {+ self.id().get(store).check_may_leave(caller)?;let (calls, _, _, instance) = store.component_resource_state_with_instance(self);resource_tables(calls, instance).resource_drop(TypedResourceIndex::Component { ty, index })}diff --git a/crates/wasmtime/src/runtime/vm/component.rs b/crates/wasmtime/src/runtime/vm/component.rsindex 541b8823ab..a8fc564d0e 100644--- a/crates/wasmtime/src/runtime/vm/component.rs+++ b/crates/wasmtime/src/runtime/vm/component.rs@@ -890,6 +890,18 @@ impl ComponentInstance {// the map returned.unsafe { &mut self.get_unchecked_mut().concurrent_state }}++ pub(crate) fn check_may_leave(+ &self,+ instance: RuntimeComponentInstanceIndex,+ ) -> anyhow::Result<()> {+ let flags = self.instance_flags(instance);+ if unsafe { flags.may_leave() } {+ Ok(())+ } else {+ Err(anyhow::anyhow!(crate::Trap::CannotLeaveComponent))+ }+ }}// SAFETY: `layout` should describe this accurately and `OwnedVMContext` is thediff --git a/crates/wasmtime/src/runtime/vm/component/libcalls.rs b/crates/wasmtime/src/runtime/vm/component/libcalls.rsindex 7e4c1e29f4..4346c56a12 100644--- a/crates/wasmtime/src/runtime/vm/component/libcalls.rs+++ b/crates/wasmtime/src/runtime/vm/component/libcalls.rs@@ -579,33 +579,42 @@ fn inflate_latin1_bytes(dst: &mut [u16], latin1_bytes_so_far: usize) -> &mut [u1fn resource_new32(store: &mut dyn VMStore,instance: Instance,+ caller_instance: u32,resource: u32,rep: u32,) -> Result<u32> {+ let caller_instance = RuntimeComponentInstanceIndex::from_u32(caller_instance);let resource = TypeResourceTableIndex::from_u32(resource);- instance.resource_new32(store, resource, rep)+ instance.resource_new32(store, caller_instance, resource, rep)}fn resource_rep32(store: &mut dyn VMStore,instance: Instance,+ caller_instance: u32,resource: u32,idx: u32,) -> Result<u32> {+ let caller_instance = RuntimeComponentInstanceIndex::from_u32(caller_instance);let resource = TypeResourceTableIndex::from_u32(resource);- instance.resource_rep32(store, resource, idx)+ instance.resource_rep32(store, caller_instance, resource, idx)}fn resource_drop(store: &mut dyn VMStore,instance: Instance,+ caller_instance: u32,resource: u32,idx: u32,) -> Result<ResourceDropRet> {+ let caller_instance = RuntimeComponentInstanceIndex::from_u32(caller_instance);let resource = TypeResourceTableIndex::from_u32(resource);- Ok(ResourceDropRet(- instance.resource_drop(store, resource, idx)?,- ))+ Ok(ResourceDropRet(instance.resource_drop(+ store,+ caller_instance,+ resource,+ idx,+ )?))}struct ResourceDropRet(Option<u32>);@@ -693,6 +702,7 @@ fn backpressure_modify(unsafe fn task_return(store: &mut dyn VMStore,instance: Instance,+ caller_instance: u32,ty: u32,options: u32,storage: *mut u8,@@ -700,6 +710,7 @@ unsafe fn task_return() -> Result<()> {instance.task_return(store,+ RuntimeComponentInstanceIndex::from_u32(caller_instance),TypeTupleIndex::from_u32(ty),OptionsIndex::from_u32(options),unsafe { core::slice::from_raw_parts(storage.cast(), storage_len) },@@ -730,22 +741,36 @@ fn waitable_set_new(fn waitable_set_wait(store: &mut dyn VMStore,instance: Instance,+ caller: u32,options: u32,set: u32,payload: u32,) -> Result<u32> {- instance.waitable_set_wait(store, OptionsIndex::from_u32(options), set, payload)+ instance.waitable_set_wait(+ store,+ RuntimeComponentInstanceIndex::from_u32(caller),+ OptionsIndex::from_u32(options),+ set,+ payload,+ )}#[cfg(feature = "component-model-async")]fn waitable_set_poll(store: &mut dyn VMStore,instance: Instance,+ caller: u32,options: u32,set: u32,payload: u32,) -> Result<u32> {- instance.waitable_set_poll(store, OptionsIndex::from_u32(options), set, payload)+ instance.waitable_set_poll(+ store,+ RuntimeComponentInstanceIndex::from_u32(caller),+ OptionsIndex::from_u32(options),+ set,+ payload,+ )}#[cfg(feature = "component-model-async")]@@ -777,8 +802,17 @@ fn waitable_join(}#[cfg(feature = "component-model-async")]-fn thread_yield(store: &mut dyn VMStore, instance: Instance, cancellable: u8) -> Result<bool> {- instance.thread_yield(store, cancellable != 0)+fn thread_yield(+ store: &mut dyn VMStore,+ instance: Instance,+ caller_instance: u32,+ cancellable: u8,+) -> Result<bool> {+ instance.thread_yield(+ store,+ RuntimeComponentInstanceIndex::from_u32(caller_instance),+ cancellable != 0,+ )}#[cfg(feature = "component-model-async")]@@ -946,17 +980,23 @@ unsafe impl HostResultHasUnwindSentinel for ResourcePair {}#[cfg(feature = "component-model-async")]-fn future_new(store: &mut dyn VMStore, instance: Instance, ty: u32) -> Result<ResourcePair> {- instance- .id()- .get_mut(store)- .future_new(TypeFutureTableIndex::from_u32(ty))+fn future_new(+ store: &mut dyn VMStore,+ instance: Instance,+ caller_instance: u32,+ ty: u32,+) -> Result<ResourcePair> {+ instance.id().get_mut(store).future_new(+ RuntimeComponentInstanceIndex::from_u32(caller_instance),+ TypeFutureTableIndex::from_u32(ty),+ )}#[cfg(feature = "component-model-async")]fn future_write(store: &mut dyn VMStore,instance: Instance,+ caller_instance: u32,ty: u32,options: u32,future: u32,@@ -964,6 +1004,7 @@ fn future_write() -> Result<u32> {store.component_async_store().future_write(instance,+ RuntimeComponentInstanceIndex::from_u32(caller_instance),TypeFutureTableIndex::from_u32(ty),OptionsIndex::from_u32(options),future,@@ -975,6 +1016,7 @@ fn future_write(fn future_read(store: &mut dyn VMStore,instance: Instance,+ caller_instance: u32,ty: u32,options: u32,future: u32,@@ -982,6 +1024,7 @@ fn future_read() -> Result<u32> {store.component_async_store().future_read(instance,+ RuntimeComponentInstanceIndex::from_u32(caller_instance),TypeFutureTableIndex::from_u32(ty),OptionsIndex::from_u32(options),future,@@ -993,12 +1036,14 @@ fn future_read(fn future_cancel_write(store: &mut dyn VMStore,instance: Instance,+ caller_instance: u32,ty: u32,async_: u8,writer: u32,) -> Result<u32> {instance.future_cancel_write(store,+ RuntimeComponentInstanceIndex::from_u32(caller_instance),TypeFutureTableIndex::from_u32(ty),async_ != 0,writer,@@ -1009,12 +1054,14 @@ fn future_cancel_write(fn future_cancel_read(store: &mut dyn VMStore,instance: Instance,+ caller_instance: u32,ty: u32,async_: u8,reader: u32,) -> Result<u32> {instance.future_cancel_read(store,+ RuntimeComponentInstanceIndex::from_u32(caller_instance),TypeFutureTableIndex::from_u32(ty),async_ != 0,reader,@@ -1025,11 +1072,13 @@ fn future_cancel_read(fn future_drop_writable(store: &mut dyn VMStore,instance: Instance,+ caller_instance: u32,ty: u32,writer: u32,) -> Result<()> {store.component_async_store().future_drop_writable(instance,+ RuntimeComponentInstanceIndex::from_u32(caller_instance),TypeFutureTableIndex::from_u32(ty),writer,)@@ -1039,24 +1088,36 @@ fn future_drop_writable(fn future_drop_readable(store: &mut dyn VMStore,instance: Instance,+ caller_instance: u32,ty: u32,reader: u32,) -> Result<()> {- instance.future_drop_readable(store, TypeFutureTableIndex::from_u32(ty), reader)+ instance.future_drop_readable(+ store,+ RuntimeComponentInstanceIndex::from_u32(caller_instance),+ TypeFutureTableIndex::from_u32(ty),+ reader,+ )}#[cfg(feature = "component-model-async")]-fn stream_new(store: &mut dyn VMStore, instance: Instance, ty: u32) -> Result<ResourcePair> {- instance- .id()- .get_mut(store)- .stream_new(TypeStreamTableIndex::from_u32(ty))+fn stream_new(+ store: &mut dyn VMStore,+ instance: Instance,+ caller_instance: u32,+ ty: u32,+) -> Result<ResourcePair> {+ instance.id().get_mut(store).stream_new(+ RuntimeComponentInstanceIndex::from_u32(caller_instance),+ TypeStreamTableIndex::from_u32(ty),+ )}#[cfg(feature = "component-model-async")]fn stream_write(store: &mut dyn VMStore,instance: Instance,+ caller_instance: u32,ty: u32,options: u32,stream: u32,@@ -1065,6 +1126,7 @@ fn stream_write() -> Result<u32> {store.component_async_store().stream_write(instance,+ RuntimeComponentInstanceIndex::from_u32(caller_instance),TypeStreamTableIndex::from_u32(ty),OptionsIndex::from_u32(options),stream,@@ -1077,6 +1139,7 @@ fn stream_write(fn stream_read(store: &mut dyn VMStore,instance: Instance,+ caller_instance: u32,ty: u32,options: u32,stream: u32,@@ -1085,6 +1148,7 @@ fn stream_read() -> Result<u32> {store.component_async_store().stream_read(instance,+ RuntimeComponentInstanceIndex::from_u32(caller_instance),TypeStreamTableIndex::from_u32(ty),OptionsIndex::from_u32(options),stream,@@ -1097,12 +1161,14 @@ fn stream_read(fn stream_cancel_write(store: &mut dyn VMStore,instance: Instance,+ caller_instance: u32,ty: u32,async_: u8,writer: u32,) -> Result<u32> {instance.stream_cancel_write(store,+ RuntimeComponentInstanceIndex::from_u32(caller_instance),TypeStreamTableIndex::from_u32(ty),async_ != 0,writer,@@ -1113,12 +1179,14 @@ fn stream_cancel_write(fn stream_cancel_read(store: &mut dyn VMStore,instance: Instance,+ caller_instance: u32,ty: u32,async_: u8,reader: u32,) -> Result<u32> {instance.stream_cancel_read(store,+ RuntimeComponentInstanceIndex::from_u32(caller_instance),TypeStreamTableIndex::from_u32(ty),async_ != 0,reader,@@ -1129,11 +1197,13 @@ fn stream_cancel_read(fn stream_drop_writable(store: &mut dyn VMStore,instance: Instance,+ caller_instance: u32,ty: u32,writer: u32,) -> Result<()> {store.component_async_store().stream_drop_writable(instance,+ RuntimeComponentInstanceIndex::from_u32(caller_instance),TypeStreamTableIndex::from_u32(ty),writer,)@@ -1143,16 +1213,23 @@ fn stream_drop_writable(fn stream_drop_readable(store: &mut dyn VMStore,instance: Instance,+ caller_instance: u32,ty: u32,reader: u32,) -> Result<()> {- instance.stream_drop_readable(store, TypeStreamTableIndex::from_u32(ty), reader)+ instance.stream_drop_readable(+ store,+ RuntimeComponentInstanceIndex::from_u32(caller_instance),+ TypeStreamTableIndex::from_u32(ty),+ reader,+ )}#[cfg(feature = "component-model-async")]fn flat_stream_write(store: &mut dyn VMStore,instance: Instance,+ caller_instance: u32,ty: u32,options: u32,payload_size: u32,@@ -1163,6 +1240,7 @@ fn flat_stream_write() -> Result<u32> {store.component_async_store().flat_stream_write(instance,+ RuntimeComponentInstanceIndex::from_u32(caller_instance),TypeStreamTableIndex::from_u32(ty),OptionsIndex::from_u32(options),payload_size,@@ -1177,6 +1255,7 @@ fn flat_stream_write(fn flat_stream_read(store: &mut dyn VMStore,instance: Instance,+ caller_instance: u32,ty: u32,options: u32,payload_size: u32,@@ -1187,6 +1266,7 @@ fn flat_stream_read() -> Result<u32> {store.component_async_store().flat_stream_read(instance,+ RuntimeComponentInstanceIndex::from_u32(caller_instance),TypeStreamTableIndex::from_u32(ty),OptionsIndex::from_u32(options),payload_size,@@ -1201,6 +1281,7 @@ fn flat_stream_read(fn error_context_new(store: &mut dyn VMStore,instance: Instance,+ caller_instance: u32,ty: u32,options: u32,debug_msg_address: u32,@@ -1208,6 +1289,7 @@ fn error_context_new() -> Result<u32> {instance.error_context_new(store.store_opaque_mut(),+ RuntimeComponentInstanceIndex::from_u32(caller_instance),TypeComponentLocalErrorContextTableIndex::from_u32(ty),OptionsIndex::from_u32(options),debug_msg_address,@@ -1219,6 +1301,7 @@ fn error_context_new(fn error_context_debug_message(store: &mut dyn VMStore,instance: Instance,+ caller_instance: u32,ty: u32,options: u32,err_ctx_handle: u32,@@ -1226,6 +1309,7 @@ fn error_context_debug_message() -> Result<()> {store.component_async_store().error_context_debug_message(instance,+ RuntimeComponentInstanceIndex::from_u32(caller_instance),TypeComponentLocalErrorContextTableIndex::from_u32(ty),OptionsIndex::from_u32(options),err_ctx_handle,@@ -1237,21 +1321,43 @@ fn error_context_debug_message(fn error_context_drop(store: &mut dyn VMStore,instance: Instance,+ caller_instance: u32,ty: u32,err_ctx_handle: u32,) -> Result<()> {instance.id().get_mut(store).error_context_drop(+ RuntimeComponentInstanceIndex::from_u32(caller_instance),TypeComponentLocalErrorContextTableIndex::from_u32(ty),err_ctx_handle,)}#[cfg(feature = "component-model-async")]-fn context_get(store: &mut dyn VMStore, instance: Instance, slot: u32) -> Result<u32> {- instance.concurrent_state_mut(store).context_get(slot)+fn context_get(+ store: &mut dyn VMStore,+ instance: Instance,+ caller_instance: u32,+ slot: u32,+) -> Result<u32> {+ instance.context_get(+ store,+ RuntimeComponentInstanceIndex::from_u32(caller_instance),+ slot,+ )}#[cfg(feature = "component-model-async")]-fn context_set(store: &mut dyn VMStore, instance: Instance, slot: u32, val: u32) -> Result<()> {- instance.concurrent_state_mut(store).context_set(slot, val)+fn context_set(+ store: &mut dyn VMStore,+ instance: Instance,+ caller_instance: u32,+ slot: u32,+ val: u32,+) -> Result<()> {+ instance.context_set(+ store,+ RuntimeComponentInstanceIndex::from_u32(caller_instance),+ slot,+ val,+ )}diff --git a/crates/wast/src/wast.rs b/crates/wast/src/wast.rsindex 91b327c59c..cf29d38eda 100644--- a/crates/wast/src/wast.rs+++ b/crates/wast/src/wast.rs@@ -311,12 +311,15 @@ impl WastContext {};Ok(match result {Ok(()) => {- match &replace.rt {- Some(rt) => rt.block_on(func.post_return_async(&mut *store))?,- None => func.post_return(&mut *store)?,+ let result = match &replace.rt {+ Some(rt) => rt.block_on(func.post_return_async(&mut *store)),+ None => func.post_return(&mut *store),+ };++ match result {+ Ok(()) => Outcome::Ok(Results::Component(results)),+ Err(e) => Outcome::Trap(e),}-- Outcome::Ok(Results::Component(results))}Err(e) => Outcome::Trap(e),})diff --git a/tests/all/component_model/post_return.rs b/tests/all/component_model/post_return.rsindex 6d86c4db69..e8d95a9364 100644--- a/tests/all/component_model/post_return.rs+++ b/tests/all/component_model/post_return.rs@@ -118,25 +118,23 @@ fn invoke_post_return() -> Result<()> {let engine = super::engine();let component = Component::new(&engine, component)?;- let mut store = Store::new(&engine, false);+ let mut store = Store::new(&engine, ());let mut linker = Linker::new(&engine);- linker.root().func_wrap(- "f",- |mut store: StoreContextMut<'_, bool>, _: ()| -> Result<()> {- assert!(!*store.data());- *store.data_mut() = true;- Ok(())- },- )?;+ linker+ .root()+ .func_wrap("f", |_: StoreContextMut<'_, ()>, _: ()| -> Result<()> {+ unreachable!()+ })?;let instance = linker.instantiate(&mut store, &component)?;let thunk = instance.get_typed_func::<(), ()>(&mut store, "thunk")?;- assert!(!*store.data());thunk.call(&mut store, ())?;- assert!(!*store.data());- thunk.post_return(&mut store)?;- assert!(*store.data());+ let result = thunk.post_return(&mut store);+ assert!(matches!(+ result.unwrap_err().downcast::<Trap>(),+ Ok(Trap::CannotLeaveComponent)+ ));Ok(())}diff --git a/tests/all/component_model/resources.rs b/tests/all/component_model/resources.rsindex 899fdc0120..f55a125828 100644--- a/tests/all/component_model/resources.rs+++ b/tests/all/component_model/resources.rs@@ -1311,60 +1311,48 @@ fn pass_host_borrow_to_guest() -> Result<()> {Ok(())}-#[test]-fn drop_on_owned_resource() -> Result<()> {- let engine = super::engine();+#[tokio::test]+async fn drop_on_owned_resource() -> Result<()> {+ let mut config = wasmtime::Config::new();+ config.wasm_component_model_async(true);+ config.async_support(true);+ let engine = &wasmtime::Engine::new(&config)?;let c = Component::new(&engine,r#"(component(import "t" (type $t (sub resource)))(import "[constructor]t" (func $ctor (result (own $t))))- (import "[method]t.foo" (func $foo (param "self" (borrow $t)) (result (list u8))))+ (import "[method]t.foo" (func $foo (param "self" (borrow $t))))(core func $ctor (canon lower (func $ctor)))(core func $drop (canon resource.drop $t))+ (core func $foo (canon lower (func $foo) async))- (core module $m1- (import "" "drop" (func $drop (param i32)))- (memory (export "memory") 1)- (global $to-drop (export "to-drop") (mut i32) (i32.const 0))- (func (export "realloc") (param i32 i32 i32 i32) (result i32)- (call $drop (global.get $to-drop))- unreachable)- )- (core instance $i1 (instantiate $m1- (with "" (instance- (export "drop" (func $drop))- ))- ))-- (core func $foo (canon lower (func $foo)- (memory $i1 "memory")- (realloc (func $i1 "realloc"))))-- (core module $m2+ (core module $m(import "" "ctor" (func $ctor (result i32)))- (import "" "foo" (func $foo (param i32 i32)))- (import "i1" "to-drop" (global $to-drop (mut i32)))+ (import "" "foo" (func $foo (param i32) (result i32)))+ (import "" "drop" (func $drop (param i32)))(func (export "f")(local $r i32)+ (local $status i32)(local.set $r (call $ctor))- (global.set $to-drop (local.get $r))- (call $foo- (local.get $r)- (i32.const 200))+ (local.set $status (call $foo (local.get $r)))+ (if (i32.ne (i32.const 1 (; STARTED ;)) (i32.and (local.get $status) (i32.const 0xf)))+ (then unreachable))+ (call $drop (local.get $r))+ (unreachable)))- (core instance $i2 (instantiate $m2+ (core instance $i (instantiate $m(with "" (instance(export "ctor" (func $ctor))(export "foo" (func $foo))+ (export "drop" (func $drop))))- (with "i1" (instance $i1))))- (func (export "f") (canon lift (core func $i2 "f")))+ (func (export "f") (canon lift (core func $i "f"))))"#,)?;@@ -1376,19 +1364,21 @@ fn drop_on_owned_resource() -> Result<()> {linker.root().resource("t", ResourceType::host::<MyType>(), |_, _| Ok(()))?;- linker.root().func_wrap("[constructor]t", |_cx, ()| {- Ok((Resource::<MyType>::new_own(300),))- })?;linker.root()- .func_wrap("[method]t.foo", |_cx, (r,): (Resource<MyType>,)| {+ .func_wrap_concurrent("[constructor]t", |_cx, ()| {+ Box::pin(async { Ok((Resource::<MyType>::new_own(300),)) })+ })?;+ linker+ .root()+ .func_wrap_concurrent("[method]t.foo", |_cx, (r,): (Resource<MyType>,)| {assert!(!r.owned());- Ok((vec![2u8],))+ Box::pin(core::future::pending::<Result<()>>())})?;- let i = linker.instantiate(&mut store, &c)?;+ let i = linker.instantiate_async(&mut store, &c).await?;let f = i.get_typed_func::<(), ()>(&mut store, "f")?;- let err = f.call(&mut store, ()).unwrap_err();+ let err = f.call_async(&mut store, ()).await.unwrap_err();assert!(format!("{err:?}").contains("cannot remove owned resource while borrowed"),"bad error: {err:?}"diff --git a/tests/disas/riscv64-component-builtins-asm.wat b/tests/disas/riscv64-component-builtins-asm.watindex 72b7e7a77d..cbbfd7de46 100644--- a/tests/disas/riscv64-component-builtins-asm.wat+++ b/tests/disas/riscv64-component-builtins-asm.wat@@ -17,32 +17,35 @@;; sd s0, 0(sp);; mv s0, sp;; addi sp, sp, -0x10-;; sd s11, 8(sp)-;; mv s11, a1-;; ld a3, 0x10(a0)-;; mv a4, s0-;; sd a4, 0x28(a3)-;; ld a4, 8(s0)-;; sd a4, 0x30(a3)-;; ld a5, 8(a0)-;; ld a5, 0x10(a5)-;; mv a1, zero-;; slli a1, a1, 0x20+;; sd s1, 8(sp)+;; mv s1, a1+;; mv a3, a2+;; ld a4, 0x10(a0)+;; mv a5, s0+;; sd a5, 0x28(a4)+;; ld a5, 8(s0)+;; sd a5, 0x30(a4)+;; ld a1, 8(a0)+;; ld a5, 0x10(a1)+;; mv a4, zero+;; slli a1, a4, 0x20;; srai a1, a1, 0x20-;; slli a2, a2, 0x20+;; slli a2, a4, 0x20;; srai a2, a2, 0x20+;; slli a3, a3, 0x20+;; srai a3, a3, 0x20;; jalr a5-;; addi a5, zero, -1-;; beq a0, a5, 0x1c-;; ld s11, 8(sp)+;; addi a1, zero, -1+;; beq a0, a1, 0x1c+;; ld s1, 8(sp);; addi sp, sp, 0x10;; ld ra, 8(sp);; ld s0, 0(sp);; addi sp, sp, 0x10;; ret-;; mv a1, s11-;; ld a0, 0x10(a1)-;; ld a2, 0x198(a0)+;; mv a1, s1+;; ld a2, 0x10(a1)+;; ld a2, 0x198(a2);; mv a0, a1;; jalr a2;; .byte 0x00, 0x00, 0x00, 0x00diff --git a/tests/disas/riscv64-component-builtins.wat b/tests/disas/riscv64-component-builtins.watindex 0623d03c9b..1451e59b56 100644--- a/tests/disas/riscv64-component-builtins.wat+++ b/tests/disas/riscv64-component-builtins.wat@@ -11,7 +11,7 @@);; function u0:0(i64 vmctx, i64, i32) tail {-;; sig0 = (i64 sext, i32 sext, i32 sext) -> i64 sext system_v+;; sig0 = (i64 sext, i32 sext, i32 sext, i32 sext) -> i64 sext system_v;; sig1 = (i64 sext vmctx) system_v;;;; block0(v0: i64, v1: i64, v2: i32):@@ -20,22 +20,22 @@;; store notrap aligned v4, v3+40;; v5 = get_return_address.i64;; store notrap aligned v5, v3+48-;; v7 = load.i64 notrap aligned readonly v0+8-;; v8 = load.i64 notrap aligned readonly v7+16+;; v8 = load.i64 notrap aligned readonly v0+8+;; v9 = load.i64 notrap aligned readonly v8+16;; v6 = iconst.i32 0-;; v9 = call_indirect sig0, v8(v0, v6, v2) ; v6 = 0-;; v10 = iconst.i64 -1-;; v11 = icmp ne v9, v10 ; v10 = -1-;; brif v11, block2, block1+;; v10 = call_indirect sig0, v9(v0, v6, v6, v2) ; v6 = 0, v6 = 0+;; v11 = iconst.i64 -1+;; v12 = icmp ne v10, v11 ; v11 = -1+;; brif v12, block2, block1;;;; block1 cold:-;; v12 = load.i64 notrap aligned readonly v1+16-;; v13 = load.i64 notrap aligned readonly v12+408-;; call_indirect sig1, v13(v1)+;; v13 = load.i64 notrap aligned readonly v1+16+;; v14 = load.i64 notrap aligned readonly v13+408+;; call_indirect sig1, v14(v1);; trap user1;;;; block2:-;; brif.i64 v9, block3, block4+;; brif.i64 v10, block3, block4;;;; block3:;; jump block4diff --git a/tests/misc_testsuite/component-model-async/trap-in-post-return.wast b/tests/misc_testsuite/component-model-async/trap-in-post-return.wastnew file mode 100644index 0000000000..be36491d29--- /dev/null+++ b/tests/misc_testsuite/component-model-async/trap-in-post-return.wast@@ -0,0 +1,257 @@+;;! 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")