WebAssembly / spec

WebAssembly specification, reference interpreter, and test suite.
https://webassembly.github.io/spec/
Other
3.09k stars 438 forks source link

[JS Generator] Add scope for each wasm instance #1698

Open LiuYu396 opened 8 months ago

LiuYu396 commented 8 months ago

The live range of the wasm instance created by JS Generator is global, likes:

let $1 = instance(...); assert...($1, ...); let $2 = instance(...); assert...($2, ...);

Tests such as memory_copy.wast and memory_init.wast, usually contain many instances. When executing these tests on some machines, out of memory fails may be reported.

Can you add a scope to each instance so that they are destroyed after use ?

rossberg commented 8 months ago

That matches the .wast semantics, where all modules exist for the rest of the test script (and some tests rely on this). Determining the end of live range implicitly in the converter would not be straightforward.

I created a patch in #1699 which modifies test generators and JS converter to explicitly introduce scopes. Unfortunately, that requires using a new feature in the .wast scripts to express these scopes. Existing tools parsing .wast will most likely break, so I'm not sure if or when we can merge this.