Commit Graph

439 Commits

Author SHA1 Message Date
Takeshi Yoneda
be727a1440 Adds simd opcodes and feature flag (#555)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-05-13 12:29:59 +09:00
Takeshi Yoneda
854ac16b15 Remove drifted comment on Reference Type (#550)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-05-13 08:57:51 +09:00
Takeshi Yoneda
bfac34e927 Adds limit on the number of tables per module (#549)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-05-12 20:04:35 +09:00
Anuraag Agrawal
5fd8c29846 Fixes minor typo in godoc (#548)
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
2022-05-12 17:08:11 +09:00
Takeshi Yoneda
5884a1f49a Pass all non-SIMD v2 core specification tests (#542)
This commit enables WebAssembly 2.0 Core Specification tests.
In order to pass the tests, this fixes several places mostly on the
validation logic.

Note that SIMD instructions are not implemented yet.

part of #484

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
Co-authored-by: Crypt Keeper <64215+codefromthecrypt@users.noreply.github.com>
2022-05-12 17:07:53 +09:00
Crypt Keeper
fccf55c286 site: fixes dark mode (#547)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-05-12 14:50:46 +08:00
Anuraag Agrawal
00bce4f6c5 Actually splits test case runs for runtime TestClose. (#546)
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
2022-05-12 14:30:32 +09:00
Anuraag Agrawal
bc6df39785 Implements errors.Is for sys.ExitError (#545)
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
2022-05-12 13:06:48 +08:00
Crypt Keeper
da325eaf59 Fixes coverage on externref/uintptr (#543)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-05-11 16:35:55 +08:00
Takeshi Yoneda
05e7201698 Check-in v2 spectest cases (#541)
This commit checks-in all the specification test cases for v2 Wasm spec,
including SIMD. Currently, we do not run the tests actually as we need to
fix several places to pass spectests plus we haven't implemented SIMD yet.

I wanted to have this PR separate from removing post1_0 tests and fixes
as that would make it impossible for reviews to review on the actual code.

Signed-off-by: Takeshi Yoneda takeshi@tetrate.io
2022-05-11 14:14:41 +09:00
Takeshi Yoneda
be32386867 ci: separate workflow for specification tests (#540)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-05-11 13:44:34 +09:00
Crypt Keeper
c50c121a48 Scaffolds basic wazero.io (#538)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-05-11 09:12:21 +08:00
Takeshi Yoneda
db465e512e ci: upgrade golangci-lint, enable matrix on check job (#539)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-05-11 07:10:25 +08:00
Crypt Keeper
0868d52e8f headline 2022-05-10 19:29:47 +08:00
Crypt Keeper
1651d86aef Fixes typos 2022-05-10 19:16:59 +08:00
Takeshi Yoneda
20e46a9fdf Complete reference types proposal (#531)
This commit completes the reference-types proposal implementation.

Notably, this adds support for 
* `ref.is_null`, `ref.func`, `ref.is_null` instructions
* `table.get`, `table.set`, `table.grow`, `table.size` and `table.fill` instructions
* `Externref` and `Funcref` types (including invocation via uint64 encoding).

part of #484

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-05-10 17:56:03 +09:00
Crypt Keeper
03bfa31928 Makes all examples and docs use Runtime.Close (#537)
This removes tedium in our examples and docs by using `Runtime.Close`
instead of tracking everything. Internal tests still track too much, but
anyway at least this stops suggesting others should do it.

This also changes our examples to use log.PanicXX so that the line
number goes into the console output.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-05-10 12:08:25 +08:00
Anuraag Agrawal
8dd797e108 Adds Runtime.Close (#534)
* Adds Runtime.Close

Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
2022-05-10 12:00:18 +09:00
Anuraag Agrawal
779f01a4e1 Sets lf line endings in gitattributes and remove unused stats linguist setting. (#536)
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
2022-05-10 10:13:28 +08:00
Crypt Keeper
96bc7c8462 Exposes api.Memory Grow (#535)
This exports an API which allows host-defined functions access to
increase the memory size.

Fixes #483

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-05-09 14:56:50 +08:00
Crypt Keeper
8f8c9ee205 Extracts CompileConfig and consolidates code. (#533)
This performs several changes to allow compilation config to be
centralized and scoped properly. The immediate effects are that we can
now process external types during `Runtime.CompileModule` instead of
doing so later during `Runtime.InstantiateModule`. Another nice side
effect is memory size problems can err at a source line instead of
having to be handled in several places.

There are some API effects to this, and to pay for them, some less used
APIs were removed. The "easy APIs" are left alone. For example, the APIs
to compile and instantiate a module from Go or Wasm in one step are left
alone.

Here are the changes, some of which are only for consistency. Rationale
is summarized in each point.
* ModuleBuilder.Build -> ModuleBuilder.Compile
  * The result of this is similar to `CompileModule`, and pairs better
    with `ModuleBuilder.Instantiate` which is like `InstantiateModule`.
* CompiledCode -> CompiledModule
  * We punted on this name, the result is more than just code. This is
    better I think and more consistent as it introduces less terms.
* Adds CompileConfig param to Runtime.CompileModule.
  * This holds existing features and will have future ones, such as
    mapping externtypes to uint64 for wasm that doesn't yet support it.
* Merges Runtime.InstantiateModuleWithConfig with Runtime.InstantiateModule
  * This allows us to explain APIs in terms of implicit or explicit
    compilation and config, vs implicit, kindof implicit, and explicit.
* Removes Runtime.InstantiateModuleFromCodeWithConfig
  * Similar to above, this API only saves the compilation step and also
    difficult to reason with from a name POV.
* RuntimeConfig.WithMemory(CapacityPages|LimitPages) -> CompileConfig.WithMemorySizer
  * This allows all error handling to be attached to the source line
  * This also allows someone to reduce unbounded memory while knowing
    what its minimum is.
* ModuleConfig.With(Import|ImportModule) -> CompileConfig.WithImportRenamer
  * This allows more types of import manipulation, also without
    conflating functions with globals.
* Adds api.ExternType
  * Needed for ImportRenamer and will be needed later for ExportRenamer.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-05-09 11:02:32 +08:00
Crypt Keeper
0561190cb9 Documents Memory.Read as a way to share memory between Go and Wasm (#527)
By testing the side-effects of Memory.Read, we ensure users who control
the underlying memory capacity can use the returned slice for
write-through access to Wasm addressible memory. Notably, this allows a
shared fixed length data structure to exist with a pointer on the Go
side and a memory offset on the Wasm side.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
Co-authored-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-05-06 09:56:40 +08:00
Takeshi Yoneda
dcedae2441 Use leb128 u32 for data/element segment prefixes (#530)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-05-06 09:16:16 +09:00
Takeshi Yoneda
f9bcd4ff2c Adds ad-hoc test on bounds check with memory capacity config (#529)
Previously, we haven't had the tests to verify that memory bounds check work correctly
with memory capacity configuration. Notably, this ensures that memory access offsets
larger than size but less than capacity actually result in memory out of bounds access.

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-05-06 09:11:17 +09:00
inkeliz
7f1dab1988 Fix bytes capacity on Read (#528)
Before that change it was possible to overwrite content out of specified range.

Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
2022-05-06 06:55:39 +08:00
Crypt Keeper
a47cb700ad examples: switches tinygo example to use slice header (#524)
We get undefined behavior, at least in code that re-slices, unless
capacity is set. This ensures the buffer under the string has a capacity
set to the same length as its size. This also shows more explicitly the
problems in TinyGo (ex some type mismatch you have to ignore until
fixed).

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-05-04 19:14:04 +08:00
Takeshi Yoneda
72f16d21eb Adds support for multi tables (#517)
This commit adds support for multiple tables per module.
Notably, if the WithFeatureReferenceTypes is enabled,
call_indirect, table.init and table.copy instructions
can reference non-zero indexed tables.

part of #484

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-05-03 11:38:51 +09:00
Crypt Keeper
18da3f58aa updates to tinygo 0.23 (#522)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-05-03 10:24:54 +08:00
Crypt Keeper
eec3cdd79e Documents why we don't use Option pattern (#521)
Closes #480

Co-authored-by: Takeshi Yoneda <takeshi@tetrate.io>
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-05-03 08:40:29 +08:00
Crypt Keeper
ceb6383ff0 Makes ModuleConfig an interface and fixes mutability bug (#520)
This makes wazero.ModuleConfig an interface instead of a struct to
prevent it from being used incorrectly. For example, even though the
fields are not exported, someone can mistakenly instantiate this
when it is a struct, and in doing so violate internal assumptions.

This also fixes a mutability bug in the implementation.

Follow-up from #519 and the last in this series

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-05-02 16:51:30 +08:00
Crypt Keeper
fbea2de984 Makes wazero.CompiledCode an interface instead of a struct (#519)
This makes wazero.CompiledCode an interface instead of a struct to
prevent it from being used incorrectly. For example, even though the
fields are not exported, someone can mistakenly instantiate this
when it is a struct, and in doing so violate internal assumptions.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-05-02 11:44:01 +08:00
Crypt Keeper
a91140f7f7 Changes RuntimeConfig to an interface and exposes WithWasmCore2 (#518)
WebAssembly Core Working Draft 1 recently came out. Before that, we had
a toe-hold feature bucked called FinishedFeatures. This replaces
`RuntimeConfig.WithFinishedFeatures` with `RuntimeConfig.WithWasmCore2`.
This also adds `WithWasmCore1` for those who want to lock into 1.0
features as opposed to relying on defaults.

This also fixes some design debt where we hadn't finished migrating
public types that require constructor functions (NewXxx) to interfaces.
By using interfaces, we prevent people from accidentally initializing
key configuration directly (via &Xxx), causing nil field refs. This also
helps prevent confusion about how to use the type (ex pointer or not) as
there's only one way (as an interface).

See https://github.com/tetratelabs/wazero/issues/516

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-05-02 10:29:38 +08:00
Crypt Keeper
abd1c79f33 Collects README links at the bottom (#515)
Collecting README links at the bottom helps with formatting. I made
some editorial changes, notably pointing people at the WebAssembly 2.0
issue which I'm fleshing out separately.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-04-30 12:18:58 +08:00
Crypt Keeper
2c03098dba Adds Runtime.WithCapacityPages to avoid allocations during runtime. (#514)
`Runtime.WithMemoryCapacityPages` is a function that determines memory
capacity in pages (65536 bytes per page). The inputs are the min and
possibly nil max defined by the module, and the default is to return
the min.

Ex. To set capacity to max when exists:
```golang
c.WithMemoryCapacityPages(func(minPages uint32, maxPages *uint32) uint32 {
	if maxPages != nil {
		return *maxPages
	}
	return minPages
})
```

Note: This applies at compile time, ModuleBuilder.Build or Runtime.CompileModule.

Fixes #500

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-04-29 17:54:48 +08:00
Crypt Keeper
189b694140 Adds experimental package to expose listener and sys APIs (#513)
This adds an experimental package to expose two work-in-progress
features:
* FunctionListener - for tracing etc.
* Sys - to control random number generators

Both the functionality and the names of the features above are
not stable. However, this should help those who can tolerate drift a
means to test things out.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
Co-authored-by: Anuraag Agrawal <anuraaga@gmail.com>
2022-04-29 08:42:24 +08:00
Takeshi Yoneda
266320e257 Complete bulk memory operations proposal (#511)
This commit implements the rest of the unimplemented instructions in the
bulk-memory-operations proposal.

Notably, this adds support for table.init, table.copy and elem.drop
instructions toggled by FeatureBulkMemoryOperations.

Given that, now wazero has the complete support for the  bulk-memory-operations
proposal as described in https://github.com/WebAssembly/spec/blob/main/proposals/bulk-memory-operations/Overview.md

fixes #321

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-04-28 15:08:24 +09:00
Takeshi Yoneda
68756acbd5 bulk memory: memory.{fill, copy, init} and data.drop (#504)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-04-27 13:22:32 +08:00
Crypt Keeper
a7373c4d6b bench: bumps wasmtime-go (#510)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-04-27 10:59:39 +08:00
Crypt Keeper
e6458c7907 Removes wasm3-go bindings (#508)
The project we were using for comparison with wasm3 was archived.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-04-26 21:41:33 +08:00
Anuraag Agrawal
633fc41706 experimental: FunctionListenerFactory can decide whether to intercept function start/finish (#505)
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-04-26 15:28:17 +08:00
Crypt Keeper
0a39438138 benchmark: Adds allocation benchmark and splits runtimes (#507)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-04-26 13:44:50 +08:00
Crypt Keeper
ad61d9a6ff Backfills test to show nested context updates work (#503)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-04-25 08:34:59 +08:00
Takeshi Yoneda
ca36651a36 Bulk memory binary encoding and validation (#494)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
Co-authored-by: Adrian Cole <adrian@tetrate.io>
2022-04-25 09:15:28 +09:00
Crypt Keeper
45ff2fe12f Propagates context to all api interface methods that aren't constant (#502)
This prepares for exposing operations like Memory.Grow while keeping the
ability to trace what did that, by adding a `context.Context` initial
parameter. This adds this to all API methods that mutate or return
mutated data.

Before, we made a change to trace functions and general lifecycle
commands, but we missed this part. Ex. We track functions, but can't
track what closed the module, changed memory or a mutable constant.
Changing to do this now is not only more consistent, but helps us
optimize at least the interpreter to help users identify otherwise
opaque code that can cause harm. This is critical before we add more
functions that can cause harm, such as Memory.Grow.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-04-25 08:13:18 +08:00
Crypt Keeper
98676fbc64 examples: polishes a few docs (#501)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-04-24 08:52:12 +08:00
Takeshi Yoneda
cd7dfee636 Adds support for nontrapping float to int conversion proposal (#490)
This commit adds support for "nontrapping float to int conversion" proposal
which is one of the finished proposals at this point and is included in the 2.0 draft.

https://github.com/WebAssembly/spec/blob/main/proposals/nontrapping-float-to-int-conversion/Overview.md

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
Co-authored-by: Adrian Cole <adrian@tetrate.io>
2022-04-23 21:33:26 +09:00
Crypt Keeper
23d878fe65 Fixes where vs benchmark stopped running after drift (#499)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-04-22 18:41:47 +09:00
Crypt Keeper
f728be94c5 Adds vs benchmark WasmEdge and splits compile from instantiate (#495)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-04-22 16:13:51 +08:00
Anuraag Agrawal
2b5b1b706e Fix build.examples so it builds all examples (#498)
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
2022-04-22 15:37:49 +08:00
Anuraag Agrawal
56a4e482f5 Add CODEOWNERS (#497)
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
2022-04-22 12:29:00 +09:00