Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for stack switching proposal #10177

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ default = [
"gc",
"gc-drc",
"gc-null",
"stack-switching",
"winch",
"pulley",

Expand Down Expand Up @@ -489,6 +490,7 @@ gc = ["wasmtime-cli-flags/gc", "wasmtime/gc"]
gc-drc = ["gc", "wasmtime/gc-drc", "wasmtime-cli-flags/gc-drc"]
gc-null = ["gc", "wasmtime/gc-null", "wasmtime-cli-flags/gc-null"]
pulley = ["wasmtime-cli-flags/pulley"]
stack-switching = ["wasmtime/stack-switching", "wasmtime-cli-flags/stack-switching"]

# CLI subcommands for the `wasmtime` executable. See `wasmtime $cmd --help`
# for more information on each subcommand.
Expand Down
7 changes: 7 additions & 0 deletions cranelift/codegen/src/ir/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,13 @@ impl FunctionStencil {
self.get_dyn_scale(dyn_ty)
}

/// Find the data for the given stack slot
pub fn get_stack_slot_data(&self, stack_slot: StackSlot) -> &StackSlotData {
self.sized_stack_slots
.get(stack_slot)
.expect("undeclared stack slot: {stack_slot}")
}

/// Get a concrete `Type` from a user defined `DynamicType`.
pub fn get_concrete_dynamic_ty(&self, ty: DynamicType) -> Option<Type> {
self.dfg
Expand Down
7 changes: 7 additions & 0 deletions cranelift/codegen/src/isa/x64/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ impl ABIMachineSpec for X64ABIMachineSpec {
mut args: ArgsAccumulator,
) -> CodegenResult<(u32, Option<usize>)> {
let is_fastcall = call_conv == CallConv::WindowsFastcall;
let is_tail = call_conv == CallConv::Tail;

let mut next_gpr = 0;
let mut next_vreg = 0;
Expand Down Expand Up @@ -182,6 +183,11 @@ impl ABIMachineSpec for X64ABIMachineSpec {
// This is consistent with LLVM's behavior, and is needed for
// some uses of Cranelift (e.g., the rustc backend).
//
// - Otherwise, if the calling convention is Tail, we behave as in
// the previous case, even if `enable_llvm_abi_extensions` is not
// set in the flags: This is a custom calling convention defined
// by Cranelift, LLVM doesn't know about it.
//
// - Otherwise, both SysV and Fastcall specify behavior (use of
// vector register, a register pair, or passing by reference
// depending on the case), but for simplicity, we will just panic if
Expand All @@ -195,6 +201,7 @@ impl ABIMachineSpec for X64ABIMachineSpec {
if param.value_type.bits() > 64
&& !(param.value_type.is_vector() || param.value_type.is_float())
&& !flags.enable_llvm_abi_extensions()
&& !is_tail
{
panic!(
"i128 args/return values not supported unless LLVM ABI extensions are enabled"
Expand Down
16 changes: 16 additions & 0 deletions crates/c-api/include/wasmtime/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,22 @@ WASMTIME_CONFIG_PROP(void, wasm_wide_arithmetic, bool)

#ifdef WASMTIME_FEATURE_COMPILER

/**
* \brief Configures whether the WebAssembly function references
* proposal is enabled.
*
* This setting is `false` by default.
*/
WASMTIME_CONFIG_PROP(void, wasm_function_references, bool)

/**
* \brief Configures whether the WebAssembly stack switching
* proposal is enabled.
*
* This setting is `false` by default.
*/
WASMTIME_CONFIG_PROP(void, wasm_stack_switching, bool)

/**
* \brief Configures how JIT code will be compiled.
*
Expand Down
10 changes: 10 additions & 0 deletions crates/c-api/include/wasmtime/linker.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ WASM_API_EXTERN void wasmtime_linker_delete(wasmtime_linker_t *linker);
WASM_API_EXTERN void wasmtime_linker_allow_shadowing(wasmtime_linker_t *linker,
bool allow_shadowing);

/**
* \brief Configures whether the given Linker will allow unknown exports from
* command modules.
*
* By default this setting is `false`.
*/
WASM_API_EXTERN void
wasmtime_linker_allow_unknown_exports(wasmtime_linker_t *linker,
bool allow_unknown_exports);

/**
* \brief Defines a new item in this linker.
*
Expand Down
4 changes: 4 additions & 0 deletions crates/c-api/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ pub extern "C" fn wasmtime_config_wasm_memory64_set(c: &mut wasm_config_t, enabl
}

#[unsafe(no_mangle)]
pub extern "C" fn wasmtime_config_wasm_stack_switching_set(c: &mut wasm_config_t, enable: bool) {
c.config.wasm_stack_switching(enable);
}

#[cfg(any(feature = "cranelift", feature = "winch"))]
pub extern "C" fn wasmtime_config_strategy_set(
c: &mut wasm_config_t,
Expand Down
1 change: 1 addition & 0 deletions crates/cli-flags/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ gc-null = ["gc", "wasmtime/gc-null"]
threads = ["wasmtime/threads"]
memory-protection-keys = ["wasmtime/memory-protection-keys"]
pulley = ["wasmtime/pulley"]
stack-switching = ["wasmtime/stack-switching"]
14 changes: 14 additions & 0 deletions crates/cli-flags/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,8 @@ wasmtime_option_group! {
pub trap_on_grow_failure: Option<bool>,
/// Maximum execution time of wasm code before timing out (1, 2s, 100ms, etc)
pub timeout: Option<Duration>,
/// Size of stacks created with cont.new instructions
pub stack_switching_stack_size: Option<usize>,
/// Configures support for all WebAssembly proposals implemented.
pub all_proposals: Option<bool>,
/// Configure support for the bulk memory proposal.
Expand Down Expand Up @@ -366,6 +368,8 @@ wasmtime_option_group! {
pub component_model_async: Option<bool>,
/// Configure support for the function-references proposal.
pub function_references: Option<bool>,
/// Configure support for the stack-switching proposal.
pub stack_switching: Option<bool>,
/// Configure support for the GC proposal.
pub gc: Option<bool>,
/// Configure support for the custom-page-sizes proposal.
Expand Down Expand Up @@ -803,6 +807,12 @@ impl CommonOptions {
config.native_unwind_info(enable);
}

match_feature! {
["stack-switching" : self.wasm.stack_switching_stack_size]
size => config.stack_switching_stack_size(size),
_ => err,
}

match_feature! {
["pooling-allocator" : self.opts.pooling_allocator.or(pooling_allocator_default)]
enable => {
Expand Down Expand Up @@ -964,6 +974,9 @@ impl CommonOptions {
if let Some(enable) = self.wasm.memory64.or(all) {
config.wasm_memory64(enable);
}
if let Some(enable) = self.wasm.stack_switching {
config.wasm_stack_switching(enable);
}
if let Some(enable) = self.wasm.custom_page_sizes.or(all) {
config.wasm_custom_page_sizes(enable);
}
Expand Down Expand Up @@ -994,6 +1007,7 @@ impl CommonOptions {
("gc", gc, wasm_gc)
("gc", reference_types, wasm_reference_types)
("gc", function_references, wasm_function_references)
("stack-switching", stack_switching, wasm_stack_switching)
}
Ok(())
}
Expand Down
Loading
Loading