xtuc / webassemblyjs

Toolchain for WebAssembly
https://webassembly.js.org
MIT License
786 stars 91 forks source link

Provide support for proposals #367

Open xtuc opened 6 years ago

xtuc commented 6 years ago

Continuing the discussion on Slack.

Here's a list of proposal that we mentioned.

Sign-extension operators

https://github.com/WebAssembly/design/issues/1178

This impacts the wasm format and type-checker (validation), new instructions needs to be parsed/emitted and checked.

cc @maurobringolf

Multi-value

https://github.com/WebAssembly/design/issues/1146

We can simulate multiple returns values using registers (globals). The transformation itself sounds trivial, but it may have some side effects. Our wast-parser and the typechecker should already work.

More information https://blog.scottlogic.com/2018/05/29/transpiling-webassembly.html

cc @ColinEberhardt

Import/Export of Mutable Globals

https://github.com/WebAssembly/design/issues/1179

This is what is done in Webpack, we don't allow importing globals from JS. The transformation removes the imports and emit "managed" mutable globals instead.

While we can expect compiler to emit such code at the moment, we can do a smaller transformation in Webpack.

cc @xtuc

Other ideas

dcodeIO commented 6 years ago

Sign-extension-ops and mutable-globals are something AssemblyScript can produce behind feature flags, so being able to "transpile" these for environments that do not support these specs yet seems useful, similar to how Babel transpiles things in JS-space. Multi-value hasn't been touched on the AS side yet (don't know if there are other producers emitting them already), but the expectation is that there'll be a flag for these as well (fwiw: implementation will most likely be based on returning object literals that must then be destructured by the callee).

ColinEberhardt commented 6 years ago

The first thing I learnt from implementing a partial multi-value transform is that the AST tools need to be improved, that's my current priority!

Following that, I'm interested to see how some of the other later-stage proposals might be transpiled, e.g. https://github.com/WebAssembly/reference-types/blob/master/proposals/reference-types/Overview.md

xtuc commented 6 years ago

Sign-extension operators

The proposal has made it to phase 4, it's going to be shipped. Should we still polyfill it?

maurobringolf commented 6 years ago

I have done some work on polyfilling sign extension operators https://github.com/xtuc/webassemblyjs/pull/375. I think polyfills for completed proposals can still be useful (at least for us to see what's possible etc).