Files
wazero/internal/wasmruntime/errors.go
Takeshi Yoneda 9ad8af121a compiler: simplify calling convention (#782)
This simplifies the calling convention and consolidates the call frame stack
and value stack into a single stack.

As a result, the cost of function calls decreases because we now don't need
to check the boundary twice (value and call frame stacks) at each function call.

The following is the result of the benchmark for recursive Fibonacci
function in integration_test/bench/testdata/case.go, and it shows that
this actually improves the performance of function calls.

[amd64]
name                               old time/op  new time/op  delta
Invocation/compiler/fib_for_5-32    109ns ± 3%    81ns ± 1%  -25.86%  (p=0.008 n=5+5)
Invocation/compiler/fib_for_10-32   556ns ± 3%   473ns ± 3%  -14.99%  (p=0.008 n=5+5)
Invocation/compiler/fib_for_20-32  61.4µs ± 2%  55.9µs ± 5%   -8.98%  (p=0.008 n=5+5)
Invocation/compiler/fib_for_30-32  7.41ms ± 3%  6.83ms ± 3%   -7.90%  (p=0.008 n=5+5)


[arm64]
name                               old time/op    new time/op    delta
Invocation/compiler/fib_for_5-10     67.7ns ± 1%    60.2ns ± 1%  -11.12%  (p=0.000 n=9+9)
Invocation/compiler/fib_for_10-10     487ns ± 1%     460ns ± 0%   -5.56%  (p=0.000 n=10+9)
Invocation/compiler/fib_for_20-10    58.0µs ± 1%    54.3µs ± 1%   -6.38%  (p=0.000 n=10+10)
Invocation/compiler/fib_for_30-10    7.12ms ± 1%    6.67ms ± 1%   -6.31%  (p=0.000 n=10+9)

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-09-06 13:29:56 +09:00

45 lines
2.1 KiB
Go

// Package wasmruntime contains internal symbols shared between modules for error handling.
// Note: This is named wasmruntime to avoid conflicts with the normal go module.
// Note: This only imports "api" as importing "wasm" would create a cyclic dependency.
package wasmruntime
var (
// ErrRuntimeStackOverflow indicates that there are too many function calls,
// and the Engine terminated the execution.
ErrRuntimeStackOverflow = New("stack overflow")
// ErrRuntimeInvalidConversionToInteger indicates the Wasm function tries to
// convert NaN floating point value to integers during trunc variant instructions.
ErrRuntimeInvalidConversionToInteger = New("invalid conversion to integer")
// ErrRuntimeIntegerOverflow indicates that an integer arithmetic resulted in
// overflow value. For example, when the program tried to truncate a float value
// which doesn't fit in the range of target integer.
ErrRuntimeIntegerOverflow = New("integer overflow")
// ErrRuntimeIntegerDivideByZero indicates that an integer div or rem instructions
// was executed with 0 as the divisor.
ErrRuntimeIntegerDivideByZero = New("integer divide by zero")
// ErrRuntimeUnreachable means "unreachable" instruction was executed by the program.
ErrRuntimeUnreachable = New("unreachable")
// ErrRuntimeOutOfBoundsMemoryAccess indicates that the program tried to access the
// region beyond the linear memory.
ErrRuntimeOutOfBoundsMemoryAccess = New("out of bounds memory access")
// ErrRuntimeInvalidTableAccess means either offset to the table was out of bounds of table, or
// the target element in the table was uninitialized during call_indirect instruction.
ErrRuntimeInvalidTableAccess = New("invalid table access")
// ErrRuntimeIndirectCallTypeMismatch indicates that the type check failed during call_indirect.
ErrRuntimeIndirectCallTypeMismatch = New("indirect call type mismatch")
)
// Error is returned by a wasm.Engine during the execution of Wasm functions, and they indicate that the Wasm runtime
// state is unrecoverable.
type Error struct {
s string
}
func New(text string) *Error {
return &Error{s: text}
}
func (e *Error) Error() string {
return e.s
}