
Implementing a JIT-compiler with Rust - ristem
https://dinfuehr.github.io/blog/dora-implementing-a-jit-compiler-with-rust/
======
pcwalton
What I especially like about this is getting the infrastructure needed to
implement copying GC in _early_. This is really important to add at the
beginning. It's very costly to add it later once you have an entire
production-quality engine built on top of non-moving or conservative GC.

(In fact I only know of one project that successfully made the transition from
conservative to precise moving GC after many years of deployment:
SpiderMonkey.)

~~~
munificent
I believe Go initially had a conservative collector for the stack and switched
to precise:

[https://github.com/golang/go/issues/5134](https://github.com/golang/go/issues/5134)

~~~
pcwalton
Go doesn't use moving GC. (Though the work needed to implement precise GC gets
you a lot of the way to moving GC.)

~~~
the_mitsuhiko
And given how much bad cgo code is out there i doubt they can ever change
this.

~~~
pcwalton
I wasn't aware of that. This is why you do moving GC early!

Do you have more information on this? That sounds like very bad news for Go...

~~~
repsilat
Aside from the difficulty of changing, can you give a couple of sentences on
the pros/cons?

Are "moving GCs" mostly good for reducing fragmentation? I guess you'd get
fewer annoying "holes" if you can compact memory, and better cache behaviour
if live objects tend to be nearer to each other.

~~~
foldr
pcwalton has been outlining the cons of Go's GC on HN for quite some time :)

[https://duckduckgo.com/?q=pcwalton+go+gc+site%3Aycombinator....](https://duckduckgo.com/?q=pcwalton+go+gc+site%3Aycombinator.com&t=he&ia=web)

------
obl
For a simple baseline JIT like that, you can improve the quality of the
generated code a lot at basically no compile-time cost (still one pass) by
doing some flavor of "destination driven code generation".

It also adds very little complexity to the compiler itself so it's a nice win.

------
kurtisc
I introduced myself to Rust by writing a compiler. It was a real trial-by-fire
thanks to how tree structures have to be handled with the borrow checker.

~~~
fasquoika
> It was a real trial-by-fire thanks to how tree structures have to be handled
> with the borrow checker.

Eh, without parent-pointers you can just use a Box<T> in the obvious way. For
more elaborate graphs you'd use arena allocation. Maybe not something a
beginner would realize, but it's not that hard

~~~
kurtisc
>without parent-pointers

Well I had them. As soon as I realised it wasn't trivial I wanted to know how
to do it and why it couldn't be trivial.

>Maybe not something a beginner would realize, but it's not that hard

It's OK to be bad at new things.

------
amelius
Just write an interpreter. Any compiler worth its salt will translate that
interpreter into a JIT. ;)

~~~
TomMarius
Can you give us some examples of such compilers that are worth their salt?

~~~
sanxiyn
Both PyPy and Truffle work this way.

