Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
486 commits
Select commit Hold shift + click to select a range
3924584
rename ExtendToResult -> IntoTrapResult
Robbepop Oct 21, 2025
afab9d0
remove break_if_trap macro
Robbepop Oct 21, 2025
b26971a
refactor/redesign VmState API
Robbepop Oct 22, 2025
14dd824
add Debug derives to [{Value,Call}]Stack types
Robbepop Oct 22, 2025
7470d8c
add missing APIs to [{Call,Value}]Stack types
Robbepop Oct 22, 2025
5862d14
add missing imports
Robbepop Oct 22, 2025
fc7d6cb
add debug_asssert to ValueStack::push
Robbepop Oct 22, 2025
407c7ae
properly adjust return and return_span handlers
Robbepop Oct 22, 2025
1d9fc98
improve macro hygiene of compile_or_get_func
Robbepop Oct 22, 2025
96ac3b0
add utils::compile_or_get_func method
Robbepop Oct 22, 2025
63e2ae6
make op_code_to_handler public
Robbepop Oct 22, 2025
ba57c58
add WasmFuncCall type and API
Robbepop Oct 22, 2025
f33398c
add Sp::as_slice method
Robbepop Oct 22, 2025
a7cfba0
add missing new line separator
Robbepop Oct 22, 2025
695233a
properly re-export handler definitions
Robbepop Oct 22, 2025
56d9e5c
implement direct-threading encoding in translator
Robbepop Oct 22, 2025
7346b0b
initial EngineExecutor impls using WasmFuncCall
Robbepop Oct 22, 2025
3415835
mark EngineStacks Send and Sync
Robbepop Oct 22, 2025
9544ba2
remove unused DEFAULT_MEMORY_INDEX constant
Robbepop Oct 22, 2025
ed9b260
silence warnings
Robbepop Oct 22, 2025
a7be24f
properly use {Read,Write}As traits in Sp's API
Robbepop Oct 22, 2025
3e9f089
remove old executor code
Robbepop Oct 22, 2025
9f17cd7
rename parameter
Robbepop Oct 22, 2025
eb0fb1f
re-design Sp::new constructor
Robbepop Oct 22, 2025
0a8876f
fix miri reported UB with direct-threading
Robbepop Oct 22, 2025
6a1a927
apply rustfmt
Robbepop Oct 23, 2025
1098200
fix trace_offset calculation
Robbepop Oct 23, 2025
86e9259
add compact and trampolines crate features to wasmi_wast crate
Robbepop Oct 23, 2025
e25e14f
use imported OpCode
Robbepop Oct 24, 2025
8a22aca
fix updating callee_sp in call handlers
Robbepop Oct 24, 2025
2a254ba
use unreachable_unchecked in Ip::decode
Robbepop Oct 24, 2025
21e2ee0
use same ip in decode and fetch
Robbepop Oct 24, 2025
96f5ffe
fix integer-overflow bug in encode_return
Robbepop Oct 24, 2025
b8b28e4
use unreachable_unreached in op_code_to_handler
Robbepop Oct 24, 2025
ed1ee87
fix bug in strip-noop optimization in copy_span
Robbepop Oct 24, 2025
36e1a8c
properly use and encode copy_span_{asc,des}
Robbepop Oct 24, 2025
bbf24cd
remove commented out code
Robbepop Oct 24, 2025
a01edd5
add #[inline(..)] annotations important for indirect-threading
Robbepop Oct 24, 2025
96eb729
fix translation of fused cmp+br for f{32,64} ops
Robbepop Oct 24, 2025
dbd34f0
apply rustfmt
Robbepop Oct 24, 2025
46614bd
fix bugs translating br_if with copying values
Robbepop Oct 24, 2025
bbf948a
add Mem0Ptr and Mem0Len types
Robbepop Oct 24, 2025
fcd3f5a
add extra-checks crate feature to wasmi_wast crate
Robbepop Oct 24, 2025
f907347
update imports for Mem0 -> Mem0Ptr renaming
Robbepop Oct 24, 2025
2d9eb83
add memory.{size,grow} execution handlers
Robbepop Oct 24, 2025
c3ae33f
dedup code in CallStack
Robbepop Oct 25, 2025
b3bf41c
optimize CallStack instance caching
Robbepop Oct 25, 2025
35959b6
add UpdateBranchOffset impl for ir::BranchOffset
Robbepop Oct 25, 2025
25a68bb
fix bug pushing a zero-sized function frame
Robbepop Oct 25, 2025
b58ba60
move debug_asserts into copy_span_{asc,des}
Robbepop Oct 25, 2025
5159e9a
fix bugs in br_table translation
Robbepop Oct 25, 2025
93df0d0
add br_table execution handlers
Robbepop Oct 25, 2025
1b94392
generate instance execution getters via macro
Robbepop Oct 25, 2025
cf768f8
fix parameter names in generated code
Robbepop Oct 25, 2025
0fa8563
change fields of global ops to improve alignment
Robbepop Oct 25, 2025
ed1a2a1
use new store internal errors in executor
Robbepop Oct 27, 2025
492ee82
reorder Done impls
Robbepop Oct 28, 2025
e011937
add done macro
Robbepop Oct 28, 2025
f1431da
use done macro in trap execution handler
Robbepop Oct 28, 2025
8b8e206
add return to done macro expansion
Robbepop Oct 28, 2025
927255e
use done macro everywhere that makes sense
Robbepop Oct 28, 2025
6a17a73
remove unneeded compile_or_get_func macro params
Robbepop Oct 28, 2025
7639921
use debug_assert in done method
Robbepop Oct 28, 2025
41f1f8f
remove unused Done type
Robbepop Oct 28, 2025
df8b270
add #[inline(always)] annotations to push_frame API
Robbepop Oct 29, 2025
db19d58
replace exec_return macro with function
Robbepop Oct 29, 2025
1a5ab78
add return_call_internal execution handler
Robbepop Oct 29, 2025
76f3be9
add remaining return_call* execution handlers
Robbepop Oct 29, 2025
183fe88
rename params in push_frame
Robbepop Oct 30, 2025
56af874
refactor Stack internals
Robbepop Oct 30, 2025
0b3a877
use unreachable_unchecked in CallStack::pop
Robbepop Oct 30, 2025
79187b1
add Inst abstraction type
Robbepop Oct 31, 2025
7159a94
make dispatching host functions use Inst instead of &Instance
Robbepop Nov 1, 2025
4cd5b6b
add Stack::prepare_host_frame API
Robbepop Nov 1, 2025
721431c
rename var bindings
Robbepop Nov 1, 2025
06f3eb5
support host function calls in call_{imported,indirect}
Robbepop Nov 1, 2025
9054de2
properly use explicit dangling Sp instead of null
Robbepop Nov 1, 2025
1314254
fix bug in memory.grow execution handler
Robbepop Nov 1, 2025
12705d2
improve debug assert message
Robbepop Nov 1, 2025
0de306e
fix bug in Stack::pop_frame
Robbepop Nov 1, 2025
25d17f5
disable known failing wast tests
Robbepop Nov 1, 2025
d8b3d50
use wasm API for f{32,64}.ne execution handlers
Robbepop Nov 1, 2025
9c9f68f
fix bug with f32.ne translation
Robbepop Nov 1, 2025
ad5516d
fix bug in ValueStack::replace
Robbepop Nov 2, 2025
eb6fdfe
use return in dispatch! macro expansion
Robbepop Nov 3, 2025
b98c276
add and use DoneReason::out_of_fuel constructor
Robbepop Nov 3, 2025
384f612
fix bug in memory.fill translation
Robbepop Nov 3, 2025
42fa7d9
add resolve_data_mut utility
Robbepop Nov 3, 2025
eb54213
add bulk-memory execution handlers
Robbepop Nov 3, 2025
d0ae110
enable some passing spec testsuite tests
Robbepop Nov 3, 2025
61b1fb1
add and use consume_fuel utility macro
Robbepop Nov 3, 2025
1f5d083
allow optional trailing comma in done! macro
Robbepop Nov 3, 2025
ba756af
move eval submodule below others
Robbepop Nov 3, 2025
a021fe7
implement Done in terms of ControlFlow
Robbepop Nov 3, 2025
8eb2389
add memory_copy_within helper method
Robbepop Nov 3, 2025
502d8e6
apply rustfmt
Robbepop Nov 3, 2025
a839a3e
add Control type alias which is less confusing
Robbepop Nov 3, 2025
c02e934
restrict visibility of some module re-exports
Robbepop Nov 3, 2025
cbc37de
rename utility traits
Robbepop Nov 3, 2025
8deee4e
move ControlBreak + impl down
Robbepop Nov 4, 2025
6cd1c6e
remove unused ControlContinue with trampolines
Robbepop Nov 4, 2025
8fde8b3
add state to Break variant
Robbepop Nov 4, 2025
346ad56
simplify ErrorKind::as_trap_code
Robbepop Nov 4, 2025
93007a2
add TrapCode::OutOfSystemMemory
Robbepop Nov 4, 2025
f68ef1c
adjust Break type for new TrapCode
Robbepop Nov 4, 2025
f869c14
add ExecutionOutcome type
Robbepop Nov 4, 2025
1e51777
update comment
Robbepop Nov 5, 2025
5949386
add IntoControl utility trait
Robbepop Nov 5, 2025
6003fd8
add memory_slice and memory_slice_mut helper methods
Robbepop Nov 5, 2025
c9ef06b
use new utilities in execution handlers where possible
Robbepop Nov 5, 2025
d9cb208
remove no longer used IntoTrapResult utility trait
Robbepop Nov 5, 2025
041d9cb
remove some unused or dead code
Robbepop Nov 5, 2025
4ea338d
remove unused import
Robbepop Nov 5, 2025
617c5c3
fix intra doc links
Robbepop Nov 5, 2025
501493f
swap lhs and rhs for circuiting cmps to avoid some memory accesses
Robbepop Nov 5, 2025
5ede2da
add call_wasm utility function
Robbepop Nov 5, 2025
2fc3ad9
add and use call_host utility function
Robbepop Nov 5, 2025
42f0874
add return_call_wasm utility function
Robbepop Nov 5, 2025
00352bb
optimize return operator execution handling
Robbepop Nov 5, 2025
ea9a4af
add and use call_wasm_or_host utility function
Robbepop Nov 5, 2025
742679f
switch param order
Robbepop Nov 5, 2025
06287b3
fix field ordering of TableSet operations
Robbepop Nov 5, 2025
927b1a9
fix type check bug in visit_table_set
Robbepop Nov 5, 2025
fa30e2a
implement bulk-table operator execution handlers
Robbepop Nov 5, 2025
9f1d643
enable many Wast tests that are now passing
Robbepop Nov 5, 2025
0d50269
change unimplemented -> panic
Robbepop Nov 6, 2025
d89f961
add wide-arithmetic execution handlers
Robbepop Nov 6, 2025
10446f1
fix bug in host function calls with zero frame size
Robbepop Nov 7, 2025
2987018
remove some dead code
Robbepop Nov 7, 2025
137f6f7
implement host function calls in return_call[_indirect]
Robbepop Nov 8, 2025
130dfc4
refactor and simplify executor in preparation of resumable functions
Robbepop Nov 9, 2025
b85b4d4
remove unused frame_size field
Robbepop Nov 10, 2025
0efeeee
use Inst instead of Instance in WasmFuncCall
Robbepop Nov 10, 2025
7d72097
add Stack::sync_ip API
Robbepop Nov 10, 2025
a094b64
add and use out_of_fuel! utility macro
Robbepop Nov 10, 2025
018e002
implement call resumption after running out of fuel
Robbepop Nov 10, 2025
494b8f0
add cfg guard to op_code_to_handler match
Robbepop Nov 10, 2025
845511a
implement call resumption after host call error
Robbepop Nov 10, 2025
9631530
rename DoneReason::CompileError -> Error + add docs
Robbepop Nov 10, 2025
343286e
disallow resumption when a host tail call would return
Robbepop Nov 10, 2025
a40f2c3
remove unused utility function
Robbepop Nov 11, 2025
8356b99
reformat code slightly
Robbepop Nov 11, 2025
6661b61
initial implementation for root host function calls
Robbepop Nov 11, 2025
908979a
remove overly strict debug_assert
Robbepop Nov 11, 2025
abc9e01
swap parameters of ResumableCall* types
Robbepop Nov 11, 2025
8cb6e8c
use proper byte sizes for ValueStack setup
Robbepop Nov 11, 2025
e124710
add missing import
Robbepop Nov 11, 2025
2b0f5cc
move comment
Robbepop Nov 11, 2025
eb6a4f9
use sp_or_dangling in restore_frame
Robbepop Nov 11, 2025
0c77960
add ValueStack::grow_if_needed method
Robbepop Nov 11, 2025
828f626
make use of ValueStack::grow_if_needed
Robbepop Nov 11, 2025
6c6aece
fix bug after using ValueStack::grow_if_needed
Robbepop Nov 11, 2025
74fd94a
relaxed debug_assert and add comment
Robbepop Nov 12, 2025
c6a3a03
disable SIMD specific Wast test for now
Robbepop Nov 12, 2025
78d3e72
fix bug in ValueStack::prepare_host_frame
Robbepop Nov 12, 2025
0b9d5b3
add default features to wasmi_wast
Robbepop Nov 12, 2025
491a1e1
simplify memory_bytes utility method
Robbepop Nov 12, 2025
821b131
use trampolines and extra-checks features in the fuzzer
Robbepop Nov 12, 2025
dd2a2b9
fix, refactor and clean-up ValueStack::replace
Robbepop Nov 12, 2025
838133d
disable simd and relaxed-simd in the fuzzer for now
Robbepop Nov 12, 2025
94a270a
remove short-circuiting from wasmi_i32_and
Robbepop Nov 12, 2025
330b065
mirror i32.and evaluation fix for i64.and
Robbepop Nov 12, 2025
c3dec8f
rename new crate features
Robbepop Nov 13, 2025
48e57c6
add codegen-units=1 to release profile
Robbepop Nov 14, 2025
f5e210f
simplify the Done type
Robbepop Nov 14, 2025
951902f
fix some incorrect execution handler identifiers
Robbepop Nov 14, 2025
e2a2a34
add stubs for all unimplemented simd operators
Robbepop Nov 14, 2025
8b66376
apply rustfmt
Robbepop Nov 14, 2025
badc801
use for_each_op to implement op_code_to_handler
Robbepop Nov 14, 2025
3d1c689
move control macros to utils
Robbepop Nov 14, 2025
501a069
move WasmFuncCall and HostFuncCall into func submodule
Robbepop Nov 14, 2025
f312651
move dispatch.rs -> dispatch/mod.rs
Robbepop Nov 14, 2025
cb1b9ef
move execute_until_done into its respective backend
Robbepop Nov 14, 2025
27e43e6
move dispatch macro into its respective backend
Robbepop Nov 14, 2025
d41177a
move NextState into its respective backend
Robbepop Nov 14, 2025
dbd7890
move control_break into its respective backend
Robbepop Nov 14, 2025
1a162cc
move Done type into its respective backend
Robbepop Nov 14, 2025
1b958d8
add #[inline(always)] for portable-dispatch
Robbepop Nov 15, 2025
f4b9609
refactor into_execution_outcome API
Robbepop Nov 15, 2025
0f58dee
improve portable-dispatch codegen
Robbepop Nov 15, 2025
e27cea4
turn execute_until_done into a method
Robbepop Nov 15, 2025
d1113fb
add inline(never) to new execute_until_done method
Robbepop Nov 15, 2025
455ee8c
refactor code a bit
Robbepop Nov 15, 2025
22eea15
move fetch_handler into backend/tail + clean-ups
Robbepop Nov 15, 2025
9c70a8b
use loop+match for portable indirect dispatch
Robbepop Nov 15, 2025
417f766
refactor portable dispatch to make it faster
Robbepop Nov 15, 2025
937235d
refactor indirect execute_until_break
Robbepop Nov 15, 2025
065a8b2
move code blocks around within file
Robbepop Nov 15, 2025
2b90de2
move some exec macros into their own submodule
Robbepop Nov 23, 2025
926b2a0
define some binary SIMD operator execution handlers
Robbepop Nov 23, 2025
f0d26b8
add support for more binary simd operators
Robbepop Nov 23, 2025
6376bd4
add extmul simd operator support
Robbepop Nov 23, 2025
da79375
add more binary simd operators
Robbepop Nov 23, 2025
90da6d4
add more binary simd operators
Robbepop Nov 23, 2025
3660c80
add support for Wasm simd splat operators
Robbepop Nov 23, 2025
a0c8f83
add more unary simd operators
Robbepop Nov 23, 2025
8ece0a2
add copy128 execution handler
Robbepop Nov 23, 2025
01801f8
fix signed simd extract_lane identifiers
Robbepop Nov 24, 2025
0978caf
add execution handlers for simd extract_lane operators
Robbepop Nov 24, 2025
4b96274
add replace_lane execution handlers
Robbepop Nov 24, 2025
3e276b1
adjust code after rebase
Robbepop Nov 24, 2025
275e941
adjust to new extract_lane identifiers
Robbepop Nov 24, 2025
91c8ce9
add ternary simd operator execution handlers
Robbepop Nov 24, 2025
0a4a032
add remaining simd ternary execution handlers
Robbepop Nov 24, 2025
059be78
move some macros to exec/macros submodule for reuse
Robbepop Nov 24, 2025
4186513
fix macro hygiene
Robbepop Nov 24, 2025
cc7b715
fix code formatting
Robbepop Nov 24, 2025
81727b9
add generic simd load execution handlers
Robbepop Nov 24, 2025
ea062e3
add simd load_lane execution handlers
Robbepop Nov 24, 2025
7be62e7
add some whitespace to improve separation of defs
Robbepop Nov 24, 2025
8a8df60
move some store macros to macro submodule
Robbepop Nov 24, 2025
28a3108
add exceution handlers for some simd store operators
Robbepop Nov 24, 2025
1d2c4e1
add store lane simd execution handlers
Robbepop Nov 24, 2025
2be7607
re-enable spec/start Wast test
Robbepop Nov 24, 2025
e7a4b71
re-enable all passing SIMD Wast tests
Robbepop Nov 24, 2025
7012944
fix build for !simd
Robbepop Nov 24, 2025
e094761
remove unused clippy allow attribute
Robbepop Nov 24, 2025
cb3bf8e
apply rustfmt
Robbepop Nov 24, 2025
8852647
fix simd translation bug with immediate operands
Robbepop Nov 24, 2025
cc35adb
implement v128.store translation
Robbepop Nov 24, 2025
c61de73
re-enable tests that pass now
Robbepop Nov 24, 2025
966a6da
fix some execution handlers to copy full UntypedVals
Robbepop Nov 24, 2025
1f74eac
rename parameter in set_value utility
Robbepop Nov 24, 2025
b368345
fix bug in copy128 execution handler
Robbepop Nov 24, 2025
ab20d82
re-enable simd tests that do now pass
Robbepop Nov 24, 2025
fd63d96
fix simd bit shift translation
Robbepop Nov 25, 2025
232ba43
re-enable simd bit shift Wast test
Robbepop Nov 25, 2025
0e33d56
fix minor translation bug in i64x2_extmul_low_i32x4_u
Robbepop Nov 25, 2025
a3609e3
re-enable last simd Wast test
Robbepop Nov 25, 2025
bbe8eb9
replace &mut self -> &self in encoded_ops method
Robbepop Nov 25, 2025
31f5b4c
rename macro binding
Robbepop Nov 25, 2025
e84393c
fix simd splat execution handlers
Robbepop Nov 25, 2025
f46ba56
remove unused import
Robbepop Nov 25, 2025
58b0d75
add comment to codegen-units=1
Robbepop Nov 25, 2025
f3d9838
fix bug in i8x16.shuffle translation
Robbepop Nov 26, 2025
7977291
refactor Stack::capacity -> bytes_allocated
Robbepop Nov 28, 2025
b7f7b3f
move Sp::new logic into ValueStack::sp
Robbepop Nov 28, 2025
3630004
apply some clippy suggestions
Robbepop Nov 28, 2025
8b2e601
add docs to Stack, ValueStack and CallStack APIs
Robbepop Nov 28, 2025
2f8b39c
refactor portable dispatch logic
Robbepop Nov 28, 2025
bc56f56
add #[cold] and #[inline] to some error constructors
Robbepop Nov 28, 2025
6a68f07
make handle_break a static method
Robbepop Nov 28, 2025
623c2c7
use #[inline(always)] for dispatch_handler
Robbepop Nov 28, 2025
13ff2c7
add important inline annotations
Robbepop Nov 28, 2025
68c7063
offset all TrapCode variants to free the zero value
Robbepop Nov 28, 2025
5150f37
resolve todo!()s
Robbepop Nov 29, 2025
d6d5d58
remove outdated TODO comment
Robbepop Nov 29, 2025
60693d3
slightly reformulate comment
Robbepop Nov 29, 2025
51f391a
no longer stage ops without results
Robbepop Nov 29, 2025
1166282
write safety docs for Send,Sync impls for EngineStacks
Robbepop Nov 29, 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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,6 @@ codegen-units = 1
[profile.miri]
inherits = "dev"
debug-assertions = false

