Hi,
Since new slides about WebAssembly has been published, with the first release (Minimum Viable Product) planned this summer, and a standardization (I think this is what is described as their PostMVP release) for the moment scheduled by the end of the year, I would like to propose the following idea: instead of spending a lot of time and energy to transpile Kotlin to JavaScript, why not targeting directly WebAssembly for your Kotlin frontend effort?
While WebAssembly MVP is similar in term of scope to asm.js and thus more designed for porting C/C++ apps like games for the web, the first standardized version of WebAssembly is likely to support more useful features like setjmp/longjmp or being able to call directly the DOM or Web APIs. The #1 use case mentioned for WebAssembly is “Better execution for languages and toolkits that are currently cross-compiled to the Web (C/C++, GWT, …)”, and that exactly what Kotlin try to achieve.
That said, since native GC support won’t be part of the first versions of WebAssembly, and given the focus on supporting LLVM → WebAssembly compile chain, WebAsssembly support is probably more related to the upcoming native environment support recently mentioned by Andrey Breslav.
Until now, Javascript was considered as the “bytecode of the web”, but with WebAssembly coming it seems to me that JavaScript will continue to be a target for languages close to JS like TypeScript or CoffeeScript, but for others, transpiling to JS will become a deprecated hack. It is like if you compile Kotlin code to Java in order to run it on the JVM!
I think we have a lot of examples that show the limits of transpiling to JavaScript. As a former Dart Google Developer Expert, I have seen that even with the best developers in that field Google failed to make dart2js a viable option. Transpiling a nice statically typed language with clear semantics to JavaScript leads to a lot of issues and is and will stay a hack. Until now we had no alternative, but now we have one and that’s an opportunity that languages should embrace to really support the Web in the coming years. Rust is a perfect fit for that, but Swift may also be a good candidate for targeting WebAssembly given their LLVM toolchain, but what about languages of the JVM? The lack of CG support make that not straightforward, but possible IMO.
So what could be the advantage for Kotlin to be a pioneer of WebAssembly?
I think that could put Kotlin in the same position than it has in Android world: a better language that produces optimized bytecode for the platform it targets.
Also being able to make concrete feedback to the WebAssembly community group, and maybe make JetBrains part of this community group to be the leader of the JVM ecosystem in that field. WebAssembly is a moving target, so you could be sure that the spec integrate your core needs in the version standardized at the end of the year. That would be a significant advantage for Kotlin frontend support.
Also by supporting WebAssembly, you would also gain JavaScript support for free.
And that could allow you to move faster on the native environment topic by joining forces with “Kotlin frontend” team, since WebAssembly support seems require AOT compilation and maybe LLVM IR generation (since WebAssembly will continue to evolve and since LLVM has first class WebAssembly support, that’s maybe easier to target a well defined format like that).
Instead of being one of the last language to release a JavaScript support, why not being the first language to work on WebAssembly support to build a strong, future proof support for the Web?