sorawee
2020-12-25 16:07:55

TIL WTF encoding is a thing


soegaard2
2020-12-25 16:18:08

Ditto. And it is (of course) on purpose: https://news.ycombinator.com/item?id=9611710 (third comment)


badkins
2020-12-25 17:18:26

Looks like PYPL may be more of an indication for how confusing a language is :)


popa.bogdanp
2020-12-25 18:40:36

Speaking of WTFs, here’s the Go runtime compiled to Racket via Wasm: https://gist.github.com/Bogdanp/de056f6c74e3614df8acf33b9e3f9e14


popa.bogdanp
2020-12-25 18:41:40

The input .wasm is 2.2MB and the output .zo (from running compile on the data in the gist) is 22MB :smile:


jcoo092
2020-12-25 22:12:59

I imagine that Go relies on system libraries being present, whereas Racket basically just compiles the whole runtime into the file. At a guess.


popa.bogdanp
2020-12-25 22:43:20

I haven’t dug in but I believe it’s mostly due the fact that my Wasm -> Racket compiler is really naïve and ends up generating a lot of code (the file in the gist is about 16MB), which itself expands into yet more code.

The WTF was meant to be self-deprecating and not related to the size thing, which I thought was just kind of interesting. Sorry for the confusion!

The Wasm format is optimized for low file sizes in a way that the .zo format (I’m guessing) isn’t. To improve code size here, probably the best approach would be for me to add more re-sugaring steps to make the generated code look more like regular Racket and to extract more common patterns into other modules so that they may be reused.


popa.bogdanp
2020-12-25 22:46:02

If anybody has references to articles re. compiling code from a low-level language to a high-level one, I’d love to see them!


jcoo092
2020-12-25 22:51:14

This might be of some relevance there: https://github.com/lifting-bits/remill (linked to from https://blog.trailofbits.com/2020/10/22/lets-build-a-high-performance-fuzzer-with-gpus/) - I heard it mentioned on a podcast the other day. To re-compile binaries for GPU execution, they lift the assembly to LLVM IR, and then run the backend on that for the new target.


samth
2020-12-26 02:33:42

The zo format is pretty space optimized but probably not for the patterns your code generates.


samdphillips
2020-12-26 04:07:07

samdphillips
2020-12-26 04:49:09

I overthought the SET and CLR logic so there is a nice bug for anyone trying that out with more than a couple pins.