Commit Graph

129 Commits

Author SHA1 Message Date
Takeshi Yoneda
c4532da719 testing: pass N, P into Run of hammer (#2146)
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
2024-03-12 10:34:42 +09:00
Takeshi Yoneda
1e22783607 validation: allows imported extern ref (#2137)
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
2024-03-08 10:03:32 +09:00
Takeshi Yoneda
81d1f20428 wazevo: implements MutableGlobal.Set, fixes emscripten test (#2129)
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
2024-03-07 12:33:59 +09:00
Takeshi Yoneda
712f9370a4 api: reverts the uint32->uint64 breaking change for 2.0 release (#2106)
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
2024-03-02 13:05:10 +09:00
Takeshi Yoneda
1458ccc8b0 Changes the type of Size() to uint64 (#2074)
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
2024-02-20 07:47:57 +09:00
Takeshi Yoneda
27624049dc wazevo(frontend): faster non-imported global access (#1889)
Some checks failed
Release CLI / Pre-release build (push) Has been cancelled
Release CLI / Pre-release test (macos-12) (push) Has been cancelled
Release CLI / Pre-release test (ubuntu-22.04) (push) Has been cancelled
Release CLI / Pre-release test (windows-2022) (push) Has been cancelled
Release CLI / Release (push) Has been cancelled
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
2023-12-22 08:04:48 -08:00
Takeshi Yoneda
b8262fe4fb Lifts LookupFunction into ModuleInstance from ModuleEngine (#1636)
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
2023-08-18 10:46:50 +09:00
Takeshi Yoneda
a9c5a44690 wazevo: adds support for imported memory (#1628)
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
2023-08-14 15:47:18 +09:00
Takeshi Yoneda
7c88d2a9d4 wazevo: adds support for load instructions (#1624)
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
2023-08-11 11:22:24 +09:00
Takeshi Yoneda
4aca6fbd0e Updates Spectest to the latest (May 23, 2023) (#1490)
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
2023-05-23 15:09:36 +10:00
Takeshi Yoneda
80452a94c3 Bulk lazy initialization of FunctionDefinitions (#1425)
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
Co-authored-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
2023-05-12 08:02:40 +10:00
Takeshi Yoneda
f47b0d3362 Reduces FunctionDefinition usages (#1419)
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
2023-05-01 10:37:43 +08:00
Nuno Cruces
77e8d72d67 api: adds CallWithStack to avoid allocations (#1407)
Signed-off-by: Nuno Cruces <ncruces@users.noreply.github.com>
2023-05-01 08:52:40 +09:00
Nuno Cruces
197facf7a9 Close certain api interfaces for external implementation (#1396)
This adds a new type `internalapi.WazeroOnly` which should be embedded on types users are likely to accidentally implement despite docs saying otherwise.

Signed-off-by: Nuno Cruces <ncruces@users.noreply.github.com>
2023-04-28 15:32:32 +08:00
Crypt Keeper
df0faa5d16 emscripten: adds experimental InstantiateForModule for invoke exports (#1372)
This adds emscripten.InstantiateForModule into the experimental package.
This builds dynamic invoke exports in the same order and only matching
those needed by the importing modules.

Finally, this removes special casing of function type IDs by deferring
resolution of them only in Emscripten.

Fixes #1364

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-04-18 09:13:50 +02:00
Crypt Keeper
b9e03dc691 Makes host function index insertion order (#1370)
This makes host functions index consistently on insertion order, rather
than lexicographic order. This helps with ABI such as Emscripten, which
need an expected order.

This also constrains the internal code around host functions to only one
export name. More than one was never used. By restricting this, logic is
simpler and smaller.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-04-17 17:18:11 +01:00
Takeshi Yoneda
8ac9a54923 wasm: reduces allocs during import resolution (#1361)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-04-13 12:35:04 +09:00
Takeshi Yoneda
a979e0f643 wasm: removes name node to simplify instantiation path (#1359)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-04-13 09:26:18 +09:00
Takeshi Yoneda
4dbdbc79a2 Defer resource closure on context cancelation to ModuleInstance.FailIfClosed (#1336)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-04-03 12:42:27 +09:00
Takeshi Yoneda
fa722dd9e3 Implements api.Function directly over engine specific callEngine (#1297)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-28 16:49:35 +09:00
Takeshi Yoneda
0857336746 Removes wasm.FunctionInstance type (#1294)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-28 14:43:44 +09:00
Takeshi Yoneda
9a87d2628b Removes validatedActiveElementSegment (#1292)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-28 08:19:40 +09:00
Takeshi Yoneda
cd606bde04 Refactors NewModuleEngine and NewCallEngine (#1291)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-27 09:40:55 +09:00
Takeshi Yoneda
a4226906cf Deletes wasm.CallCtx (#1280)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-24 17:00:43 -07:00
Takeshi Yoneda
d0fc0c6232 Import function type check at validation phrase (#1281)
Import function type check at compilation

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-24 09:10:18 +01:00
Takeshi Yoneda
cd1110c088 Avoids allocation of exports map per instance (#1275)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-23 16:37:56 +09:00
Takeshi Yoneda
cd05a22df2 Reduces allocations during instantiation (#1267)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-22 18:55:58 +09:00
Takeshi Yoneda
fe8784996c Avoides allocation with constExpr execution (#1257)
Previously executConstExpr is called various places, and therefore it was necessary to return interface{}
and that resulted in allocation per call.
This commit avoids the allocation by adding executConstExprI32 which is used by data segment manipulation,
and repurposes executConstExpr solely to global instance initialization.

As a result, this completely removes the allocation around const expr execution, and hence the perf improvement
in the instantiation phrase. The improvement diff is proportionate to the number of data segments and globals.

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-20 12:56:25 +09:00
Takeshi Yoneda
8ab1615b53 Forbids empty name module imports (#1244)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
Co-authored-by: Crypt Keeper <64215+codefromthecrypt@users.noreply.github.com>
2023-03-16 12:22:37 +09:00
Takeshi Yoneda
e17a85146a Holds wasm.Code as values on wasm.Module (#1243)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-15 14:45:54 +09:00
Takeshi Yoneda
350e81e632 Holds function types as values, not ptrs in wasm.Module (#1227)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-15 13:45:52 +09:00
Takeshi Yoneda
e42987a17a Holds memory/func defs, and validated elements as values in wasm.Module (#1224)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-13 14:52:01 +09:00
Takeshi Yoneda
7466f0e7bd Holds most fields as slice of values, not ptrs in wasm.Module (#1221)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-13 12:50:36 +09:00
Takeshi Yoneda
24e4d5dfa0 Generates typeIDs at compilation time (#1218)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-10 13:46:08 +09:00
Takeshi Yoneda
add6458c99 Removes unnecessary Engine.CreateElementInstance (#1134)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-02-17 18:20:09 +09:00
Takeshi Yoneda
f84a68b576 Fixes races around {api.Module, wazero.Runtime}.CloseWithExitCode (#1119)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-02-14 15:17:57 +09:00
Takeshi Yoneda
92e0a488b6 Support context Cancelation/Timeout in function executions (#1108)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-02-10 09:39:04 +09:00
Takeshi Yoneda
b63d4e6dcd Deletes namespace API (#1018)
Formerly, we introduced `wazero.Namespace` to help avoid module name or import conflicts while still sharing the runtime's compilation cache. Now that we've introduced `CompilationCache` `wazero.Namespace` is no longer necessary. By removing it, we reduce the conceptual load on end users as well internal complexity. Since most users don't use namespace, the change isn't very impactful.

Users who are only trying to avoid module name conflict can generate a name like below instead of using multiple runtimes:

```go
moduleName := fmt.Sprintf("%d", atomic.AddUint64(&m.instanceCounter, 1))
module, err := runtime.InstantiateModule(ctx, compiled, config.WithName(moduleName))
```

For `HostModuleBuilder` users, we no longer take `Namespace` as the last parameter of `Instantiate` method: 

```diff
 	// log to the console.
 	_, err := r.NewHostModuleBuilder("env").
 		NewFunctionBuilder().WithFunc(logString).Export("log").
-		Instantiate(ctx, r)
+		Instantiate(ctx)
 	if err != nil {
 		log.Panicln(err)
 	}
```


The following is an example diff a use of namespace can use to keep compilation cache while also ensuring their modules don't conflict:

```diff

 func useMultipleRuntimes(ctx context.Context, cache) {
-	r := wazero.NewRuntime(ctx)
+	cache := wazero.NewCompilationCache()
 
 	for i := 0; i < N; i++ {
-		// Create a new namespace to instantiate modules into.
-		ns := r.NewNamespace(ctx) // Note: this is closed when the Runtime is
+		r := wazero.NewRuntimeWithConfig(ctx, wazero.NewRuntimeConfig().WithCompilationCache(cache))
 
 		// Instantiate a new "env" module which exports a stateful function.
 		_, err := r.NewHostModuleBuilder("env").
```

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-01-10 14:11:46 +09:00
Takeshi Yoneda
35500f9b85 Introduces Cache API (#1016)
This introduces the new API wazero.Cache interface which can be passed to wazero.RuntimeConfig. 
Users can configure this to share the underlying compilation cache across multiple wazero.Runtime. 
And along the way, this deletes the experimental file cache API as it's replaced by this new API.

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
Co-authored-by: Crypt Keeper <64215+codefromthecrypt@users.noreply.github.com>
2023-01-10 09:32:42 +09:00
Crypt Keeper
da3aa7a5ad Adds ExportedFunctionDefinitions and ExportedMemoryDefinitions (#986)
This adds ExportedFunctionDefinitions and ExportedMemoryDefinitions to
api.Module so that those who can't access CompileModule can see them.

Fixes #839

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-12-31 13:11:37 +08:00
Takeshi Yoneda
c51a63058e Removes importedFn (#926)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-12-15 15:00:22 +09:00
Crypt Keeper
126bd9050d Removes context parameter from instruction-scoped operations (#923)
We originally had a `context.Context` for anything that might be
traced, but it turned out to be only useful for lifecycle and host functions.

For instruction-scoped aspects like memory updates, a context parameter is too
fine-grained and also invisible in practice. For example, most users will use
the compiler engine, and its memory, global or table access will never use go's
context.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-12-14 16:08:07 +09:00
Clifton Kaznocha
3ec5928a83 Simplify namespace (#906)
Signed-off-by: Clifton Kaznocha <ckaznocha@users.noreply.github.com>
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-12-09 09:50:48 +09:00
Takeshi Yoneda
a129cd7fd5 Removes ModuleInstance.TypeIDsIndex to reduce allocations (#897)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-12-07 13:49:12 +09:00
Takeshi Yoneda
4a60a8f4eb ModuleInstance.Functions/Exports as non-pointer slice (#894)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-12-07 12:45:06 +09:00
Takeshi Yoneda
b8adb361e8 Fixes FuncRef global initialization with imported globals (#888)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-12-06 14:32:12 +09:00
Crypt Keeper
af8105ba0e Adds ResultNames to HostFunctionBuilder and FunctionDefinition (#887)
This adds ResultNames to HostFunctionBuilder and FunctionDefinition
which helps for multi-results or special-cased ones.

End users can access result names in `FunctionDefinition.ResultNames` or
set for their own host functions via
`HostFunctionBuilder.WithResultNames`. This change adds them for all
built-in functions where result names help.

Most notably, GOOS=js uses `ProxyFunc` to allow logging when a function
returns multiple results. Before, the results were returned without
names: e.g. `11231,1` and now they are named like `n=11231,ok=1`.

We soon plan to allow more visibility in WASI, for example, logging
results that will write to memory offsets. This infrastructure makes it
possible to do that.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-12-06 14:30:55 +09:00
Takeshi Yoneda
610af79719 Fixes applyTableInits for many extern null inits (#874)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-11-30 15:32:06 +09:00
Takeshi Yoneda
721327decc Consolidates table init logics (#873)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-11-30 14:28:37 +09:00
Takeshi Yoneda
8339045657 Ensures listeners only bound to compile time objects (#870)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-11-29 17:25:59 +09:00