Commit Graph

603 Commits

Author SHA1 Message Date
Crypt Keeper
57a705e594 Disallows nil context and fixes linters (#754)
staticcheck linters broke until recent golangci-lint. Now, normal
behaviour of enforcing no nil context works again. Ex.
```
assemblyscript/assemblyscript_example_test.go:16:25: SA1012: do not pass a nil Context, even if a function permits it; pass context.TODO if you are unsure about which Context to use (staticcheck)
	r := wazero.NewRuntime(nil)
```

Since default lint already checks for nil context, this removes our
permission of nil context args. The original reason we permitted nil is
no longer valid: we once allowed context to be stashed in config, and
removed that as it caused bugs. We forgot to undo allowing nil
explicitly.

Note: this doesn't particularly check in our code for nil context,
similar as we don't particularly check in our code for nil anything
else. End users should use linters as none of our parameters should be
nil anyway.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-08-19 14:52:50 +08:00
Takeshi Yoneda
5b2c25cfed Adds test to verify cross-process file system cache works (#753)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-08-19 14:17:47 +09:00
Anuraag Agrawal
b93fd89637 Accept nil ctx in NewRuntime (#752)
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
2022-08-19 12:35:15 +09:00
Takeshi Yoneda
7f8e629c65 Use ReadBuildInfo to embed wazero version (#751)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-08-19 11:18:10 +09:00
Takeshi Yoneda
1948909ec0 Fixes doc drifts on NewRuntimeConfig (#750)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-08-18 21:31:13 +09:00
Takeshi Yoneda
3b32c2028b Externalize compilation cache by compilers (#747)
This adds the experimental support of the file system compilation cache.
Notably, experimental.WithCompilationCacheDirName allows users to configure
where the compiler writes the cache into.

Versioning/validation of binary compatibility has been done via the release tag
(which will be created from the end of this month). More specifically, the cache
file starts with a header with the hardcoded wazero version.


Fixes #618

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
Co-authored-by: Crypt Keeper <64215+codefromthecrypt@users.noreply.github.com>
2022-08-18 19:37:11 +09:00
Takeshi Yoneda
076d3245e3 Pass context into NewRuntime (#748)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-08-18 14:47:49 +09:00
Matt Turner
7d071a45d7 Enable comparative benchmark builds on darwin/aarch64 (ie Apple Silicon) (#746)
Enable for Wasmer, as confirmed that the version we use has arm64 support.
Enable for Wasmtime after bumping to a version which supports arm64.
Don't enable for wasm-edge as they don't support arm64/darwin.
2022-08-17 07:33:40 +08:00
Takeshi Yoneda
d7d18a5519 compiler: drop higher bits on table index (#744)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-08-12 16:10:06 +08:00
Takeshi Yoneda
fd05b9610c arm64: do not load/store higher bits of 32-bit int/float (#743)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-08-12 16:09:37 +08:00
Nuno Cruces
ab0cb6f273 Fix fdRead: handle io.Reader corner cases (#740)
Signed-off-by: Nuno Cruces <ncruces@users.noreply.github.com>
Signed-off-by: Adrian Cole <adrian@tetrate.io>
Co-authored-by: Adrian Cole <adrian@tetrate.io>
2022-08-12 16:04:44 +08:00
Takeshi Yoneda
087ab9d9fc amd64: do not load/store higher bits of 32-bit int/float (#742)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-08-12 12:08:20 +08:00
Teppei Fukuda
bed4959f6d Adds Zig example (#741)
Signed-off-by: knqyf263 <knqyf263@gmail.com>
2022-08-11 16:31:06 +08:00
Vladislav
ec1f595225 Optimize memory bulk operations: fill on x86 (#735)
Signed-off-by: Vladislav Oleshko <vladislav.oleshko@gmail.com>
2022-08-11 12:06:26 +08:00
Nuno Cruces
00bd58e74f Fix fdSeek: result newoffset should be a uint64le (#739)
Signed-off-by: Nuno Cruces <ncruces@users.noreply.github.com>
2022-08-10 10:20:27 +08:00
Takeshi Yoneda
ef19028513 Fixes function calls / memory access with wasm-implemented host functions (#737)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-08-07 09:50:34 +08:00
Crypt Keeper
9414b0bb74 Switches default random source to deterministic (#736)
This changes the default random source to provide deterministic values
similar to how nanotime and walltime do. This also prevents any worries
about if wasm can deplete the host's underlying source of entropy.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-08-06 17:47:50 +08:00
Crypt Keeper
fe56fabd63 Removes invalid ignore files (#734)
None of the examples suggest `go build` first anymore.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-08-04 19:57:03 +12:00
Takeshi Yoneda
9be4f2979f amd64: fixes huge memory offset consts handling (#733)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-08-04 13:17:42 +09:00
Takeshi Yoneda
cb6ae4e660 Set floor on Go 1.18 (#732)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-08-03 14:25:23 +09:00
Takeshi Yoneda
9dfdab2548 amd64: correctly select sign of zeros on f32x4/f64x2 min/max (#730) 2022-08-02 19:47:49 +09:00
Takeshi Yoneda
b02b5513e8 amd64: correctly select sign of zeros on f64/32 min/max (#731)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-08-02 17:46:08 +09:00
Takeshi Yoneda
76c5d98786 Updates v2 spectest version (#729)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-30 18:33:34 +09:00
Takeshi Yoneda
c50ed2c263 example: adds missing error check (#727)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-30 11:34:33 +09:00
Takeshi Yoneda
b18b36c173 compiler: support for Wasm-implemented host functinos (#728)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-30 11:33:03 +09:00
Takeshi Yoneda
02c23d55db Disallow direct call of host functions (#723)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-30 09:33:20 +08:00
Takeshi Yoneda
ce2f447555 amd64: fixes i64x2.shr_s on CX register allocation (#726)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-29 08:36:41 +09:00
Takeshi Yoneda
c5daf5a218 interpreter,compiler(arm64): clears higher bits in i32.load_8/16_s (#725)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-28 15:45:07 +09:00
Takeshi Yoneda
d1336806d6 compiler: save conditional values at data.drop (#724)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-27 17:18:42 +09:00
Takeshi Yoneda
a064f68532 compiler: allow memory access after table.grow (#721)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-27 09:56:48 +09:00
Takeshi Yoneda
d15cc069c6 compiler: save conditional value on elem.drop (#722)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-27 09:53:19 +09:00
Vladislav
63e438aa66 Optimize memory bulk operations: copy on x86 (#700)
Signed-off-by: Vladislav Oleshko <vladislav.oleshko@gmail.com>
Co-authored-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
2022-07-26 18:22:47 +09:00
Takeshi Yoneda
41df6d9556 arm64: fix bounds check on v128.load{32,64}_zero. (#720)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-26 16:23:54 +09:00
Takeshi Yoneda
97e3216eb2 asm(arm64): fixes the source register of CMEQ(vector,zero) (#719)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-26 15:59:45 +09:00
Takeshi Yoneda
37d2c6d803 asm(arm64): fixes unaligned vector stores (#718)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-26 12:10:26 +09:00
Takeshi Yoneda
143b2be398 compiler: save conditional values at ref.func (#717)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-25 13:58:15 +09:00
Crypt Keeper
939403c10b Makes it possible to implement FunctionListener and Factory (#716)
This simplifies FunctionListener definition by making it possible to
implement both interfaces without intermediate state. Passing the
function definition to the before/after callbacks is the key.

This also continues efforts towards Go 1.19 doc formatting.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-07-25 12:53:41 +08:00
Takeshi Yoneda
8d75403c49 compiler: save conditional values at table.size (#715)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-25 13:32:32 +09:00
Takeshi Yoneda
ed068597cd ci: adds Go 1.19.0-rc.2 into matrix (#714)
This adds the 1.19.0-rc2. in the testing matrix.

This also formats the Godocs across the codebase, as
Go 1.19 has started auto-formatting Godoc. https://github.com/tetratelabs/wazero/issues/426

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-25 11:14:00 +09:00
Crypt Keeper
1689fc1bbf Allows wasm-defined host functions to use memory in interpreter (#713)
Before, we allowed stubbed host functions to be defined in wasm instead
of Go. This improves performance and reduces a chance of side-effects vs
Go. In fact, any pure function was supported in wasm, provided it only
called pure functions.

This changes internals so that a wasm-defined host function can use
memory. Notably, host functions use the caller's memory, so this is
simpler to initially support in the interpreter.

This is needed to simplify and reduce performance hit of GOARCH=wasm,
GOOS=js code, which perform a lot of memory reads and do not have
idiomatic signatures.

Note: wasm-defined host functions remain internal until we gain
experience, at least conclusion of the wasm_exec host module.


Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-07-25 09:12:44 +08:00
Takeshi Yoneda
6a62b794f5 Fixes compileDropRange when all registers are used up by live values (#711)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-25 09:18:04 +09:00
Crypt Keeper
866fac2e96 Makes CacheNumInUint64 lazy and stops crashing in assemblyscript (#712)
* Makes CacheNumInUint64 lazy and stops crashing in assemblyscript

This makes CacheNumInUint64 lazy so that all tests for function types
don't need to handle it. This also changes the assemblyscript special
functions so they don't crash when attempting to log. Finally, this
refactors `wasm.Func` so that it can enclose the parameter names as it
is more sensible than defining them elsewhere.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-07-22 16:01:20 +08:00
Takeshi Yoneda
4c71c1f33b interpreter: fixes V128FloatPromote to use lower 64-bits. (#709)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-21 17:25:06 +09:00
Takeshi Yoneda
e44fa5f44a interpreter: clear higher bits for 32-bit signed shr (#708)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-21 17:13:09 +09:00
Crypt Keeper
b98a11e9c3 Refactors host function tests to stub with wasm (#710)
This refactors host functions with no-op or constant returns to be
implemented with wasm instead of the host function bridge. This allows
better performance.

This also breaks up and makes WASI tests consistent, in a way that shows
parameter name drifts easier.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-07-21 15:49:55 +08:00
Takeshi Yoneda
303b14e67c moremath: align NaN handling with amd64/arm64 compilers (#705)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-21 12:03:05 +09:00
Crypt Keeper
0da1af2d51 Supports mix of wasm and go funcs in the same module (#707)
This removes the constraint of a module being exclusively wasm or host
functions. Later pull requests can optimize special imports to be
implemented in wasm, particularly useful for disabled logging callbacks.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-07-19 11:55:37 +08:00
Crypt Keeper
0d76b11d66 Adds Emscripten integration (#678)
This adds a toehold integration for emscripten users, so they don't
have to define the memory growth function.

Fixes #601

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-07-18 07:51:48 +08:00
Crypt Keeper
b1f4ced425 Uses Zig 0.10.0-dev for cc, adding the name section (#706)
This manually installs in CI until 0.10.0 is released.

Here's the example wasm trace output from cat.c:
```
--> ._start.command_export()
	--> .__wasm_call_ctors()
		--> .__wasilibc_populate_preopens()
			==> wasi_snapshot_preview1.fd_prestat_get(fd=3,result.prestat=1048568)
			<== ESUCCESS
			--> .dlmalloc(2)
			<-- (1051568)
			==> wasi_snapshot_preview1.fd_prestat_dir_name(fd=3,path=1051568,path_len=1)
			<== ESUCCESS
			--> .dlmalloc(32)
			<-- (1051584)
			--> .memset(32,0,1051584)
			<-- (1051584)
			--> .memcpy(0,0,1051584)
			<-- (1051584)
			--> .free(0)
			<-- ()
			--> .dlmalloc(1)
			<-- (1051632)
			--> .memcpy(1,1051569,1051632)
			<-- (1051632)
			--> .free(1051568)
			<-- ()
			==> wasi_snapshot_preview1.fd_prestat_get(fd=4,result.prestat=1048568)
			<== EBADF
		<-- ()
	<-- ()
	--> ._start()
		--> .__original_main()
			==> wasi_snapshot_preview1.args_sizes_get(result.argc=1048024,result.argv_buf_size=1048028)
			<== ESUCCESS
			--> .dlmalloc(15)
			<-- (1051648)
			--> .dlmalloc(12)
			<-- (1051568)
			--> .memset(12,0,1051568)
			<-- (1051568)
			==> wasi_snapshot_preview1.args_get(argv=1051568,argv_buf=1051648)
			<== ESUCCESS
			==> wasi_snapshot_preview1.fd_fdstat_get(fd=3,result.stat=1048544)
			<== ESUCCESS
			==> wasi_snapshot_preview1.path_open(fd=3,dirflags=1,path=1051654,path_len=8,oflags=0,fs_rights_base=0,fs_rights_inheriting=0,fdflags=0,result.opened_fd=1048572)
			<== ESUCCESS
			==> wasi_snapshot_preview1.fd_read(fd=4,iovs=1048544,iovs_len=1,result.size=1048572)
			<== ESUCCESS
			==> wasi_snapshot_preview1.fd_write(fd=1,iovs=1048544,iovs_len=1,result.size=1048572)
greet filesystem
			<== ESUCCESS
			==> wasi_snapshot_preview1.fd_read(fd=4,iovs=1048544,iovs_len=1,result.size=1048572)
			<== ESUCCESS
			==> wasi_snapshot_preview1.fd_close(fd=4)
			<== ESUCCESS
		<-- (0)
	<-- ()
	--> .__wasm_call_dtors()
		--> .__stdio_exit()
		<-- ()
	<-- ()
<-- ()

```

Special thanks to @Luukdegram for supporting the `--export` linker
argument even if this particular example doesn't use it.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-07-16 15:53:53 +08:00
Takeshi Yoneda
ff4a7ff4f9 interpreter: fixes i32x4/i16x8 bit mask (#704)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-15 16:07:49 +09:00