Skip to content

WIP: replace register-alloc with purely stack-based translation #1512

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

Draft
wants to merge 338 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
338 commits
Select commit Hold shift + click to select a range
7aafcfc
implement some visit methods
Robbepop Jun 5, 2025
a23eb27
apply clippy suggestion
Robbepop Jun 6, 2025
cc8c0fa
refactor ControlFrame
Robbepop Jun 6, 2025
773e4f1
implemented visit_end as stub
Robbepop Jun 6, 2025
ba45fa4
remove unused ControlFrame::is_branched_to method
Robbepop Jun 6, 2025
26107e1
differentiate between func enclosing block in translation
Robbepop Jun 7, 2025
e8c438f
initial impl for translate_end_func
Robbepop Jun 7, 2025
28f25b4
implement translate_end_func method
Robbepop Jun 7, 2025
bfb93ed
unsilence unused_variables warning and fix occurrences
Robbepop Jun 7, 2025
98cf750
simplify translate_end_func when in unreachable state
Robbepop Jun 7, 2025
e38e78b
unsilence and fix occurrences of unused_imports
Robbepop Jun 7, 2025
d68d2f4
add Stack::peek_control
Robbepop Jun 8, 2025
eed2cfc
add InstrEncoder::{get_mut, bump_fuel_consumption} methods
Robbepop Jun 8, 2025
474ee4c
refactor tranlate_end_func
Robbepop Jun 8, 2025
12e74f5
add ControlFrame::len_branch_params
Robbepop Jun 9, 2025
8ca5123
refactor and simplify translate_end
Robbepop Jun 9, 2025
6b908e4
format the code in a more readable way
Robbepop Jun 9, 2025
0feb63f
no longer pop operands in translate_return
Robbepop Jun 9, 2025
594a856
trunc operands in translate_end_block
Robbepop Jun 9, 2025
a0f45d5
fix Stack::trunc method
Robbepop Jun 9, 2025
d7ebd28
no longer manipulate stack in copy_operand[s]_to_temp methods
Robbepop Jun 9, 2025
119310f
move trivial match arm to top
Robbepop Jun 9, 2025
71e9457
refactor FuncTranslator::is_fuel_metering_enabled
Robbepop Jun 9, 2025
abd129a
return Operand in Stack::operator_to_temp
Robbepop Jun 9, 2025
7600fc0
refactor new translator
Robbepop Jun 9, 2025
e90f33a
move into_allocations method higher in file
Robbepop Jun 9, 2025
ccd60e7
fix intra doc link
Robbepop Jun 9, 2025
d5abbd6
add experimental-translator crate feature to wasmi_wast crate
Robbepop Jun 9, 2025
7d61056
properly update reachability in translate_end_block
Robbepop Jun 9, 2025
12e6630
implement translate_end_loop
Robbepop Jun 9, 2025
3b719ba
add ReusableAllocations trait
Robbepop Jun 11, 2025
e187591
add InstrEncoderAllocations
Robbepop Jun 11, 2025
06d01a2
add fuel_costs to InstrEncoder
Robbepop Jun 11, 2025
3b49f25
make full use of the new ReusableAllocations trait
Robbepop Jun 11, 2025
6f5b6b6
add InstrEncoder::push_consume_fuel_instr
Robbepop Jun 11, 2025
5923186
add Stack::consume_fuel_instr getter
Robbepop Jun 11, 2025
42c19f8
apply rustfmt
Robbepop Jun 11, 2025
4231293
add fuel metering support to InstrEncoder APIs
Robbepop Jun 11, 2025
5c99004
make InstrEncoder aware if fuel metering is enabled
Robbepop Jun 11, 2025
32dbe4f
add FuncTranslator::pin_label utility method
Robbepop Jun 11, 2025
3809414
refactor Stack::push_loop
Robbepop Jun 11, 2025
9b089d1
improve and update docs
Robbepop Jun 11, 2025
a342744
remove debug println
Robbepop Jun 11, 2025
77508a1
add StackOperand::ty getter method
Robbepop Jun 11, 2025
42a5253
refactor and fix OperandStack::operand_to_temp_at method
Robbepop Jun 11, 2025
5eeaedf
implement FuncTranslator::visit_block trait method
Robbepop Jun 11, 2025
dcfb843
implement FuncTranslator::visit_loop trait method
Robbepop Jun 11, 2025
d6f3f07
reorder exports
Robbepop Jun 12, 2025
dd04341
push else operands only for IfReachability::Both
Robbepop Jun 12, 2025
95f5c35
start implementation of FuncTranslator::visit_if
Robbepop Jun 12, 2025
107cbee
convert condition operand to Reg
Robbepop Jun 13, 2025
9d6f383
fix some internal doc links
Robbepop Jun 14, 2025
819c4f7
make InstrEncoder::get_mut private
Robbepop Jun 14, 2025
a889514
fix compile error
Robbepop Jun 14, 2025
3f25bb1
silence warnings temporarily for visit_if
Robbepop Jun 15, 2025
a10e1db
remove Reset impl for InstrEncoder
Robbepop Jun 15, 2025
5ba6253
add last_instr field to InstrEncoder
Robbepop Jun 15, 2025
97fe4cf
add (debug) asserts for is_instruction_parameter
Robbepop Jun 15, 2025
3702c30
add AllocConst impl for StackLayout
Robbepop Jun 15, 2025
d2f7b64
add InstrEncoder::try_replace_instr method
Robbepop Jun 15, 2025
da4c301
implement translate_br_if variants + fusion
Robbepop Jun 15, 2025
afca602
implement visit_if
Robbepop Jun 15, 2025
8848d7f
fix bug in translate_br_if fallback
Robbepop Jun 15, 2025
222441b
reorder exports
Robbepop Jun 16, 2025
093ed53
fix imports in func2 translator
Robbepop Jun 16, 2025
6e1bfd4
cfg-guard func and func2 modules
Robbepop Jun 16, 2025
95a3eba
silence warnings instead of conditionally compile func module
Robbepop Jun 17, 2025
7d395df
implement translate_br
Robbepop Jun 17, 2025
41d4b85
refactor Stack::push_else method
Robbepop Jun 17, 2025
33fe300
implement FuncTranslator::visit_else
Robbepop Jun 17, 2025
5d4a565
implement FuncTranslator::visit_nop
Robbepop Jun 17, 2025
8a4a60c
implement FuncTranslator::visit_unreachable
Robbepop Jun 17, 2025
1a6f1a0
implement FuncTranslator::end_unreachable
Robbepop Jun 17, 2025
b3f3158
add StackHeight utility type
Robbepop Jun 17, 2025
5f10063
put debug_assert to various translate_end_* methods
Robbepop Jun 20, 2025
a5c4cc3
improve ControlStack::pop docs
Robbepop Jun 20, 2025
2a0a3ea
rename UnreachableControlFrame -> ControlFrameKind
Robbepop Jun 20, 2025
deecddc
pop else operands only when available
Robbepop Jun 20, 2025
d5bab0c
drop else operands when possible
Robbepop Jun 20, 2025
bccd1d7
pull let binding into if's then block
Robbepop Jun 20, 2025
462726c
implement translate_end_if
Robbepop Jun 20, 2025
e52da65
add and use ControlFrameBase trait
Robbepop Jun 20, 2025
4227cf0
use ControlFrameBase to generalize end_if translation
Robbepop Jun 20, 2025
b55c0f1
fix translate_end_if label pinning
Robbepop Jun 20, 2025
d5e6a87
implement translate_end_else
Robbepop Jun 20, 2025
5afeb60
fix pinning of the else_label
Robbepop Jun 20, 2025
2689675
implement FuncTranslator::visit_return
Robbepop Jun 20, 2025
1e7178b
rename translate_return -> encode_return
Robbepop Jun 20, 2025
aa6456f
make ControlStack::get_mut return ControlFrameMut wrapper
Robbepop Jun 22, 2025
c7a379b
add Stack::acquire_target method
Robbepop Jun 22, 2025
971f41d
rename acquire_target -> peek_control_mut + docs
Robbepop Jun 23, 2025
58b5f5a
apply rustfmt
Robbepop Jun 23, 2025
55a50eb
rename some FuncTranslator helper methods
Robbepop Jun 23, 2025
73bcb3c
fix after renamings
Robbepop Jun 23, 2025
7564855
implement FuncTranslator::visit_br
Robbepop Jun 23, 2025
5732bbd
add ty and height methods to ControlFrameBase trait
Robbepop Jun 23, 2025
8256ed9
implement FuncTranslator::visit_br_if method
Robbepop Jun 23, 2025
2c6c530
implement FuncTranslator::visit_drop method
Robbepop Jun 23, 2025
9eabfe6
translate all commitative binary Wasm operators
Robbepop Jun 24, 2025
32ea09c
apply clippy suggestions
Robbepop Jun 24, 2025
d76ae07
add translation for i{32,64} unary operators
Robbepop Jun 24, 2025
fc64313
add FuncTranslator::push_instr_with_result utility
Robbepop Jun 24, 2025
19867c9
add translate_trap utility method
Robbepop Jun 24, 2025
c3e88a6
add missing import
Robbepop Jun 24, 2025
7b56c9b
remove no longer import
Robbepop Jun 25, 2025
571a02c
add Operand16 type and make_imm16 utility
Robbepop Jun 25, 2025
3f9a81b
fix translate_trap not respecting its trap parameter
Robbepop Jun 25, 2025
ae86985
implement i{32,64}_{div,rem}_{s,u} translations
Robbepop Jun 25, 2025
34f3803
simplify translate_divrem generic params
Robbepop Jun 25, 2025
b885d36
add missing docs
Robbepop Jun 25, 2025
7cd54f5
add tranlate_binary_consteval* helpers
Robbepop Jun 30, 2025
d165368
implement visit_{i64,f32,f64}_const trait methods
Robbepop Jun 30, 2025
5341a07
improve hygiene of bail_unreachable macro
Robbepop Jun 30, 2025
d817865
add swap_ops utility macro
Robbepop Jun 30, 2025
9a25bb8
impl i{32,64} comparison translation
Robbepop Jun 30, 2025
139de47
double-brace swap_ops macro expansion
Robbepop Jun 30, 2025
f7531f6
refactor WasmInteger trait
Robbepop Jul 1, 2025
1f3bd37
implement shift and rotate translation
Robbepop Jul 2, 2025
c116b0f
remove unnecessary .into() call
Robbepop Jul 2, 2025
12e1f78
apply clippy suggestion
Robbepop Jul 2, 2025
54f6cbd
impl unary f{32,64} translation
Robbepop Jul 2, 2025
a641c49
remove unnecessary generic params
Robbepop Jul 2, 2025
8d871bd
remove unnecessary generic params (2)
Robbepop Jul 2, 2025
7f39a2c
impl translation for fallible f2i conversions
Robbepop Jul 2, 2025
a37e32d
impl more conversion translations
Robbepop Jul 2, 2025
bb34ea9
initial i64.extend_i32_u translation
Robbepop Jul 2, 2025
63f8675
apply rustfmt
Robbepop Jul 2, 2025
006566f
impl i2f conversion instruction translation
Robbepop Jul 2, 2025
336ebe3
impl promote and demote instruction translation
Robbepop Jul 2, 2025
ea6c509
add translate_reinterpret helper method
Robbepop Jul 3, 2025
6956d46
implement Wasm reinterpret operators translation
Robbepop Jul 3, 2025
3f1e6c1
remove superflous generic parameters
Robbepop Jul 3, 2025
8b720ba
implement i{32,64}_extend{8,16,32}_s translation
Robbepop Jul 3, 2025
c295777
impl trunc-sat instruction translation
Robbepop Jul 3, 2025
fc6589c
add Typed supertrait to WasmFloat trait
Robbepop Jul 4, 2025
18883bf
implement f{32,64} comparison translation
Robbepop Jul 4, 2025
f6fb521
apply clippy suggestions for more explicit lifetimes
Robbepop Jul 4, 2025
b163e7a
implement most of binary float instruction translation
Robbepop Jul 4, 2025
3e33600
renaming match bindings
Robbepop Jul 4, 2025
b35d018
add From impls for Operand
Robbepop Jul 4, 2025
39f5981
add make_copy_imm_instr utility method
Robbepop Jul 5, 2025
7c4516f
add local.{set,tee} translation
Robbepop Jul 5, 2025
bf1edba
dedup code with new push_binary_instr_with_result utility
Robbepop Jul 5, 2025
b8c1f57
update doc (clippy)
Robbepop Jul 5, 2025
9f79c5e
add WasmInteger::wrapping_neg trait method
Robbepop Jul 5, 2025
de31929
add i{32,64}.sub operators translation
Robbepop Jul 5, 2025
c9baeeb
fix i{32,64}.{and,or,xor} translation
Robbepop Jul 5, 2025
e0dfb64
fix OperandStack::peek yielding too many operands
Robbepop Jul 5, 2025
d562c7f
apply rustfmt
Robbepop Jul 5, 2025
b8aef2d
cfg-guard WasmInteger::wrapping_neg
Robbepop Jul 5, 2025
e99c7e4
add TODO comment to remove cfg-guard
Robbepop Jul 5, 2025
d0e4c36
add f{32,64}.copysign operators translation
Robbepop Jul 5, 2025
48d5f61
replace Operand::[partial_]eq with Operand::is_same
Robbepop Jul 7, 2025
baf9b2f
add translation for Wasm select instructions
Robbepop Jul 7, 2025
0a3e30c
add InstrEncoder::last_instr getter
Robbepop Jul 8, 2025
52d60c2
add fuse_eqz and fuse_nez methods
Robbepop Jul 8, 2025
f1d1360
support custom opts in translation of commutative binary ops
Robbepop Jul 8, 2025
5bc4a8c
add Stack::pop_n method
Robbepop Jul 9, 2025
85d2454
refactor copy_operands_to_temp
Robbepop Jul 9, 2025
c9fd965
make push_instr return the pushed Instr
Robbepop Jul 9, 2025
7976666
extend encode_return with ReturnReg{2,3} support
Robbepop Jul 9, 2025
a60f6d4
make use of copy_operands_to_temp return value
Robbepop Jul 9, 2025
86d86fc
add FuncTranslator::{resolve_func_type[_with]} methods
Robbepop Jul 9, 2025
eec3540
add temporary buffer for Operands to FuncTranslator
Robbepop Jul 9, 2025
af80cc2
initial support for call instruction translation
Robbepop Jul 9, 2025
1cfd63c
add Stack::peek{2,3} methods
Robbepop Jul 9, 2025
58a9454
fix translate_reinterpret types
Robbepop Jul 9, 2025
6265846
fix return type of translate_binary
Robbepop Jul 9, 2025
bca23ca
account for bit-{and,or,xor} in try_fuse_branch_cmp debug_assert
Robbepop Jul 9, 2025
6838693
avoid copies if the stack already forms a RegSpan
Robbepop Jul 9, 2025
73d8e61
implement return_call translation
Robbepop Jul 9, 2025
864d0ec
add IndexType::ty conversion method
Robbepop Jul 10, 2025
8101070
add FuncTranslator::make_index16 utility method
Robbepop Jul 10, 2025
05ea309
implement return_call[_indirect] translation
Robbepop Jul 10, 2025
857ea8d
add global.get translation
Robbepop Jul 10, 2025
832e19f
add global.set translation
Robbepop Jul 10, 2025
7a4761b
fix copy_branch_params call in visit_br
Robbepop Jul 10, 2025
9973c9a
update branch offsets upon finishing translation
Robbepop Jul 10, 2025
7c08da7
add result_ty to push_binary_instr_with_result method
Robbepop Jul 10, 2025
19be57d
remove commented out line of code
Robbepop Jul 10, 2025
a29a329
fix return value of requires_branch_param_copies
Robbepop Jul 11, 2025
9288f63
add missing bail_unreachable to visit[_return]_call_indirect
Robbepop Jul 11, 2025
bf310da
fix calculation of frame_size in FuncTranslator::finish
Robbepop Jul 11, 2025
650c973
fix branch from end of `then` to end of `if`
Robbepop Jul 11, 2025
c368303
move encode_register_list to InstrEncoder
Robbepop Jul 12, 2025
7d86d9a
add Stack::peek_n method
Robbepop Jul 12, 2025
19538ac
add new copy_branch_params implementation (v2)
Robbepop Jul 12, 2025
b429a6e
add BlockType::func_type_with
Robbepop Jul 14, 2025
6919213
add FuncTranslator::push_frame_results utility method
Robbepop Jul 14, 2025
ab84177
apply rustfmt
Robbepop Jul 14, 2025
9bc1d10
remove unused import
Robbepop Jul 14, 2025
13f2e79
silence warnings for non-(experimental-translator) builds
Robbepop Jul 14, 2025
8def063
add TODO annotation for later removal
Robbepop Jul 14, 2025
b8bbd44
add frame_results_impl API to fix borrow issues
Robbepop Jul 14, 2025
d84cfa2
make conditionals a bit more readable
Robbepop Jul 14, 2025
a923877
use new copy_branch_params_v2 API
Robbepop Jul 14, 2025
3103a2a
fix bugs with push_frame_results usage
Robbepop Jul 14, 2025
8e51861
fix reachability of divergent ifs
Robbepop Jul 14, 2025
1375f2b
apply clippy suggestion
Robbepop Jul 14, 2025
fb512fe
use new copy_branch_params_v2 API
Robbepop Jul 14, 2025
f03fcc8
rename and re-doc copy_branch_params API
Robbepop Jul 14, 2025
cffcb70
remove _v2 suffix from copy_branch_params_v2
Robbepop Jul 14, 2025
872df4b
make new FuncTranslator encode ReturnMany
Robbepop Jul 14, 2025
f2ba04a
remove now unused API
Robbepop Jul 14, 2025
33f53f3
remove some unused APIs
Robbepop Jul 14, 2025
250f213
add immediates buffer to FuncTranslator
Robbepop Jul 15, 2025
a0cffac
add try_form_regspan_or_move utility method
Robbepop Jul 15, 2025
68f20c5
remove invalid debug assertions in push_param
Robbepop Jul 15, 2025
e77d2fa
implement br_table translation
Robbepop Jul 15, 2025
54dbdda
add codegen for reinterpretation with local operands
Robbepop Jul 15, 2025
a04f856
add ref.{func,null,is_null} operands translation
Robbepop Jul 15, 2025
4b4f60b
fix frame_size calculation
Robbepop Jul 15, 2025
76fc886
simplify frame_size calculation
Robbepop Jul 16, 2025
44e8340
implement translation of Wasm load operators
Robbepop Jul 16, 2025
a2fa548
implement Wasm integer store operators translation
Robbepop Jul 16, 2025
f8403d4
implement translation for storing f{32,64} types
Robbepop Jul 16, 2025
ebd6579
consider function local constants in frame size calculation
Robbepop Jul 16, 2025
aa6f650
put frame_size calculation into its own method
Robbepop Jul 16, 2025
0945419
apply rustfmt
Robbepop Jul 16, 2025
75c5f5b
add memory.size operator translation
Robbepop Jul 16, 2025
00c229f
add memory.grow operator translation
Robbepop Jul 16, 2025
4eae0f0
assert that cmp+branch fusion succeed at the end
Robbepop Jul 17, 2025
70a4f96
fix panic in try_fuse_branch_cmp
Robbepop Jul 17, 2025
f742643
deduplicate fuse_nez and fuze_eqz implementations
Robbepop Jul 17, 2025
a3ec2ab
fix translation of `if` with return values and no `else`
Robbepop Jul 17, 2025
f879f35
add OperandStack::push_operand
Robbepop Jul 18, 2025
0bee663
refactor Stack `else` operands API
Robbepop Jul 18, 2025
00f9ca6
rename `else` operands API methods
Robbepop Jul 18, 2025
daa5878
remove unnecessary IfControlFrame APIs
Robbepop Jul 18, 2025
cb81cbd
remove misplaced stack.trunc call
Robbepop Jul 18, 2025
b6408e6
refactor how else operands are handled
Robbepop Jul 18, 2025
3d19f46
add FuncTranslator::push_param convenience method
Robbepop Jul 18, 2025
c1d88f6
add FuncTranslator::make_operand16 utility method
Robbepop Jul 18, 2025
073b7da
add Wasm memory.init translation
Robbepop Jul 18, 2025
4cf72be
add Wasm data.drop translation
Robbepop Jul 18, 2025
b498674
rename Operand16 -> Input16
Robbepop Jul 18, 2025
da2d025
add make_input utility method
Robbepop Jul 18, 2025
de5055b
add Wasm memory.copy translation
Robbepop Jul 18, 2025
aefc644
add Wasm memory.fill translation
Robbepop Jul 18, 2025
4dc0d19
fix broken intra doc link
Robbepop Jul 18, 2025
36c1e24
add FuncTranslator::make_index32 utility
Robbepop Jul 18, 2025
26f8820
add Wasm table.init translation
Robbepop Jul 18, 2025
49b8b8c
add Wasm elem.drop translation
Robbepop Jul 18, 2025
676cf9a
add Wasm table.copy translation
Robbepop Jul 18, 2025
ffb1f3a
add Wasm table.fill translation
Robbepop Jul 18, 2025
b4e6e8c
add Wasm table.get translation
Robbepop Jul 18, 2025
40fdbc0
add Wasm table.set translation
Robbepop Jul 18, 2025
cb91c48
add Wasm table.grow translation
Robbepop Jul 18, 2025
79b10e1
add Wasm table.size translation
Robbepop Jul 18, 2025
6e42252
add wide-arithmetic operators translation
Robbepop Jul 18, 2025
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
10 changes: 10 additions & 0 deletions crates/core/src/index_ty.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::ValType;

