Skip to content

Commit

Permalink
Disable the type validation in wabt tools (#461)
Browse files Browse the repository at this point in the history
This potentially fixes/improves the situation for #451 but opens a
question wrt our API.

Current situation:

You can do the parsing and cache the loaded module in memory with:
```java
private static final Module MODULE = Module.builder(...).build();
```
after that, you still need 2 steps:
 - `Instance` initialization
 - `start` function call
the initialization will also map the `HostImports`, but, when using
`wasi` we always need to re-initialize everything even when changing
only the `arguments`, as we have a single `build` method:
 ```java
 Instance.builder(MODULE).withHostImports(imports).build();
 ```
 
this is sub-optimal as there are use cases(i.e. multiple subsequent
executions of a tool) that would benefit from caching the `Instance` and
hot-swapping the wasi `HostImports`:
 
 Possible resolution:
 
 ```java
 private static final HostImports baseImports = ???;
private static final Instance INSTANCE =
Instance.builder(Module.builder(...).build()).withHostImports(baseImports).withStart(false).build();
 ```
 
when using the `Instance` we should be able to fully skip the
initialization(and have an effective memoization) by using, something
like:
 
 ```java

INSTANCE.updateImports(baseImports.withArgs(myNewArgs)).export("_start").apply();
 ```
 
There are few possible alternatives to tackle the problem, I'm
interested if this is something we want to fix now or something that can
be postponed, I'm not sure how much this pattern is widely used.
 Thoughts?
  • Loading branch information
andreaTP authored Aug 13, 2024
1 parent 34e951b commit 346f378
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion wabt/src/main/java/com/dylibso/chicory/wabt/Wast2Json.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ public void process() {
.withOpts(wasiOpts.build())
.build()) {
HostImports imports = new HostImports(wasi.toHostFunctions());
Instance.builder(MODULE).withHostImports(imports).build();
Instance.builder(MODULE)
.withTypeValidation(false)
.withHostImports(imports)
.build();
}

createDirectories(output.toPath().getParent());
Expand Down
5 changes: 4 additions & 1 deletion wabt/src/main/java/com/dylibso/chicory/wabt/Wat2Wasm.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ private static byte[] parse(InputStream is, String fileName) {
try (var wasi =
WasiPreview1.builder().withLogger(logger).withOpts(wasiOpts).build()) {
HostImports imports = new HostImports(wasi.toHostFunctions());
Instance.builder(MODULE).withHostImports(imports).build();
Instance.builder(MODULE)
.withTypeValidation(false)
.withHostImports(imports)
.build();
}

return stdoutStream.toByteArray();
Expand Down

0 comments on commit 346f378

Please sign in to comment.