Commit Graph

549 Commits

Author SHA1 Message Date
Crypt Keeper
5f92e37d19 Makes ExportedFunctions unique (#698)
Exported functions are easier to use as a map vs making the callers do
it.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-07-14 18:05:12 +08:00
Crypt Keeper
040736caac Adds function names to host functions and improves logging listener (#697)
This improves the experimental logging listener to show parameter name
and values like so:

```
--> ._start.command_export()
        	--> .__wasm_call_ctors()
        		--> .__wasilibc_initialize_environ()
        			==> wasi_snapshot_preview1.environ_sizes_get(result.environc=1048572,result.environBufSize=1048568)
        			<== ESUCCESS
        		<-- ()
        		==> wasi_snapshot_preview1.fd_prestat_get(fd=3,result.prestat=1048568)
        		<== ESUCCESS
        		--> .dlmalloc(2)
        			--> .sbrk(0)
        			<-- (1114112)
        		<-- (1060080)
--snip--
```

The convention `==>` implies it was a host function call
(def.IsHostFunction). This also improves the lifecycle by creating
listeners during compile. Finally, this backfills param names for
assemblyscript and wasi.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-07-14 16:43:25 +08:00
Takeshi Yoneda
0ae4254f21 Support for select instructions on vector values (#696)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-14 14:45:17 +09:00
Takeshi Yoneda
48d6e6f2e1 compiler(amd64),interpreter: signed-extend to 32-bit in V128ExtractLane. (#695)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-14 12:47:44 +09:00
Takeshi Yoneda
7474308111 func_validation: do not modify original types in unreachable state (#693)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-14 09:48:15 +09:00
Takeshi Yoneda
03b0c03a81 interpreter: remove unnecessary pc advancing in V128ITruncSatFromF (#692)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-13 16:55:46 +09:00
Takeshi Yoneda
a6927d58ed Read unsigned leb128 for the index of ref.func in global initializer (#691)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-13 15:21:21 +09:00
Crypt Keeper
49e5bcb8c7 Top-levels FunctionDefinition to allow access to all function metadata (#686)
This top-levels `api.FunctionDefinition` which was formerly
experimental, and also adds import metadata to it. Now, it holds all
metadata known at compile time.

Here are the public API visible changes:
* api.ExportedFunction - replaced with api.FunctionDefinition as it is
  usable for all types of functions.
* api.Function - `.ParamTypes/ResultTypes()` are replaced with
  `.Definition().
* api.FunctionDefinition - extracted from experimental and adds
  `.Import()` to get the any imported module and function name.
* experimental.FunctionDefinition - replaced with
  api.FunctionDefinition.
* experimental.FunctionListenerFactory - adds first arg of the
  instantiated module name, as it can be different than compiled.
* wazero.CompiledModule - Adds `.ImportedFunctions()` and changes result
  type of `.ExportedFunctions()` to api.FunctionDefinition.

Internally, logic to create function definition are consolidated between
host and wasm-defined functions, notably wasm.Module now includes
`.BuildFunctionDefinitions()` which reduces duplication in
wasm.ModuleInstance `.BuildFunctions()`,

This obviates #681 by deleting the `ExportedFunction` type which
overlaps with this information.

This fixes #637 as it includes more metadata including imports.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
Co-authored-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-13 14:16:18 +08:00
Takeshi Yoneda
e85e713eb3 ir: correctly ignores unreachable br_table instructions (part2) (#690)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-13 15:02:12 +09:00
Takeshi Yoneda
f80893901d ir: correctly ignores unreachable br_table instructions (#689)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-13 12:29:33 +09:00
Takeshi Yoneda
84adbc9b9d Fixes a bug with funcref in block type (#688)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-13 10:57:34 +09:00
Takeshi Yoneda
372b93ade0 Allow externref in table validation (#687)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-13 09:43:44 +09:00
Takeshi Yoneda
aebfab8961 Fixes error message on validate/applyData elements (#685)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-13 09:07:59 +09:00
Takeshi Yoneda
e848d35244 ir: fixes a range for drop operation on vector values (#683)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-13 09:05:47 +09:00
Takeshi Yoneda
7e3d965dcd binary: allow externref in element segments (#684)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-13 09:05:23 +09:00
Takeshi Yoneda
9f178f9202 ir: correctly ignore unreachable br/br_if (#682)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-12 17:45:40 +09:00
Takeshi Yoneda
a0478f0c5c Adds ExportedFunctions API on CompiledModule. (#681)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-12 12:21:56 +09:00
Crypt Keeper
14d892d310 Removes api.ImportRenamer for a different approach to "env" (#680)
Before, we introduced a type `api.ImportRenamer` to resolve conflicts
where the "env" module was shared between AssemblyScript and
user-defined functions. This API was never used in GitHub, and is
complicated.

AssemblyScript also isn't the only ABI to share the "env" module, as
other web APIs like Emscripten do also. The less complicated approach is
to have packages that need to share "env" use
`ModuleBuilder.ExportFunctions` instead, and use namespaces as needed if
there is overlap.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-07-11 14:57:26 +08:00
Takeshi Yoneda
09a8aa6030 example(wasi): fixes link drifts (#679)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-11 07:33:41 +08:00
Crypt Keeper
f0e05fb95b examples: adds rust build and WASI example (#676)
This fixes where our pull requests didn't check the rust source in
examples were valid. It also adds an example of wasi with rust.

This uses cargo-wasi because the default target creates almost 2MB of
wasm for a simple cat program.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-07-08 10:49:50 +08:00
Anuraag Agrawal
66d43a2a52 Fix computation of offset in arm64 compiler (#677)
* Fix computation of offset in arm64 compiler

Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
2022-07-07 16:13:00 +09:00
Crypt Keeper
8c2f0928bc Panics caller on exit error (#673)
This changes the AssemblyScript abort handler and WASI proc_exit
implementation to panic the caller which eventually invoked close.

This ensures no code executes afterwards, For example, LLVM inserts
unreachable instructions after calls to exit.

See https://github.com/emscripten-core/emscripten/issues/12322
See #601

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-07-06 16:30:31 +08:00
Crypt Keeper
273013d7ce adds image syncer (#675)
This adds an image sync script similar to what we had in func-e as the
amount of matrix jobs that use qemu are hitting rate-limit problems.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-07-06 13:46:56 +08:00
Anuraag Agrawal
bd1f742cb2 Enable wasm 2.0 support in tinygo examples to allow running with wasm… (#672)
* Enable wasm 2.0 support in tinygo examples to allow running with wasm built with latest

Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
2022-07-05 15:23:38 +09:00
Crypt Keeper
891761ac1e Adds support for FreeBSD (#671)
FreeBSD was disabled due to lack of testing. This works around the
compilation problems. Note: We can't currently test arm64 automatically!

Notes:

* GitHub Actions doesn’t support FreeBSD, and may never.
* We could use Travis to run FreeBSD, but it would split our CI config.
* Using Vagrant directly is easier to debug than vmactions/freebsd-vm.
* GitHub Actions only supports virtualization on MacOS.
* GitHub Actions removed vagrant from the image starting with macos-11.
* Since VirtualBox doesn't work on arm64, freebsd/arm64 is untestabl

Signed-off-by: Adrian Cole <adrian@tetrate.io>
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
Co-authored-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-07-01 18:59:19 +08:00
Takeshi Yoneda
63f6b22311 compiler: cleanup arch specific files (#670)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-06-30 14:24:17 +09:00
Takeshi Yoneda
c5f1d84914 asm: backfills unit tests and fixes node formatting (#669)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-06-30 11:07:35 +09:00
Crypt Keeper
fe1cde140d Removes redundant error handling (#668)
This consolidates to use EBADF in places go uses it in syscalls to
reduce where we formally returned both bool and err. This also removes
the redundant panic type handling as go will already panic with a
similar message.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-06-30 07:33:24 +08:00
Takeshi Yoneda
8688f3fcb4 compiler: fix stackPointerCeil calculation (#667)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-06-29 13:19:06 +09:00
Takeshi Yoneda
cbe6170473 compiler: always allocate register to save conditional values (#666)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-06-29 09:26:50 +09:00
Crypt Keeper
512096cdbf Fixes experimental listener (#640)
There was a bug peeking values that was only visible if the entrypoint
function had parameters. This fixes the bug and backfills a relevant
call-site.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-06-29 06:47:47 +08:00
Takeshi Yoneda
29e1dead13 spectest: precise assertion on (canonical,arithmetic) NaNs (#664)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-06-28 20:47:02 +09:00
Takeshi Yoneda
2fa67b83bf asm(amd64): resolve NOP padding TODO after golang-asm removal (#663)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-06-28 09:39:19 +09:00
Takeshi Yoneda
b8c94fd0b9 asm: remove integration tests with golang-asm (#659)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-06-28 09:19:21 +09:00
Crypt Keeper
798ff20f81 Removes WithWorkDirFS and "." resolution (#660)
This removes WithWorkDirFS and any other attempts to resolve the current directory (".") in host functions. This is a reaction to reality of compilers who track this inside wasm (not via host functions). One nice side effect is substantially simpler internal implementation of file-systems.

This also allows experimental.WithFS to block file access via passing nil.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-06-27 13:29:35 +08:00
Takeshi Yoneda
fb911b811c amd64: fix unsigned extension of i32 globals (#658)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-06-27 10:30:45 +09:00
Takeshi Yoneda
fd318d4be9 asm: unexport arm64 pkg implementations (#657)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-06-26 20:26:22 +09:00
Takeshi Yoneda
1489a9f19f arm64: remove golang-asm integeration test (#655)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-06-24 14:49:50 +09:00
Takeshi Yoneda
70a69c24d0 arm64: remove CompileJumpToMemory (#654)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-06-24 12:14:56 +09:00
Takeshi Yoneda
e6f08a86fd arm64: remove NOP insertion at the beginning (#653)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-06-24 09:39:47 +09:00
Takeshi Yoneda
c983e2c972 Delete debug assembler (#652)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-06-23 16:22:58 +09:00
Takeshi Yoneda
3b4544ee48 compiler: remove embedding of pointers of jump tables (#650)
This removes the embedding of pointers of jump tables (uintptr of []byte)
used by BrTable operations. That is the last usage of unsafe.Pointer in
compiler implementations.
Alternatively, we treat jump tables as asm.StaticConst and emit them
into the constPool already implemented and used by various places.

Notably, now the native code compiled by compilers can be reusable
across multiple processes, meaning that they are independent of
any runtime pointers.

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-06-23 13:42:46 +09:00
Anuraag Agrawal
53f0c018a6 Clarify Runtime implements Namespace in ModuleBuilder.Instantiate godoc (#651)
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
2022-06-22 16:55:20 +08:00
Takeshi Yoneda
4136a360ac amd64: removes embeddings of pointers of bit masks for FP arithmetic (#648)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-06-22 13:31:26 +09:00
Takeshi Yoneda
36caf1ad5e doc: remove oudated comment on 2.0 (#649)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-06-22 13:28:20 +09:00
Takeshi Yoneda
2f8276e853 amd64,simd: fix occational partial failure of FP neg. (#647)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-06-21 15:34:51 +09:00
Takeshi Yoneda
7a6a6987db interpreter: consolidates function call logics (#646)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-06-21 13:22:24 +09:00
Takeshi Yoneda
597aca0413 site: reflect 2.0 impl on specs page (#645)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
Co-authored-by: Crypt Keeper <64215+codefromthecrypt@users.noreply.github.com>
2022-06-21 11:44:03 +09:00
Takeshi Yoneda
b0588a98c9 Completes arm64 backend for SIMD instructions (#644)
This completes the implementation of arm64 backend for SIMD instructions.
Notably, now the arm64 compiler passes 100% of WebAssemby 2.0 draft
specification tests.

Combined with the completion of the interpreter and amd64 backend (#624),
this finally resolves #484. Therefore, this also documents that wazero is
100% compatible with WebAssembly 1.0 and 2.0.

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-06-21 10:51:02 +09:00
Takeshi Yoneda
3219832e5a arm64: dot and pseudo min/max instructions (#643)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-06-20 20:03:53 +09:00