Commit Graph

184 Commits

Author SHA1 Message Date
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
5464903d8f interpreter: use slice of values on functions, not ptrs (#1357)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-04-12 11:35:13 +09:00
Takeshi Yoneda
b6d19696da compiler: reuses allocated runtimeValueLocation stacks (#1348)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-04-10 14:58:47 +09:00
Takeshi Yoneda
f167939c88 wazeroir: avoids allocation with InclusiveRange (#1345)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-04-07 12:14:39 +09:00
Takeshi Yoneda
24dbf49c79 compiler: avoid alloc with stack pointer ceil and reuse bytes reader (#1344)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-04-06 16:47:08 +09:00
Takeshi Yoneda
df8586e58b interpreter: reduces allocations in lowerIR (#1343)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-04-06 15:04:39 +09:00
Takeshi Yoneda
cc28399052 wazeroir: reuses allocated slices for a module (#1342)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-04-05 20:26:44 +09:00
Edoardo Vacchi
0dc152d672 wazeroir: migrate vector, table, branch and all other remaining ops to compact repr (#1334)
Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
Co-authored-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-04-05 09:38:49 +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
Edoardo Vacchi
f3ef84c9b3 wazeroir: Load Ops, Store Ops, Set, Pick, Select, CallIndirect (#1329)
Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
Co-authored-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
2023-04-01 08:00:27 +09:00
Takeshi Yoneda
b9babda2d4 compiler: stop using map for label infos (#1327)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-31 15:14:16 +09:00
Takeshi Yoneda
cee1e50ad2 compiler: avoids allocation in label resolution (#1326)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-30 22:26:18 -07:00
Takeshi Yoneda
bbae781978 compiler: avoid allocation in SetJumpTargetOnNext (#1325)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-31 13:03:26 +09:00
Takeshi Yoneda
276d7015df compiler: removes takeFreeRegisters fn (#1324)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-31 12:34:41 +09:00
Takeshi Yoneda
ef8e12a575 compiler: bitmask for tracking used registers (#1323)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-31 12:28:20 +09:00
Tristan Willy
f3516a656f wasm: move ModuleInstance.Closed to the top (#1321)
ModuleInstance.Closed is an atomic variable meant to be loaded and
swapped with sync/atomic. Closed, being a 64 bit integer, requires 64
bit alignment. The simplest way we can get alignment is to place these
atomic fields at the top of their struct.

Closed can be moved to a more logical place once support for Go 1.18 is
dropped and its type changed to atomic.Uint64.

Signed-off-by: Tristan Willy <tristan.willy@gmail.com>
2023-03-31 08:13:44 +09:00
Edoardo Vacchi
8887799da7 wazeroir: move unary byte ops to UnionOperator (#1320)
Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
2023-03-31 08:07:12 +09:00
Edoardo Vacchi
c5d37877bd wazeroir: migrate unary operations to UnionOperation (#1318)
* refactor: OperationCall, OperationGlobalGet, OperationGlobalSet

* refactor: Constant Operations

Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>

---------
2023-03-30 12:57:45 +02:00
Edoardo Vacchi
37135067b6 wazeroir: rm nullary Operations, move interpreterOp to UnionOperation (#1310)
Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
2023-03-30 16:57:41 +09:00
Edoardo Vacchi
54ba876002 interpreter: add u1, u2 int64 to interpreterOp (#1298)
Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
2023-03-29 08:26:29 +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
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
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
c20073d228 Removes unnecessary .Index field of FunctionInstance (#1270)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-22 18:55:35 +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
aba4ede088 Removes usage of host functions with Wasm optocdes (#1241)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-15 13:42:53 +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
46887b0e31 doc: adds 'How function call works' (#1216)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
Co-authored-by: Adrian Cole <adrian@tetrate.io>
2023-03-10 15:44:44 +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
38fc1cf76c Deletes callContext.withMemory (#1214)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-08 15:42:39 +09:00
Takeshi Yoneda
ad968dc3fe Pass correct api.Module to host functions (#1213)
Fixes #1211

Previously, host functions are getting api.Module for the "originating" module, 
which is the module for api.Function currently invoked, except that the api.Module 
is modified by withMemory with the caller's memory instance, therefore there 
haven't been no problem for most cases. The only issues were the methods 
besides Memory() of api.Module, and this commit fixes them.

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-08 15:05:48 +09:00
Takeshi Yoneda
9c07b2793d Allows to set the version of CLI (#1176)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-02-28 18:09:41 +09:00
Takeshi Yoneda
5eab1a7307 compiler: pass runtimeValueLocationStack by values to reduce allocations (#1170)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-02-27 09:42:45 +09:00
Clifton Kaznocha
ecb5b1ad03 Close and return immediately if the context is already canceled (#1158)
Signed-off-by: Clifton Kaznocha <ckaznocha@users.noreply.github.com>
Co-authored-by: Clifton Kaznocha <ckaznocha@users.noreply.github.com>
2023-02-24 09:58:07 +08:00
Takeshi Yoneda
0547a8e0ab wazeroir: uses u64 as unique keys for labels (#1142)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-02-21 08:24:59 +09:00
Takeshi Yoneda
381f26db20 wazeroir: less allocations with Labels (#1141)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-02-20 17:09:17 +09:00
Takeshi Yoneda
a265d41d30 wazeroir: less allocations (#1138)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-02-20 13:29:56 +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
Edoardo Vacchi
5895873019 Add support for querying amd64 cpuid (#1118)
Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
2023-02-11 22:12:18 +09:00
Takeshi Yoneda
4f7a15bc43 Adds asmfmt in make format (#1114)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-02-10 10:20:04 +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
Crypt Keeper
8918d73020 ci: supports building with Go 1.20 and raises floor version to 1.18 (#1096)
This moves our floor version to the same we'll release 1.0 with: 1.18.
This is congruent with our version policy which is current-2.

Fixes #921

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-02-06 17:29:08 +02:00
Takeshi Yoneda
c9155b8f2b amd64: fixes memory.fill bug (#1055)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
2023-01-24 08:07:11 +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