Skip to content

Commit 908ea1f

Browse files
committed
Stack switching squashed base commit
1 parent 25d5c99 commit 908ea1f

File tree

101 files changed

+9571
-290
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+9571
-290
lines changed

Diff for: Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ default = [
426426
"gc",
427427
"gc-drc",
428428
"gc-null",
429+
"stack-switching",
429430
"winch",
430431
"pulley",
431432

@@ -483,6 +484,7 @@ gc = ["wasmtime-cli-flags/gc", "wasmtime/gc"]
483484
gc-drc = ["gc", "wasmtime/gc-drc", "wasmtime-cli-flags/gc-drc"]
484485
gc-null = ["gc", "wasmtime/gc-null", "wasmtime-cli-flags/gc-null"]
485486
pulley = ["wasmtime-cli-flags/pulley"]
487+
stack-switching = ["wasmtime/stack-switching", "wasmtime-cli-flags/stack-switching"]
486488

487489
# CLI subcommands for the `wasmtime` executable. See `wasmtime $cmd --help`
488490
# for more information on each subcommand.

Diff for: cranelift/codegen/src/ir/function.rs

+7
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,13 @@ impl FunctionStencil {
255255
self.get_dyn_scale(dyn_ty)
256256
}
257257

258+
/// Find the data for the given stack slot
259+
pub fn get_stack_slot_data(&self, stack_slot: StackSlot) -> &StackSlotData {
260+
self.sized_stack_slots
261+
.get(stack_slot)
262+
.expect("undeclared stack slot: {stack_slot}")
263+
}
264+
258265
/// Get a concrete `Type` from a user defined `DynamicType`.
259266
pub fn get_concrete_dynamic_ty(&self, ty: DynamicType) -> Option<Type> {
260267
self.dfg

Diff for: cranelift/codegen/src/isa/x64/abi.rs

+7
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ impl ABIMachineSpec for X64ABIMachineSpec {
104104
mut args: ArgsAccumulator,
105105
) -> CodegenResult<(u32, Option<usize>)> {
106106
let is_fastcall = call_conv == CallConv::WindowsFastcall;
107+
let is_tail = call_conv == CallConv::Tail;
107108

108109
let mut next_gpr = 0;
109110
let mut next_vreg = 0;
@@ -182,6 +183,11 @@ impl ABIMachineSpec for X64ABIMachineSpec {
182183
// This is consistent with LLVM's behavior, and is needed for
183184
// some uses of Cranelift (e.g., the rustc backend).
184185
//
186+
// - Otherwise, if the calling convention is Tail, we behave as in
187+
// the previous case, even if `enable_llvm_abi_extensions` is not
188+
// set in the flags: This is a custom calling convention defined
189+
// by Cranelift, LLVM doesn't know about it.
190+
//
185191
// - Otherwise, both SysV and Fastcall specify behavior (use of
186192
// vector register, a register pair, or passing by reference
187193
// depending on the case), but for simplicity, we will just panic if
@@ -195,6 +201,7 @@ impl ABIMachineSpec for X64ABIMachineSpec {
195201
if param.value_type.bits() > 64
196202
&& !(param.value_type.is_vector() || param.value_type.is_float())
197203
&& !flags.enable_llvm_abi_extensions()
204+
&& !is_tail
198205
{
199206
panic!(
200207
"i128 args/return values not supported unless LLVM ABI extensions are enabled"

Diff for: crates/c-api/include/wasmtime/config.h

+16
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,22 @@ WASMTIME_CONFIG_PROP(void, wasm_wide_arithmetic, bool)
250250

251251
#ifdef WASMTIME_FEATURE_COMPILER
252252

253+
/**
254+
* \brief Configures whether the WebAssembly function references
255+
* proposal is enabled.
256+
*
257+
* This setting is `false` by default.
258+
*/
259+
WASMTIME_CONFIG_PROP(void, wasm_function_references, bool)
260+
261+
/**
262+
* \brief Configures whether the WebAssembly stack switching
263+
* proposal is enabled.
264+
*
265+
* This setting is `false` by default.
266+
*/
267+
WASMTIME_CONFIG_PROP(void, wasm_stack_switching, bool)
268+
253269
/**
254270
* \brief Configures how JIT code will be compiled.
255271
*

Diff for: crates/c-api/include/wasmtime/linker.h

+10
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@ WASM_API_EXTERN void wasmtime_linker_delete(wasmtime_linker_t *linker);
6666
WASM_API_EXTERN void wasmtime_linker_allow_shadowing(wasmtime_linker_t *linker,
6767
bool allow_shadowing);
6868

69+
/**
70+
* \brief Configures whether the given Linker will allow unknown exports from
71+
* command modules.
72+
*
73+
* By default this setting is `false`.
74+
*/
75+
WASM_API_EXTERN void
76+
wasmtime_linker_allow_unknown_exports(wasmtime_linker_t *linker,
77+
bool allow_unknown_exports);
78+
6979
/**
7080
* \brief Defines a new item in this linker.
7181
*

Diff for: crates/c-api/src/config.rs

+4
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ pub extern "C" fn wasmtime_config_wasm_memory64_set(c: &mut wasm_config_t, enabl
137137
}
138138

139139
#[unsafe(no_mangle)]
140+
pub extern "C" fn wasmtime_config_wasm_stack_switching_set(c: &mut wasm_config_t, enable: bool) {
141+
c.config.wasm_stack_switching(enable);
142+
}
143+
140144
#[cfg(any(feature = "cranelift", feature = "winch"))]
141145
pub extern "C" fn wasmtime_config_strategy_set(
142146
c: &mut wasm_config_t,

Diff for: crates/cli-flags/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@ gc-null = ["gc", "wasmtime/gc-null"]
4040
threads = ["wasmtime/threads"]
4141
memory-protection-keys = ["wasmtime/memory-protection-keys"]
4242
pulley = ["wasmtime/pulley"]
43+
stack-switching = ["wasmtime/stack-switching"]

Diff for: crates/cli-flags/src/lib.rs

+17
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,8 @@ wasmtime_option_group! {
331331
pub trap_on_grow_failure: Option<bool>,
332332
/// Maximum execution time of wasm code before timing out (1, 2s, 100ms, etc)
333333
pub timeout: Option<Duration>,
334+
/// Size of stacks created with cont.new instructions
335+
pub stack_switching_stack_size: Option<usize>,
334336
/// Configures support for all WebAssembly proposals implemented.
335337
pub all_proposals: Option<bool>,
336338
/// Configure support for the bulk memory proposal.
@@ -366,6 +368,8 @@ wasmtime_option_group! {
366368
pub component_model_async: Option<bool>,
367369
/// Configure support for the function-references proposal.
368370
pub function_references: Option<bool>,
371+
/// Configure support for the stack-switching proposal.
372+
pub stack_switching: Option<bool>,
369373
/// Configure support for the GC proposal.
370374
pub gc: Option<bool>,
371375
/// Configure support for the custom-page-sizes proposal.
@@ -801,6 +805,12 @@ impl CommonOptions {
801805
config.native_unwind_info(enable);
802806
}
803807

808+
match_feature! {
809+
["stack-switching" : self.wasm.stack_switching_stack_size]
810+
size => config.stack_switching_stack_size(size),
811+
_ => err,
812+
}
813+
804814
match_feature! {
805815
["pooling-allocator" : self.opts.pooling_allocator.or(pooling_allocator_default)]
806816
enable => {
@@ -962,6 +972,9 @@ impl CommonOptions {
962972
if let Some(enable) = self.wasm.memory64.or(all) {
963973
config.wasm_memory64(enable);
964974
}
975+
if let Some(enable) = self.wasm.stack_switching {
976+
config.wasm_stack_switching(enable);
977+
}
965978
if let Some(enable) = self.wasm.custom_page_sizes.or(all) {
966979
config.wasm_custom_page_sizes(enable);
967980
}
@@ -992,6 +1005,10 @@ impl CommonOptions {
9921005
("gc", gc, wasm_gc)
9931006
("gc", reference_types, wasm_reference_types)
9941007
("gc", function_references, wasm_function_references)
1008+
// FIXME(frank-emrich): If function-references depends on the gc
1009+
// feature, and stack-switching requires function-references, that
1010+
// probably means that stack-switching should depend on gc.
1011+
("stack-switching", stack_switching, wasm_stack_switching)
9951012
}
9961013
Ok(())
9971014
}

0 commit comments

Comments
 (0)