Skip to content

Any plans to support WebAssembly? #1747

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
fomkin opened this issue Jun 22, 2015 · 16 comments
Closed

Any plans to support WebAssembly? #1747

fomkin opened this issue Jun 22, 2015 · 16 comments
Labels
wontfix We decided not to fix this issue/not implement that feature request.

Comments

@fomkin
Copy link
Contributor

fomkin commented Jun 22, 2015

Some time ago Google, Microsoft, Mozilla were announced new standard of byte-code for web. Any plans to support compilation to it?

@sjrd
Copy link
Member

sjrd commented Jun 22, 2015

No. WebAssembly is the same as asm.js, i.e., it's designed for C/C++ languages, without garbage collector, without access to JavaScript objects, etc. So it is not at all a good target for Scala.js.

Supposedly, future versions of WebAssembly will (partially) aim to address garbage-collected languages, but this is a looooonnng way off, if it ever gets there.

@sjrd sjrd closed this as completed Jun 22, 2015
@sjrd sjrd added the wontfix We decided not to fix this issue/not implement that feature request. label Jun 22, 2015
@dstibbe
Copy link

dstibbe commented Jul 9, 2015

@sjrd
Copy link
Member

sjrd commented Jul 9, 2015

As the second link shows, the "support" is extremely limited, compared to what Scala.js allows you to access from JavaScript. So no, even that is not enough.

@ClintCombs
Copy link

This post-MVP WebAssembly tracking issue addresses GC. It sounds like there's a desire to more fully support GC. WebAssembly/design#1079

@sjrd
Copy link
Member

sjrd commented Jul 21, 2017

I am following those developments. Hopefully we can steer them in a way that makes Scala.js on wasm possible. Don't hold your breath, though. We're talking about years, here.

@nafg
Copy link

nafg commented Jul 15, 2019

What Blazor does currently is they compile the .NET runtime to WASM, then run regular CLR bytecode DLLs in the browser.

Other ways of getting Scala on WASM:

  1. https://github.com/shadaj/scala-native-wasm -- use scala-native to get LLVM code, emscripten compiles that to WASM.
  2. http://teavm.org/

TeaVM is an ahead-of-time compiler for Java bytecode that emits JavaScript and WebAssembly that runs in a browser. Its close relative is the well-known GWT. The main difference is that TeaVM does not require source code, only compiled class files. Moreover, the source code is not required to be Java, so TeaVM successfully compiles Kotlin and Scala.

@ljleb
Copy link

ljleb commented Apr 19, 2020

I might be delusional here, but it might be possible to "simply" implement a fully-fledged custom GC with the wasm features currently available and export Scala code along with it...

@nafg
Copy link

nafg commented Apr 19, 2020

@lebel-louisjacob see @sjrd's talk https://www.youtube.com/watch?v=QsOHofFJpig

@ljleb
Copy link

ljleb commented May 13, 2020

@nafg thanks for the talk, I'm a bit more up to date with the topic now.

As far as I understand the situation, one solution would be to translate (compile?) both JS and Scala to a common target (like llvm IR or wasm, with a custom garbage collector (just like what Blazor does for .NET)). Being both managed by the same GC, in the same environment, there would be no more "garbage collection cycle" problem.

However, it might be hard to map correctly the semantics of both languages into a common representation, and I'm not sure how much effort would be required to achieve this. Also, emitted code might get less performant and take more memory to run. Maybe waiting for a builtin GC in wasm is a more realistic idea?

Otherwise, I'm not sure where I'd be missing something.

@sjrd
Copy link
Member

sjrd commented May 13, 2020

As far as I understand the situation, one solution would be to translate (compile?) both JS and Scala to a common target (like llvm IR or wasm, with a custom garbage collector (just like what Blazor does for .NET)). Being both managed by the same GC, in the same environment, there would be no more "garbage collection cycle" problem.

You can't compile the DOM and other built-in classes and functions from JS. So that doesn't work.

@ljleb
Copy link

ljleb commented May 13, 2020

Can't we import those functions using the "import" wasm builtin (I believe you used it in your talk)? see this, they seem to refer to this functionality as well.

Unless... would using this feature mean having to run a real JS GC along with the wasm code? That would be a dead end.

@sjrd
Copy link
Member

sjrd commented May 13, 2020

would using this feature mean having to run a real JS GC along with the wasm code? That would be a dead end.

You nailed it.

@shafqatevo
Copy link

shafqatevo commented Dec 6, 2020

GraalVM has plans to be run as WebAssembly. Won’t that be another route via JS or directly from Scala?

@sjrd
Copy link
Member

sjrd commented Dec 6, 2020

Sure ... if you don't care about interoperability with other JavaScript libraries, the DOM, or any other environmental JavaScript API.

We're talking about a fundamental limitations of Wasm here, not about a limitation of compiling Scala to Wasm. No other technology can solve it as long as Wasm doesn't expose the required fundamental building blocks.

@nafg
Copy link

nafg commented Dec 6, 2020 via email

@shafqatevo
Copy link

Yes, I actually meant Blazor-like support and interop.

Akka and actor model driving and running WebAssembly-based web workers can be a major improvement to the state of the art.

Lumen, the Rust-based port of Erlang BEAM to WebAssembly, is also doing this. They can create thousands of Erlang processes even with a single web worker based process scheduler. They can even create thousands of web worker based process schedulers.

Akka on WebAssembly interoping with ScalaJS to drive DOM will be a great solution to maximally offload logic of complex large scale SPAs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix We decided not to fix this issue/not implement that feature request.
Projects
None yet
Development

No branches or pull requests

7 participants