Is that right? Close? An oversimplification. Way off?
Is that right? Close? An oversimplification. Way off?
Say you have the code C=A+B in your program.
The generated assembly for a real machine looks something like this: (R* denote registers and A-C are memory addresses) load A->R1 load B->R2 add R1+R2->R3 store R3->C
WASM looks more like this: push A push B add pop C
This alone makes the approach to code generation and optimization quite different.
WASM does lack some features that you would find in real CPUs, most notably the ability for execution to jump to arbitrary memory locations. They had to work around this to maintain the behavior of goroutines. Functions also live in their own address spaces which necessitates a change to how the program counter works.
It's more that Go _requires_ a runtime to support certain features which require Garbage Collection. The requirement of a runtime in turn dictates a different architecture to run on WebAssembly.
The link does talk about GC support. It looks like wasm will have one, but go’s will most likely perform better since it is tailored to go. (edit for clarification)
I assume a lot of the planning for this was in the GitHub and mailing list discussions dedicated to go’s wasm support. I’m on mobile but I can link those later.
You can, of course, compile your GC in today, and it will work. Wasm's integrated support will mean re-using the existing GC, which means smaller code size.
Side note: most people thought this would be a precursor to DOM support, but the new "host bindings" proposal opens up DOM support without needing GC support, and many people believe that now the former will land before the latter.
Can Go simply run with the WASM GC or does it need some specific type of GC?
See https://github.com/WebAssembly/gc for the current proposal.
But one day, when there are implementations, can every language run with the WASM GC?
To go the extra mile in GC performance, the compiler and GC implementation have to collaborate, taking advantage of language specific features.
You can still do it, of course and performance isn't even that bad. See Fabrice Bellard's x86 emulator using asm.js.
There is no way around porting the runtime as well.