/// The index type used for addressing memories and tables.
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum IndexType {
Expand All @@ -8,6 +10,14 @@ pub enum IndexType {
}

impl IndexType {
/// Returns the [`ValType`] associated to `self`.
pub fn ty(&self) -> ValType {
match self {
IndexType::I32 => ValType::I32,
IndexType::I64 => ValType::I64,
}
}

/// Returns `true` if `self` is [`IndexType::I64`].
pub fn is_64(&self) -> bool {
matches!(self, Self::I64)
Expand Down
1 change: 1 addition & 0 deletions crates/wasmi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ prefer-btree-collections = [
]
wat = ["dep:wat", "std"]
simd = ["wasmi_core/simd", "wasmi_ir/simd", "wasmparser/simd"]
experimental-translator = []

# Enables extra checks performed during Wasmi bytecode execution.
#
Expand Down
21 changes: 16 additions & 5 deletions crates/wasmi/src/engine/block_type.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg_attr(not(feature = "experimental-translator"), allow(dead_code))] // TODO: remove

use crate::{
core::ValType,
engine::DedupFuncType,
Expand All @@ -18,7 +20,7 @@ pub enum BlockTypeInner {
/// A block type with no parameters and no results.
Empty,
/// A block type with no parameters and exactly one result.
Returns,
Returns(ValType),
/// A general block type with parameters and results.
FuncType(DedupFuncType),
}
Expand Down Expand Up @@ -54,8 +56,8 @@ impl BlockType {
}

/// Creates a [`BlockType`] with no parameters and a single result type.
fn returns(_return_type: ValType) -> Self {
Self::from_inner(BlockTypeInner::Returns)
fn returns(return_type: ValType) -> Self {
Self::from_inner(BlockTypeInner::Returns(return_type))
}

/// Creates a [`BlockType`] with parameters and results.
Expand All @@ -66,7 +68,7 @@ impl BlockType {
/// Returns the number of parameters of the [`BlockType`].
pub fn len_params(&self, engine: &Engine) -> u16 {
match &self.inner {
BlockTypeInner::Empty | BlockTypeInner::Returns => 0,
BlockTypeInner::Empty | BlockTypeInner::Returns(_) => 0,
BlockTypeInner::FuncType(func_type) => {
engine.resolve_func_type(func_type, FuncType::len_params)
}
Expand All @@ -77,10 +79,19 @@ impl BlockType {
pub fn len_results(&self, engine: &Engine) -> u16 {
match &self.inner {
BlockTypeInner::Empty => 0,
BlockTypeInner::Returns => 1,
BlockTypeInner::Returns(_) => 1,
BlockTypeInner::FuncType(func_type) => {
engine.resolve_func_type(func_type, FuncType::len_results)
}
}
}

/// Applies `f` to `self`'s [`FuncType`] and returns the result.
pub fn func_type_with<R>(&self, engine: &Engine, f: impl for<'a> FnOnce(&FuncType) -> R) -> R {
match &self.inner {
BlockTypeInner::Empty => f(&FuncType::new([], [])),
BlockTypeInner::Returns(return_type) => f(&FuncType::new([], [*return_type])),
BlockTypeInner::FuncType(func_type) => engine.resolve_func_type(func_type, f),
}
}
}
5 changes: 5 additions & 0 deletions crates/wasmi/src/engine/translator/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ pub enum TranslationError {
TooManyFunctionResults,
/// Tried to define a function with too many function parameters.
TooManyFunctionParams,
/// Tried to define a function with too many local variables.
TooManyLocalVariables,
/// The function failed to compiled lazily.
LazyCompilationFailed,
}
Expand Down Expand Up @@ -99,6 +101,9 @@ impl Display for TranslationError {
Self::TooManyFunctionParams => {
write!(f, "encountered function with too many function parameters")
}
Self::TooManyLocalVariables => {
write!(f, "encountered function with too many local variables")
}
Self::LazyCompilationFailed => {
write!(
f,
Expand Down
Loading
Loading