News for hackers. Stuff that matters.
Re:Zig self hosted compiler is now capable of building itself by sitkack on Saturday April 16, 2022 @12:29PM (#31053675)
You can also target C through Wasm.

https://github.com/WebAssembly/wabt/tree/main/wasm2c

Re:Zig self hosted compiler is now capable of building itself by exikyut on Saturday April 16, 2022 @02:07PM (#31054579)
My genuine question is what sort of code-size and/or performance impact the translation imposes.

The simple example in the README.md seems straightforward enough, but I wonder if there are any pathological explosions in practice.

Re:Zig self hosted compiler is now capable of building itself by sitkack on Sunday April 17, 2022 @08:01PM (#31065769)
That would be an interesting undergraduate paper. Perf, Size, by primary language, by toolchain, linker, post processor (dead code elimination, etc).

For a pathological explosion, you mean something like a Zip Bomb? Wasm and C are pretty close together in their semantics, Wasm hides the stack and prevents jumping into the middle of a function (CFI, Control Flow Integrity). I think the code bloat should be on the order of some multiple of the smallest interpreter.

I just did a quick scan of Wasm interpreters (3 in Rust, 1 in C)

    yblein/rust-wasm ~4kloc
    rhysd/wain ~16kloc
    paritytech/wasmi ~25kloc
    wasm3/wasm3 ~22kloc (C)
My hunch is that the expanded code would be approximately (2x-5x interpreter + bin.wasm). I just did a spot check with doom.wasm, I am wrong. The resulting expanded C code when compiled to Arm is 2x the wasm binary size.

    4.1M wasidoom.o
    1.8M wasidoom.wasm

https://en.wikipedia.org/wiki/Zip_bomb