[profile.release]
codegen-units = 1 # required to avoid stackoverflows when _not_ using `wasmi`'s `portable-dispatch` feature
31 changes: 20 additions & 11 deletions crates/core/src/trap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,18 +263,22 @@ macro_rules! generate_trap_code {
};
}
generate_trap_code! {
// Note: we deliberately do _not_ assign the zero value so that it can be used as success state
// in `Result<(), TrapCode>` or `Control<(), TrapCode>` as the compiler can then generate
// slightly better code.

/// Wasm code executed `unreachable` opcode.
///
/// This indicates that unreachable Wasm code was actually reached.
/// This opcode have a similar purpose as `ud2` in x86.
UnreachableCodeReached = 0,
UnreachableCodeReached = 1,

/// Attempt to load or store at the address which
/// lies outside of bounds of the memory.
///
/// Since addresses are interpreted as unsigned integers, out of bounds access
/// can't happen with negative addresses (i.e. they will always wrap).
MemoryOutOfBounds = 1,
MemoryOutOfBounds = 2,

/// Attempt to access table element at index which
/// lies outside of bounds.
Expand All @@ -284,58 +288,62 @@ generate_trap_code! {
///
/// Since indexes are interpreted as unsigned integers, out of bounds access
/// can't happen with negative indexes (i.e. they will always wrap).
TableOutOfBounds = 2,
TableOutOfBounds = 3,

/// Indicates that a `call_indirect` instruction called a function at
/// an uninitialized (i.e. `null`) table index.
IndirectCallToNull = 3,
IndirectCallToNull = 4,

/// Attempt to divide by zero.
///
/// This trap typically can happen if `div` or `rem` is executed with
/// zero as divider.
IntegerDivisionByZero = 4,
IntegerDivisionByZero = 5,

/// An integer arithmetic operation caused an overflow.
///
/// This can happen when trying to do signed division (or get the remainder)
/// -2<sup>N-1</sup> over -1. This is because the result +2<sup>N-1</sup>
/// isn't representable as a N-bit signed integer.
IntegerOverflow = 5,
IntegerOverflow = 6,

/// Attempted to make an invalid conversion to an integer type.
///
/// This can for example happen when trying to truncate NaNs,
/// infinity, or value for which the result is out of range into an integer.
BadConversionToInteger = 6,
BadConversionToInteger = 7,

/// Stack overflow.
///
/// This is likely caused by some infinite or very deep recursion.
/// Extensive inlining might also be the cause of stack overflow.
StackOverflow = 7,
StackOverflow = 8,

/// Attempt to invoke a function with mismatching signature.
///
/// This can happen with indirect calls as they always
/// specify the expected signature of function. If an indirect call is executed
/// with an index that points to a function with signature different of what is
/// expected by this indirect call, this trap is raised.
BadSignature = 8,
BadSignature = 9,

/// This trap is raised when a WebAssembly execution ran out of fuel.
///
/// The Wasmi execution engine can be configured to instrument its
/// internal bytecode so that fuel is consumed for each executed instruction.
/// This is useful to deterministically halt or yield a WebAssembly execution.
OutOfFuel = 9,
OutOfFuel = 10,

/// This trap is raised when a growth operation was attempted and an
/// installed `wasmi::ResourceLimiter` returned `Err(...)` from the
/// associated `table_growing` or `memory_growing` method, indicating a
/// desire on the part of the embedder to trap the interpreter rather than
/// merely fail the growth operation.
GrowthOperationLimited = 10,
GrowthOperationLimited = 11,

/// This trap is raised when a WebAssembly operation demanded a memory
/// allocation and the host system could not supply the requested amount.
OutOfSystemMemory = 12,
}

impl TrapCode {
Expand All @@ -358,6 +366,7 @@ impl TrapCode {
Self::BadSignature => "indirect call type mismatch",
Self::OutOfFuel => "all fuel consumed by WebAssembly",
Self::GrowthOperationLimited => "growth operation limited",
Self::OutOfSystemMemory => "out of system memory",
}
}
}
Expand Down
17 changes: 3 additions & 14 deletions crates/core/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub trait Integer: Sized + Unsigned {
/// Signed shift-right `self` by `other`.
fn shr_s(lhs: Self, rhs: Self) -> Self;
/// Unsigned shift-right `self` by `other`.
fn shr_u(lhs: Self, rhs: Self) -> Self;
fn shr_u(lhs: Self::Uint, rhs: Self::Uint) -> Self::Uint;
/// Get left bit rotation result.
fn rotl(lhs: Self, rhs: Self) -> Self;
/// Get right bit rotation result.
Expand Down Expand Up @@ -130,25 +130,14 @@ pub trait Integer: Sized + Unsigned {
pub trait Unsigned {
/// The unsigned type.
type Uint;

/// Converts `self` losslessly to the unsigned type.
fn to_unsigned(self) -> Self::Uint;
}

impl Unsigned for i32 {
type Uint = u32;
#[inline]
fn to_unsigned(self) -> Self::Uint {
self as _
}
}

impl Unsigned for i64 {
type Uint = u64;
#[inline]
fn to_unsigned(self) -> Self::Uint {
self as _
}
}

/// Float-point value.
Expand Down Expand Up @@ -270,8 +259,8 @@ macro_rules! impl_integer {
lhs.wrapping_shr(rhs as u32)
}
#[inline]
fn shr_u(lhs: Self, rhs: Self) -> Self {
lhs.to_unsigned().wrapping_shr(rhs as u32) as _
fn shr_u(lhs: Self::Uint, rhs: Self::Uint) -> Self::Uint {
lhs.wrapping_shr(rhs as u32) as _
}
#[inline]
fn rotl(lhs: Self, rhs: Self) -> Self {
Expand Down
4 changes: 2 additions & 2 deletions crates/core/src/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ impl_untyped_val! {
fn i64_shl(lhs: i64, rhs: i64) -> i64 = Integer::shl;
fn i32_shr_s(lhs: i32, rhs: i32) -> i32 = Integer::shr_s;
fn i64_shr_s(lhs: i64, rhs: i64) -> i64 = Integer::shr_s;
fn i32_shr_u(lhs: i32, rhs: i32) -> i32 = Integer::shr_u;
fn i64_shr_u(lhs: i64, rhs: i64) -> i64 = Integer::shr_u;
fn i32_shr_u(lhs: u32, rhs: u32) -> u32 = <i32 as Integer>::shr_u;
fn i64_shr_u(lhs: u64, rhs: u64) -> u64 = <i64 as Integer>::shr_u;
fn i32_rotl(lhs: i32, rhs: i32) -> i32 = Integer::rotl;
fn i64_rotl(lhs: i64, rhs: i64) -> i64 = Integer::rotl;
fn i32_rotr(lhs: i32, rhs: i32) -> i32 = Integer::rotr;
Expand Down
2 changes: 1 addition & 1 deletion crates/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ exclude.workspace = true
publish = false

[dependencies]
wasmi = { workspace = true, features = ["std", "simd"] }
wasmi = { workspace = true, features = ["std", "simd", "portable-dispatch", "extra-checks"] }
wasmtime = { workspace = true, optional = true, features = [
"cranelift",
"runtime",
Expand Down
4 changes: 3 additions & 1 deletion crates/fuzz/src/oracle/wasmi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ impl From<wasmi::Error> for FuzzError {
| TrapCode::BadConversionToInteger => crate::TrapCode::BadConversionToInteger,
| TrapCode::StackOverflow => crate::TrapCode::StackOverflow,
| TrapCode::BadSignature => crate::TrapCode::BadSignature,
| TrapCode::OutOfFuel | TrapCode::GrowthOperationLimited => return FuzzError::Other,
| TrapCode::OutOfFuel
| TrapCode::GrowthOperationLimited
| TrapCode::OutOfSystemMemory => return FuzzError::Other,
};
FuzzError::Trap(trap_code)
}
Expand Down
5 changes: 2 additions & 3 deletions crates/ir2/build/display/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use crate::build::{
BinaryOp,
CmpBranchOp,
CmpSelectOp,
FieldTy,
GenericOp,
LaneWidth,
LoadOp,
Expand Down Expand Up @@ -62,8 +61,8 @@ impl Display for DisplayDecode<&'_ Isa> {
impl Display for DisplayDecode<&'_ UnaryOp> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let camel_ident = DisplayIdent::camel(self.value);
let slot_ty = FieldTy::Slot;
writeln!(f, "pub type {camel_ident} = UnaryOp<{slot_ty}>;")
let value_ty = self.value.value_field().ty;
writeln!(f, "pub type {camel_ident} = UnaryOp<{value_ty}>;")
}
}

Expand Down
11 changes: 9 additions & 2 deletions crates/wasmi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ exclude = [
[dependencies]
wasmi_core = { workspace = true }
wasmi_collections = { workspace = true }
wasmi_ir = { workspace = true }
wasmi_ir2 = { workspace = true }
wasmparser = { workspace = true, features = ["validate", "features"] }
wat = { workspace = true, optional = true }
spin = { version = "0.9", default-features = false, features = [
Expand Down Expand Up @@ -51,7 +51,14 @@ prefer-btree-collections = [
"wasmparser/prefer-btree-collections",
]
wat = ["dep:wat", "std"]
simd = ["wasmi_core/simd", "wasmi_ir/simd", "wasmparser/simd"]
simd = ["wasmi_core/simd", "wasmi_ir2/simd", "wasmparser/simd"]

# Enables a portable dispatch scheme that avoids tail-call reliance.
# Recommended for targets without stable or guaranteed tail-call support.
portable-dispatch = []
# Enables an indirect dispatch scheme using op-codes instead of
# embedded function pointers for more compact bytecode.
indirect-dispatch = []

# Enables extra checks performed during Wasmi bytecode execution.
#
Expand Down
54 changes: 20 additions & 34 deletions crates/wasmi/src/engine/code_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
use super::{FuncTranslationDriver, FuncTranslator, TranslationError, ValidatingFuncTranslator};
use crate::{
collections::arena::{Arena, ArenaIndex},
core::{Fuel, FuelCostsProvider, UntypedVal},
core::{Fuel, FuelCostsProvider},
engine::{utils::unreachable_unchecked, ResumableOutOfFuelError},
errors::FuelError,
ir::{index::InternalFunc, Op},
ir::index::InternalFunc,
module::{FuncIdx, ModuleHeader},
Config,
Error,
Expand All @@ -28,6 +28,9 @@ use core::{
use spin::Mutex;
use wasmparser::{FuncToValidate, ValidatorResources, WasmFeatures};

#[cfg(doc)]
use crate::ir::Op;

/// A reference to a compiled function stored in the [`CodeMap`] of an [`Engine`](crate::Engine).
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct EngineFunc(u32);
Expand Down Expand Up @@ -785,9 +788,7 @@ impl<'a> From<&'a [u8]> for SmallByteSlice {
#[derive(Debug)]
pub struct CompiledFuncEntity {
/// The sequence of [`Op`] of the [`CompiledFuncEntity`].
instrs: Pin<Box<[Op]>>,
/// The constant values local to the [`EngineFunc`].
consts: Pin<Box<[UntypedVal]>>,
ops: Pin<Box<[u8]>>,
/// The number of stack slots used by the [`EngineFunc`] in total.
///
/// # Note
Expand All @@ -802,31 +803,25 @@ impl CompiledFuncEntity {
///
/// # Panics
///
/// - If `instrs` is empty.
/// - If `instrs` contains more than `i32::MAX` instructions.
pub fn new<I, C>(len_stack_slots: u16, instrs: I, consts: C) -> Self
where
I: IntoIterator<Item = Op>,
C: IntoIterator<Item = UntypedVal>,
{
let instrs: Pin<Box<[Op]>> = Pin::new(instrs.into_iter().collect());
let consts: Pin<Box<[UntypedVal]>> = Pin::new(consts.into_iter().collect());
/// - If `ops` is empty.
/// - If `ops` contains more than `i32::MAX` encoded bytes.
pub fn new(len_stack_slots: u16, ops: &[u8]) -> Self {
let ops: Pin<Box<[u8]>> = Pin::new(ops.into());
assert!(
!instrs.is_empty(),
!ops.is_empty(),
"compiled functions must have at least one instruction"
);
assert!(
// Generally, Wasmi has no issues with more than `i32::MAX` instructions.
// However, Wasmi's branch instructions can jump across at most `i32::MAX`
// forwards or `i32::MIN` instructions backwards and thus having more than
// `i32::MAX` instructions might introduce problems.
instrs.len() <= i32::MAX as usize,
ops.len() <= i32::MAX as usize,
"compiled function has too many instructions: {}",
instrs.len(),
ops.len(),
);
Self {
instrs,
consts,
ops,
len_stack_slots,
}
}
Expand All @@ -835,10 +830,8 @@ impl CompiledFuncEntity {
/// A shared reference to the data of a [`EngineFunc`].
#[derive(Debug, Copy, Clone)]
pub struct CompiledFuncRef<'a> {
/// The sequence of [`Op`] of the [`CompiledFuncEntity`].
instrs: Pin<&'a [Op]>,
/// The constant values local to the [`EngineFunc`].
consts: Pin<&'a [UntypedVal]>,
/// The sequence of encoded [`Op`]s of the [`CompiledFuncEntity`].
ops: Pin<&'a [u8]>,
/// The number of stack slots used by the [`EngineFunc`] in total.
len_stack_slots: u16,
}
Expand All @@ -847,29 +840,22 @@ impl<'a> From<&'a CompiledFuncEntity> for CompiledFuncRef<'a> {
#[inline]
fn from(func: &'a CompiledFuncEntity) -> Self {
Self {
instrs: func.instrs.as_ref(),
consts: func.consts.as_ref(),
ops: func.ops.as_ref(),
len_stack_slots: func.len_stack_slots,
}
}
}

impl<'a> CompiledFuncRef<'a> {
/// Returns the sequence of [`Op`] of the [`EngineFunc`].
/// Returns the sequence of encoded [`Op`]s of the [`EngineFunc`].
#[inline]
pub fn instrs(&self) -> &'a [Op] {
self.instrs.get_ref()
pub fn ops(&self) -> &'a [u8] {
self.ops.get_ref()
}

/// Returns the number of stack slots used by the [`EngineFunc`].
#[inline]
pub fn len_stack_slots(&self) -> u16 {
self.len_stack_slots
}

/// Returns the function local constant values of the [`EngineFunc`].
#[inline]
pub fn consts(&self) -> &'a [UntypedVal] {
self.consts.get_ref()
}
}
Loading