Live data from Hacker News

Wasm3 compiles itself (using LLVM/Clang compiled to WASM)

twitter.com

21–30 of 106 posts

Re: Wasm3 compiles itself (using LLVM/Clang compiled to WASM)

#21
post #9
post #5

I feel the need to repost this link: https://www.destroyallsoftware.com/talks/the-birth-and-death...

I'm somewhat curious at what pace WASM will gain "market share" while it's only practical to target it with C, C++, Rust, etc. Supposedly, there are plans to expand it to where it looks more like a virtual machine and less like ASM. Adding things like garbage collection, direct DOM manipulation, polymorphic inline cache, etc. Things that would make it possible to run a decent scripting language without pulling in som…

I think WASM success won't be measured by market share gain on the web, but by number of new non-browser things that are programmed with WASM.

Re: Wasm3 compiles itself (using LLVM/Clang compiled to WASM)

#22
post #2

For those wondering, Wasm3 describes itself as "the fastest WebAssembly interpreter". Other webassembly runtimes are JIT based, rather than being interpreters. The project's readme ( https://github.com/wasm3/wasm3 ) talks more about this decision. For more on the difference, and an explanation of what JIT is, check out this section of the book Crafting Interpreters ( https://craftinginterpreters.com/a-map-of-the-terr…

> Other webassembly runtimes are JIT based, rather than being interpreters. Do none of the notable ones do normal compilation?

I think the model is typically that optimisation applied in "normal compilation" are applied when the source language is translated to WASM, meaning that the WASM -> native translation can be quite straightforward and still performant.

Re: Wasm3 compiles itself (using LLVM/Clang compiled to WASM)

#23

Earlier quoted context omitted.

An AOT compiler would do a one-time translation to a platform-specific binary. If the environment you run on doesn’t support JIT compilation (iOS for example), AOT compiling WASM is useful.

How can a platform not support j.i.t. compilation? In what way does a platform need to coöperate with that?

A JIT generally means it compiles parts of the program to machine code on the fly before running them, as needed.

To support that, the environment must allow the JIT to write machine code to memory, and then execute that same code.

CPUs have memory protection flags to control which memory areas can be written, and which can be executed. The OS is in charge of setting those flags, on request from the application. Eg. mmap and mprotect system calls.

iOS denies requests for memory that is both writable and executable at the same time. So applications cannot get the type of memory area a JIT needs. There are indirect methods where a file is written then mapped, like generating a small program or shared library on the fly. But iOS restricts these as well.

There are workarounds for a developer's personal applications, used on their own registered iOS devices. But these workarounds cannot be run by everyone else, except people with a jailbroken iOS. They cannot be used in applications on the App Store.

Re: Wasm3 compiles itself (using LLVM/Clang compiled to WASM)

#24
post #9
post #5

I feel the need to repost this link: https://www.destroyallsoftware.com/talks/the-birth-and-death...

I'm somewhat curious at what pace WASM will gain "market share" while it's only practical to target it with C, C++, Rust, etc. Supposedly, there are plans to expand it to where it looks more like a virtual machine and less like ASM. Adding things like garbage collection, direct DOM manipulation, polymorphic inline cache, etc. Things that would make it possible to run a decent scripting language without pulling in som…

> Adding things like garbage collection, direct DOM manipulation, polymorphic inline cache, etc. Things that would make it possible to run a decent scripting language without pulling in some huge runtime.

Doesnt this just imply building a 'huge runtime' into the language?

Re: Wasm3 compiles itself (using LLVM/Clang compiled to WASM)

#25
post #13

Earlier quoted context omitted.

It seems like it's headed that way. At the moment, it's only really practical to generate WASM from compiled languages, or really small languages, like Lua. And your interfaces to the browser (and thus, the outside world) itself are pretty limited, so still lots of javascript involved.

Can confirm that Lua does run in WASM in the browser: https://github.com/vvanders/wasm_lua I sometimes wonder what the world would be like if Lua had zero based indices and saw a bit broader adoption. It's such an easy language to embed/extends although QuickJS looks like it's going to give it a run for the money in the long term given the similar goals on ease of embedding. I wonder if anyone has compiled QuickJS to…

> I wonder if anyone has compiled QuickJS to WASM and run it in the browser.

Fabrice Bellard actually did it himself here: http://numcalc.com/

Re: Wasm3 compiles itself (using LLVM/Clang compiled to WASM)

#26
post #9

Earlier quoted context omitted.

I'm somewhat curious at what pace WASM will gain "market share" while it's only practical to target it with C, C++, Rust, etc. Supposedly, there are plans to expand it to where it looks more like a virtual machine and less like ASM. Adding things like garbage collection, direct DOM manipulation, polymorphic inline cache, etc. Things that would make it possible to run a decent scripting language without pulling in som…

I think WASM success won't be measured by market share gain on the web, but by number of new non-browser things that are programmed with WASM.

Agreed. An interesting example is the new Microsoft Flight Simulator, which uses WASM[0] as a sandboxed language to create airplane gauges and custom flight models (HN discussion[1]).

[0]: https://forums.flightsimulator.com/t/getting-started-with-wa... [1]: https://news.ycombinator.com/item?id=24281400

Re: Wasm3 compiles itself (using LLVM/Clang compiled to WASM)

#27
post #9
post #5

I feel the need to repost this link: https://www.destroyallsoftware.com/talks/the-birth-and-death...

I'm somewhat curious at what pace WASM will gain "market share" while it's only practical to target it with C, C++, Rust, etc. Supposedly, there are plans to expand it to where it looks more like a virtual machine and less like ASM. Adding things like garbage collection, direct DOM manipulation, polymorphic inline cache, etc. Things that would make it possible to run a decent scripting language without pulling in som…

> Things that would make it possible to run a decent scripting language without pulling in some huge runtime.

Seems to me the web already has an answer for that: transpile to JavaScript, and leverage the existing high-performance JavaScript engines.

Dart does this, for instance.

Re: Wasm3 compiles itself (using LLVM/Clang compiled to WASM)

#28
Has anyone built a compiler extension and libffi-based runtime that supports compiling otherwise normal native code to WASM (eschewing hard linking for runtime resolution)?

Would be fun to make it so that native apps for any platform can be run from an interpreter

Re: Wasm3 compiles itself (using LLVM/Clang compiled to WASM)

#29

I'm a newer dev so pardon my ignorance. Is webassembly the new, more open JVM? Feels like that write once, run everywhere but this time with any(most) mainstream language.

I'm also trying to build a mental model of what wasm is so someone correct me if I'm wrong.

As I understand, the JVM adds a thick layer of abstraction between incoming bytecode and output machine instructions. A wasm "runtime" OTOH adds a much thinner abstraction between incoming wasm and outputted machine code. It's a fairly 1:1 transformation.

However, I think you're correct in that, in order to serve as a host for GC'd and/or web-API-aware scripting languages (DOM, etc), a wasm runtime will need to become more JVM-like. How will wasm remain "web assembly" while doing that? No idea. This is where my mental model breaks down.

Re: Wasm3 compiles itself (using LLVM/Clang compiled to WASM)

#30

Has anyone built a compiler extension and libffi-based runtime that supports compiling otherwise normal native code to WASM (eschewing hard linking for runtime resolution)? Would be fun to make it so that native apps for any platform can be run from an interpreter

Emscripten?
Post reply on HN