I was too curious to see what would happen if you push LLM to port and bootstrap the ocaml sources to Haxe itself. I wasn’t able to bring it on par with the reference with the existing targets, but since we’re generating code anyway I had it create a new target that did. For anyone else curious: https://haxe-in-haxe.ben.mk
It’s already a thing.
http://haxe-in-haxe.com ![]()
https://haxe.run/
Very cool! I’ll be interested to follow up on language changes you implement.
I think the next direction for what I’ve produced would be a way to keep up with upstream over time. Maybe the sanest thing is actually going the ml2hx way and try to get that to produce Haxe that’s close to what the port settled on. Ideally that would mean the Haxe sources can be synced with whatever the Haxe compiler is at and give you the same release/stability cycle.
Out of this experiment I actually found the custom target route, and the things I learned the most interesting. Especially the speed at which you can try, benchmark and redirect. I once spent over a month of my life writing a custom target so this feels crazy.
And so my next endeavour is a custom target that produces and links native code and wasm, fully in Haxe, no C compiler needed (think golang). It’s already producing binaries and the performance is not much different than the garbage collected C target I had it build earlier. But compile times are much faster.
Hmm. Up until recently, I would’ve said ml2hx sounds rather ambitous. And until the AI bubble bursts and inference prizes 100x, I would suspect it’s more straight forward have a pipeline that LLM ports any upstream commits as they’re merged.
Also, I think there’s something to be said for having the code in Haxe and being able to tweak it without making structural changes that make further LLM powered incremental porting hard, e.g.:
- guard every backend behind
#if !gencpp.skipand so forth, so that one can trivially produce a compiler with only a subset of the targets (reducing binary size and potentially making the compilation of the compiler faster) - plug in code that only ever makes sense on some particular target, for example
#if nodejsrun macros not by interpreting typed ast in eval, but rather turning it to JS and loading that at compile time (or perhaps slightly more ambitious, do this on JVM) … for macro heavy projects, the interpreter speedup could eat the compiler slowdown
I could probably go on about wonky ideas. But my intuition is that there a whole space of tweaks one could do on the Haxe code that an LLM won’t mind, while an ml → hx pipeline would make them harder to integrate? But dunno, perhaps that’s a solvable problem too ![]()
Are you still bringing your own runtime, or are you targeting Wasm GC? Because the latter could at least be rather lean and potentially also faster (haven’t even checked how fancy the hxc GC is, but somehow I expect the JS runtimes might be better still).
In any case, super cool stuff ![]()
The ml2hx route I would really only consider if this experiment proves worthwhile and I build something on top. It would also allow you to go to older haxe versions (with some work). Regarding macros, since the target route is working out, I think we could build in a switch to compile them the same way and execute directly bypassing eval.
The custom target is taking shape now. The website is updated with the new binaries and wasm built from pure Haxe (except mbedtls and libuv which are linked in). The benchmarks show that it could be a useful target outside of the compiler too. The performance is comparable to the static targets (hxcpp, hlc) while the compilation time is close to the dynamic targets (js, hl jit), while memory usage is not too crazy.
Highlighting the more extreme example benchmark: haxe-formatter runs in 5s and compiles in 0.9s whereas hxcpp runs it at 9.7s and compiles it in 117s (the whole cpp compile chain).
I have WasmGC down as a thing to try, but for now sharing as much as possible between native and wasm pushes things forward faster.
I slopgunned it and am pleased to report the result is faster and has a lower memory footprint than the OCaml based compiler (at least on linux64 that is):
Compiling the whole compiler source to jvm is 20% faster and uses 40% memory on the bootstrapped compiler vs. the OCaml version. I’m taking that as a reference here, since it goes from source to the same (virtual) machine code, so as far as comparisons go it’s decently apples to apples.
The performance is really impressive to me (it already was before my poking around), and there’s probably quite some room for relatively cheap improvements.
And so my next endeavour is a custom target that produces and links native code and wasm, fully in Haxe, no C compiler needed (think golang).
I am working on a Haxe Go target called hx2go that could be useful if you want less surface area to work on. It’s has around 96% of the Haxe unit tests passing.
I think the next direction for what I’ve produced would be a way to keep up with upstream over time.
I think that makes much more sense, having it be a compliment to Haxe rather then a replacement.
cool stuff - I wanted to start in the same direction, now I can invest my tokens in other parts
please don’t forget neko as a target - it is not dead yet. Did some work on a JIT for 64bit targets and it is now about 10 to 14 times faster than the interpreter