Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
148 changes: 84 additions & 64 deletions Cargo.lock

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -303,16 +303,16 @@ wit-bindgen = { version = "0.39.0", default-features = false }
wit-bindgen-rust-macro = { version = "0.39.0", default-features = false }

# wasm-tools family:
wasmparser = { version = "0.226.0", default-features = false, features = ['simd'] }
wat = "1.226.0"
wast = "226.0.0"
wasmprinter = "0.226.0"
wasm-encoder = "0.226.0"
wasm-smith = "0.226.0"
wasm-mutate = "0.226.0"
wit-parser = "0.226.0"
wit-component = "0.226.0"
wasm-wave = "0.226.0"
wasmparser = { version = "0.227.0", default-features = false, features = ['simd'] }
wat = "1.227.0"
wast = "227.0.0"
wasmprinter = "0.227.0"
wasm-encoder = "0.227.0"
wasm-smith = "0.227.0"
wasm-mutate = "0.227.0"
wit-parser = "0.227.0"
wit-component = "0.227.0"
wasm-wave = "0.227.0"

# Non-Bytecode Alliance maintained dependencies:
# --------------------------
Expand Down
106 changes: 84 additions & 22 deletions crates/cranelift/src/compiler/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,25 +103,36 @@ impl<'a> TrampolineCompiler<'a> {
Trampoline::ResourceNew(ty) => self.translate_resource_new(*ty),
Trampoline::ResourceRep(ty) => self.translate_resource_rep(*ty),
Trampoline::ResourceDrop(ty) => self.translate_resource_drop(*ty),
Trampoline::TaskBackpressure { instance } => {
self.translate_task_backpressure_call(*instance)
Trampoline::BackpressureSet { instance } => {
self.translate_backpressure_set_call(*instance)
}
Trampoline::TaskReturn { results } => self.translate_task_return_call(*results),
Trampoline::TaskWait {
Trampoline::TaskReturn { results, options } => {
self.translate_task_return_call(*results, options)
}
Trampoline::WaitableSetNew { instance } => self.translate_waitable_set_new(*instance),
Trampoline::WaitableSetWait {
instance,
async_,
memory,
} => {
self.translate_task_wait_or_poll_call(*instance, *async_, *memory, host::task_wait)
}
Trampoline::TaskPoll {
} => self.translate_task_wait_or_poll_call(
*instance,
*async_,
*memory,
host::waitable_set_wait,
),
Trampoline::WaitableSetPoll {
instance,
async_,
memory,
} => {
self.translate_task_wait_or_poll_call(*instance, *async_, *memory, host::task_poll)
}
Trampoline::TaskYield { async_ } => self.translate_task_yield_call(*async_),
} => self.translate_task_wait_or_poll_call(
*instance,
*async_,
*memory,
host::waitable_set_poll,
),
Trampoline::WaitableSetDrop { instance } => self.translate_waitable_set_drop(*instance),
Trampoline::WaitableJoin { instance } => self.translate_waitable_join(*instance),
Trampoline::Yield { async_ } => self.translate_yield_call(*async_),
Trampoline::SubtaskDrop { instance } => self.translate_subtask_drop_call(*instance),
Trampoline::StreamNew { ty } => self.translate_future_or_stream_call(
&[ty.as_u32()],
Expand Down Expand Up @@ -375,7 +386,9 @@ impl<'a> TrampolineCompiler<'a> {
}
}

fn translate_task_return_call(&mut self, results: TypeTupleIndex) {
fn translate_task_return_call(&mut self, results: TypeTupleIndex, options: &CanonicalOptions) {
// FIXME(#10338) shouldn't ignore options here.
let _ = options;
let args = self.builder.func.dfg.block_params(self.block0).to_vec();
let vmctx = args[0];

Expand All @@ -394,6 +407,60 @@ impl<'a> TrampolineCompiler<'a> {
);
}

fn translate_waitable_set_new(&mut self, instance: RuntimeComponentInstanceIndex) {
let args = self.builder.func.dfg.block_params(self.block0).to_vec();
let vmctx = args[0];

let instance = self
.builder
.ins()
.iconst(ir::types::I32, i64::from(instance.as_u32()));

self.translate_intrinsic_libcall(
vmctx,
host::waitable_set_new,
&[vmctx, instance],
TrapSentinel::NegativeOne,
);
}

fn translate_waitable_set_drop(&mut self, instance: RuntimeComponentInstanceIndex) {
let args = self.builder.func.dfg.block_params(self.block0).to_vec();
let vmctx = args[0];
let set = args[2];

let instance = self
.builder
.ins()
.iconst(ir::types::I32, i64::from(instance.as_u32()));

self.translate_intrinsic_libcall(
vmctx,
host::waitable_set_drop,
&[vmctx, instance, set],
TrapSentinel::Falsy,
);
}

fn translate_waitable_join(&mut self, instance: RuntimeComponentInstanceIndex) {
let args = self.builder.func.dfg.block_params(self.block0).to_vec();
let vmctx = args[0];
let set = args[2];
let waitable = args[3];

let instance = self
.builder
.ins()
.iconst(ir::types::I32, i64::from(instance.as_u32()));

self.translate_intrinsic_libcall(
vmctx,
host::waitable_join,
&[vmctx, instance, set, waitable],
TrapSentinel::Falsy,
);
}

fn translate_sync_enter(&mut self) {
match self.abi {
Abi::Wasm => {}
Expand Down Expand Up @@ -534,7 +601,7 @@ impl<'a> TrampolineCompiler<'a> {
self.translate_intrinsic_libcall(vmctx, get_libcall, &callee_args, sentinel);
}

fn translate_task_backpressure_call(&mut self, caller_instance: RuntimeComponentInstanceIndex) {
fn translate_backpressure_set_call(&mut self, caller_instance: RuntimeComponentInstanceIndex) {
let args = self.builder.func.dfg.block_params(self.block0).to_vec();
let vmctx = args[0];

Expand All @@ -549,7 +616,7 @@ impl<'a> TrampolineCompiler<'a> {

self.translate_intrinsic_libcall(
vmctx,
host::task_backpressure,
host::backpressure_set,
&callee_args,
TrapSentinel::Falsy,
);
Expand Down Expand Up @@ -586,7 +653,7 @@ impl<'a> TrampolineCompiler<'a> {
);
}

fn translate_task_yield_call(&mut self, async_: bool) {
fn translate_yield_call(&mut self, async_: bool) {
let args = self.builder.func.dfg.block_params(self.block0).to_vec();
let vmctx = args[0];

Expand All @@ -597,12 +664,7 @@ impl<'a> TrampolineCompiler<'a> {
.iconst(ir::types::I8, if async_ { 1 } else { 0 }),
];

self.translate_intrinsic_libcall(
vmctx,
host::task_yield,
&callee_args,
TrapSentinel::Falsy,
);
self.translate_intrinsic_libcall(vmctx, host::yield_, &callee_args, TrapSentinel::Falsy);
}

fn translate_subtask_drop_call(&mut self, caller_instance: RuntimeComponentInstanceIndex) {
Expand Down
18 changes: 12 additions & 6 deletions crates/environ/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,21 @@ macro_rules! foreach_builtin_component_function {
resource_exit_call(vmctx: vmctx) -> bool;

#[cfg(feature = "component-model-async")]
task_backpressure(vmctx: vmctx, caller_instance: u32, enabled: u32) -> bool;
backpressure_set(vmctx: vmctx, caller_instance: u32, enabled: u32) -> bool;
#[cfg(feature = "component-model-async")]
task_return(vmctx: vmctx, ty: u32, storage: ptr_u8, storage_len: size) -> bool;
#[cfg(feature = "component-model-async")]
task_wait(vmctx: vmctx, caller_instance: u32, async_: u8, memory: ptr_u8, payload: u32) -> u64;
waitable_set_new(vmctx: vmctx, caller_instance: u32) -> u64;
#[cfg(feature = "component-model-async")]
task_poll(vmctx: vmctx, caller_instance: u32, async_: u8, memory: ptr_u8, payload: u32) -> u64;
waitable_set_wait(vmctx: vmctx, caller_instance: u32, set: u32, async_: u8, memory: ptr_u8, payload: u32) -> u64;
#[cfg(feature = "component-model-async")]
task_yield(vmctx: vmctx, async_: u8) -> bool;
waitable_set_poll(vmctx: vmctx, caller_instance: u32, set: u32, async_: u8, memory: ptr_u8, 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")]
yield_(vmctx: vmctx, async_: u8) -> bool;
#[cfg(feature = "component-model-async")]
subtask_drop(vmctx: vmctx, caller_instance: u32, task_id: u32) -> bool;
#[cfg(feature = "component-model-async")]
Expand All @@ -116,7 +122,7 @@ macro_rules! foreach_builtin_component_function {
#[cfg(feature = "component-model-async")]
future_close_writable(vmctx: vmctx, ty: u32, err_ctx_ty: u32, writer: u32, error: u32) -> bool;
#[cfg(feature = "component-model-async")]
future_close_readable(vmctx: vmctx, ty: u32, reader: u32) -> bool;
future_close_readable(vmctx: vmctx, ty: u32, reader: u32, error: u32) -> bool;
#[cfg(feature = "component-model-async")]
stream_new(vmctx: vmctx, ty: u32) -> u64;
#[cfg(feature = "component-model-async")]
Expand All @@ -130,7 +136,7 @@ macro_rules! foreach_builtin_component_function {
#[cfg(feature = "component-model-async")]
stream_close_writable(vmctx: vmctx, ty: u32, err_ctx_ty: u32, writer: u32, error: u32) -> bool;
#[cfg(feature = "component-model-async")]
stream_close_readable(vmctx: vmctx, ty: u32, reader: u32) -> bool;
stream_close_readable(vmctx: vmctx, ty: u32, reader: u32, error: u32) -> bool;
#[cfg(feature = "component-model-async")]
flat_stream_write(vmctx: vmctx, memory: ptr_u8, realloc: ptr_u8, ty: u32, payload_size: u32, payload_align: u32, stream: u32, address: u32, count: u32) -> u64;
#[cfg(feature = "component-model-async")]
Expand Down
46 changes: 33 additions & 13 deletions crates/environ/src/component/dfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,23 +283,33 @@ pub enum Trampoline {
ResourceNew(TypeResourceTableIndex),
ResourceRep(TypeResourceTableIndex),
ResourceDrop(TypeResourceTableIndex),
TaskBackpressure {
BackpressureSet {
instance: RuntimeComponentInstanceIndex,
},
TaskReturn {
results: TypeTupleIndex,
options: CanonicalOptions,
},
WaitableSetNew {
instance: RuntimeComponentInstanceIndex,
},
TaskWait {
WaitableSetWait {
instance: RuntimeComponentInstanceIndex,
async_: bool,
memory: MemoryId,
},
TaskPoll {
WaitableSetPoll {
instance: RuntimeComponentInstanceIndex,
async_: bool,
memory: MemoryId,
},
TaskYield {
WaitableSetDrop {
instance: RuntimeComponentInstanceIndex,
},
WaitableJoin {
instance: RuntimeComponentInstanceIndex,
},
Yield {
async_: bool,
},
SubtaskDrop {
Expand Down Expand Up @@ -772,31 +782,41 @@ impl LinearizeDfg<'_> {
Trampoline::ResourceNew(ty) => info::Trampoline::ResourceNew(*ty),
Trampoline::ResourceDrop(ty) => info::Trampoline::ResourceDrop(*ty),
Trampoline::ResourceRep(ty) => info::Trampoline::ResourceRep(*ty),
Trampoline::TaskBackpressure { instance } => info::Trampoline::TaskBackpressure {
Trampoline::BackpressureSet { instance } => info::Trampoline::BackpressureSet {
instance: *instance,
},
Trampoline::TaskReturn { results } => {
info::Trampoline::TaskReturn { results: *results }
}
Trampoline::TaskWait {
Trampoline::TaskReturn { results, options } => info::Trampoline::TaskReturn {
results: *results,
options: self.options(options),
},
Trampoline::WaitableSetNew { instance } => info::Trampoline::WaitableSetNew {
instance: *instance,
},
Trampoline::WaitableSetWait {
instance,
async_,
memory,
} => info::Trampoline::TaskWait {
} => info::Trampoline::WaitableSetWait {
instance: *instance,
async_: *async_,
memory: self.runtime_memory(*memory),
},
Trampoline::TaskPoll {
Trampoline::WaitableSetPoll {
instance,
async_,
memory,
} => info::Trampoline::TaskPoll {
} => info::Trampoline::WaitableSetPoll {
instance: *instance,
async_: *async_,
memory: self.runtime_memory(*memory),
},
Trampoline::TaskYield { async_ } => info::Trampoline::TaskYield { async_: *async_ },
Trampoline::WaitableSetDrop { instance } => info::Trampoline::WaitableSetDrop {
instance: *instance,
},
Trampoline::WaitableJoin { instance } => info::Trampoline::WaitableJoin {
instance: *instance,
},
Trampoline::Yield { async_ } => info::Trampoline::Yield { async_: *async_ },
Trampoline::SubtaskDrop { instance } => info::Trampoline::SubtaskDrop {
instance: *instance,
},
Expand Down
Loading