vs via Scala native / LLVM?
As @odersky explained, the problem with compiling to Wasm via LLVM is, there’s no way to express WasmGC primitives with LLVM.
Can WasmGC adopt a similar toolchain model as WasmMVP, and in particular use LLVM? Unfortunately, no, since LLVM does not support WasmGC (some amount of support has been explored, but it is hard to see how full support could even work). Also, many GC languages do not use LLVM–there is a wide variety of compiler toolchains in that space. And so we need something else for WasmGC.
(quote from A new way to bring garbage collected programming languages efficiently to WebAssembly · V8)
As far as I know, TeaVM and AssemblyScript ships with their own GC code instead of WasmGC. However, to make GC work, we need to ship with our own GC and allocation code, and also need to manage our own shadow stack on linear memory to maintain GC roots. That will make Scala on Wasm slower. (see the comment from TeaVM author).
Fortunately, WasmGC is already at phase 4, and pure Wasm runtimes are actively working on it.
Opting for our own GC might be an option if we wanna compile Scala to a WASI as soon as possible, at the expense of execution performance. However, in 2024, waiting for WasmGC would lead to better Wasm support for Scala in a long run.
(Also, If the goal is to compile Scala to WASI without relying on WasmGC, alternatives such as using Scala.js with QuickJS or TeaVM can be explored).
Regarding from ScalaNative (NIR) to Wasm, I’m not 100% sure which one (SJSIR to Wasm or NIR to Wasm) is better choice TBH. Especially if we don’t care JS interop.
Technically, both NIR and SJSIR can be lowered to WasmGC I guess.
With SJSIR we can benefit the Scala.js’s JS interop API for Wasm on JS environment. On the other hand, I couldn’t find the benefits of compiling from NIR.
It could be interesting to integrate with libc using wasi-libc. However, it’s impossible to link with native library with wasm (It works only if the native library compiles to wasm component + WIT). Wasm backend is basically the new different backend, most of the scala-native ecosystem won’t work with wasm out of the box.
I’d like to hear some more opinions which compilation path would be desirable @WojciechMazur @sjrd
The “Interop with other languages” part seems to be important. Is WebAssembly also an ecosystem of libraries / SDKs, or will it become one?
Yes, Wasm Component Model proposal is the thing. Although still in the early stages, there are high expectations and a number of related implementations and ecosystems are already being built, such as wit-bindgen and jco. They generates a glue code for WIT.
Please check out the UseCase for more details.