3 ms·
i am more interested in your AOT static Ruby Compiler, anything to share on that front?
by ksec 12y ago
i am more interested in your AOT static Ruby Compiler, anything to share on that front?
- vidarh 12y agohttp://www.hokstad.com/compiler http://www.hokstad.com/compiler Note that it is very unfinished, and I'm moving very slowly with it. I'm overdue for posting another blog post or two about it - I have two that just needs editing, and a third halfway done. At current pace I'm realistically hoping to be close to having it self hosted by christmas. (the big caveat of course being that getting it self-hosted is not the great indication of feature completeness it may sound like, since you get to cop out by not using constructs you don't feel like implementing yet) To be honest, it kind of veered off course from me just illustrating some low level techniques to quickly bootstrap a very primitive language, to me deciding I wanted to experiment with a Ruby compiler, and so the writing is all over the place. One of the things that motivates me apart from writing about it, is to try to figure out how dynamic Ruby really need to be, and how much static information you can "recover". On the surface, Ruby is notoriously tricky, because e.g. you can't tell based on local information even what piece of code will be called. E.g: t1 = Thread.new do loop do puts 4 + 5 sleep (1) end end sleep(rand(3)) class Fixnum def + other 42 end end t1.join It's no fun reasoning about that "puts 4+5" when even integer addition may suddenly stop working after a random interval... But of course in real life, most of the really hairy nastiness doesn't occur outside of scary examples (I've never seen anyone override stuff in Fixnum to do anything useful, for example), and could easily be documented as unsupported in an AOT compiler, allowing both making the code substantially more static, inferring types in quite large sections of programs eventually, and making it faster (as a side note, there's a Truffle based backend on the way for jRuby that achieves much of this by basically assuming the normal case in lot of situations, but "de-optimizing" when assumptions turn out to be wrong, which will get many of the benefits). I'm hoping to essentially find space where the compiler can basically declare "mostly safe" default behaviour, such as assuming nobody overrides Fixnum#+, and optimize for that, with switches or pragma's to re-enable "standard" behaviour for those cases where someone is in fact doing something really silly and expecting it to work.