Skip to content

Commit

Permalink
async/stream/future plumbing for wasmtime-environ
Browse files Browse the repository at this point in the history
I've split this out of bytecodealliance#9582 to make review easier.

This patch includes the plumbing needed to route
async/stream/future/error-context data from `wit-parser`, through the various
layers of `wasmtime-environ`, and on to `wasmtime-cranelift` and `wasmtime`.
The `wasmtime::runtime`, `wasmtime_environ::fact`, and
`wasmtime_cranelift::compiler::component` modules only contain `todo!()` stubs
to begin with; I'll flesh those out in later PRs.

Signed-off-by: Joel Dice <[email protected]>

remove debugging code

Signed-off-by: Joel Dice <[email protected]>

revert comment formatting change in trap_encoding.rs

Signed-off-by: Joel Dice <[email protected]>

deduplicate code in inline.rs

Signed-off-by: Joel Dice <[email protected]>

remove `ComponentTypesBuilder::error_context_type`

This was just an alias for `error_context_table_type`, which I've made public.

Signed-off-by: Joel Dice <[email protected]>

defer `VMComponentOffsets` changes to a future PR

Signed-off-by: Joel Dice <[email protected]>
  • Loading branch information
dicej committed Jan 22, 2025
1 parent 636435f commit 8f4d991
Show file tree
Hide file tree
Showing 22 changed files with 1,701 additions and 91 deletions.
123 changes: 123 additions & 0 deletions crates/cranelift/src/compiler/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,103 @@ impl<'a> TrampolineCompiler<'a> {
Trampoline::AlwaysTrap => {
self.translate_always_trap();
}
Trampoline::TaskBackpressure { instance } => {
_ = instance;
todo!()
}
Trampoline::TaskReturn => todo!(),
Trampoline::TaskWait {
instance,
async_,
memory,
} => {
_ = (instance, async_, memory);
todo!()
}
Trampoline::TaskPoll {
instance,
async_,
memory,
} => {
_ = (instance, async_, memory);
todo!()
}
Trampoline::TaskYield { async_ } => {
_ = async_;
todo!()
}
Trampoline::SubtaskDrop { instance } => {
_ = instance;
todo!()
}
Trampoline::StreamNew { ty } => {
_ = ty;
todo!()
}
Trampoline::StreamRead { ty, options } => {
_ = (ty, options);
todo!()
}
Trampoline::StreamWrite { ty, options } => {
_ = (ty, options);
todo!()
}
Trampoline::StreamCancelRead { ty, async_ } => {
_ = (ty, async_);
todo!()
}
Trampoline::StreamCancelWrite { ty, async_ } => {
_ = (ty, async_);
todo!()
}
Trampoline::StreamCloseReadable { ty } => {
_ = ty;
todo!()
}
Trampoline::StreamCloseWritable { ty } => {
_ = ty;
todo!()
}
Trampoline::FutureNew { ty } => {
_ = ty;
todo!()
}
Trampoline::FutureRead { ty, options } => {
_ = (ty, options);
todo!()
}
Trampoline::FutureWrite { ty, options } => {
_ = (ty, options);
todo!()
}
Trampoline::FutureCancelRead { ty, async_ } => {
_ = (ty, async_);
todo!()
}
Trampoline::FutureCancelWrite { ty, async_ } => {
_ = (ty, async_);
todo!()
}
Trampoline::FutureCloseReadable { ty } => {
_ = ty;
todo!()
}
Trampoline::FutureCloseWritable { ty } => {
_ = ty;
todo!()
}
Trampoline::ErrorContextNew { ty, options } => {
_ = (ty, options);
todo!()
}
Trampoline::ErrorContextDebugMessage { ty, options } => {
_ = (ty, options);
todo!()
}
Trampoline::ErrorContextDrop { ty } => {
_ = ty;
todo!()
}
Trampoline::ResourceNew(ty) => self.translate_resource_new(*ty),
Trampoline::ResourceRep(ty) => self.translate_resource_rep(*ty),
Trampoline::ResourceDrop(ty) => self.translate_resource_drop(*ty),
Expand All @@ -115,6 +212,26 @@ impl<'a> TrampolineCompiler<'a> {
me.raise_if_host_trapped(rets.pop().unwrap());
})
}
Trampoline::AsyncEnterCall => todo!(),
Trampoline::AsyncExitCall {
callback,
post_return,
} => {
_ = (callback, post_return);
todo!()
}
Trampoline::FutureTransfer => {
_ = host::future_transfer;
todo!()
}
Trampoline::StreamTransfer => {
_ = host::stream_transfer;
todo!()
}
Trampoline::ErrorContextTransfer => {
_ = host::error_context_transfer;
todo!()
}
}
}

Expand Down Expand Up @@ -159,8 +276,14 @@ impl<'a> TrampolineCompiler<'a> {
realloc,
post_return,
string_encoding,
callback: _,
async_,
} = *options;

if async_ {
todo!()
}

// vmctx: *mut VMComponentContext
host_sig.params.push(ir::AbiParam::new(pointer_type));
callee_args.push(vmctx);
Expand Down
4 changes: 4 additions & 0 deletions crates/environ/examples/factc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ impl Factc {
realloc: Some(dummy_def()),
// Lowering never allows `post-return`
post_return: None,
async_: false,
callback: None,
},
lift_options: AdapterOptions {
instance: RuntimeComponentInstanceIndex::from_u32(1),
Expand All @@ -159,6 +161,8 @@ impl Factc {
} else {
None
},
async_: false,
callback: None,
},
func: dummy_def(),
});
Expand Down
4 changes: 4 additions & 0 deletions crates/environ/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ macro_rules! foreach_builtin_component_function {
resource_enter_call(vmctx: vmctx);
resource_exit_call(vmctx: vmctx) -> bool;

future_transfer(vmctx: vmctx, src_idx: u32, src_table: u32, dst_table: u32) -> u64;
stream_transfer(vmctx: vmctx, src_idx: u32, src_table: u32, dst_table: u32) -> u64;
error_context_transfer(vmctx: vmctx, src_idx: u32, src_table: u32, dst_table: u32) -> u64;

trap(vmctx: vmctx, code: u8);

utf8_to_utf8(src: ptr_u8, len: size, dst: ptr_u8) -> bool;
Expand Down
Loading

0 comments on commit 8f4d991

Please sign in to comment.