“WebAssembly is a binary instruction format for a stack-based virtual machine…” Fast (startup) • Decoding Wasm binary is faster than parsing JS • Decode, validate, compile in stream / in parallel Secure • Runs in a sandboxed environment • Wasm design eliminates dangerous features from its execution semantic
では実行できない Generated Wasm runs on JS environment, but it doesn’t run on non-JS runtimes (wasmedge, wasmtime…) Wasm Linker backend in Scala.js NEW! Doesn’t work on non-JS runtime yet
/ export 文字列などの高度な型を表現する標準的なABIがない There’s no standard way to serialize high-level types across modules Wasm modules import/export functions only with i32, i64, f32, f64
in binary WIT (Wasm Interface Types) A language for describing the interfaces and data types. Tools generate glue code that conforms to the ABI from WIT. Component Model under the hood ABI とインターフェース定義言語により構成される
Without Wasm native GC, there’s a problem with interoperability between JavaScript and WebAssembly. (cycle collection problem) Why Scala hadn’t support Wasm? G “Scala.js and WebAssembly a tale of the dangers of the sea” from ScalaDays 2019 Lausanne, by Sébastien Doeraene (author of Scala.js) https://www.youtube.com/watch?v=QsOHofFJpig Wasmは2019年から考えられていたが、当時WasmGCが未成熟。適切にJSと の相互呼び出しができない
huge • Good for legacy applications Embed own GC • GC need to inspect the stack to find GC roots, which isn’t possible in Wasm, requires a shadow stack. • Cycle-collection problem Compile Scala to Wasm in 2019 WasmGC以前にWasm対応するとしたら? JVM on Wasm・GCをWasm moduleに埋め込む。どちらにも問題がある
program format • Scala is compiling to WasmGC via Scala.js IR ◦ Currently, Scala supports Wasm on browser • Wasm has potential in non-JS environment + inter-communicate with different source languages. Conclusion Wasmはブラウザ外でも活躍し言語間のinteropのための新しいレイヤ Scala.jsからWasmGCを使って効率の良いバイナリを生成
LLVM, Emscripten, and WASI-SDK to support Wasm! • ScalaNative libs work out of the box in stand-alone Wasm runtime but… • LLVM doesn’t support WasmGC ◦ Need to embed GC to Wasm module, that is expensive ◦ GC cycle-collection problem Appendix: How about Scala Native? ScalaNative は LLVM を活用、LLVM経由でWasmサポートの検討 LLVM は WasmGC 対応しておらず、GCを組み込むことになる。