Hacker News new | ask | show | jobs
by larsberg 5467 days ago
A lot has changed. If you're looking at other strongly-typed functional language, particularly if you don't have to handle laziness, Compiling with Continuations is a fantastic book (http://www.amazon.com/Compiling-Continuations-Andrew-W-Appel... ).

There is still a lot that has changed since then. In particular:

1) Control-flow analysis has become much more well-understood, and there's a lot more you can do in your optimization phases to dramatically speed up code and reduce allocations (allocations and heap accesses are the bane of functional language implementation, btw. Unless you're Haskell, and then you also have to deal with mutation for shared lazy computation results).

2) Certain tricks such as monomorphisation (http://mlton.org/Monomorphise ) dramatically improve the ability of the compiler to generate optimized code from originally polymorphic inputs without paying huge representation overheads.

Unfortunately, #1 and #2 are mainly written up "in the source" of modern functional language compilers or at best in JFP (Journal of Functional Programming) articles :-( But the Appel book provides most of the fundamentals you'll need to get bootstrapped with anything more modern, so I'd recommend it anyway!

1 comments

Which papers do you recommend about this subject, for reading after the Appel book?

Something that I found interesting is that polymorthic types on .NET are also implemented with monomorphisation.

If you are still interested in learning more about writing compiler optimizations after reading the Appel book, there are two really fantastic Ph.D. theses:

Olin Shivers, Control Flow Analysis in Scheme

David Tarditi, Design and Implementation of Code Optimizations for a Type-Directed Compiler for Standard ML

The first can be a bit mathematically hairy, particularly if you have either a weak or engineering-focused math background. Fortunately, you can skip it and still get a lot out of both the static analyses and particularly the optimizations listed at the back. There are several he lists that still offer promise and that folks are even now trying to figure out how to implement efficiently (i.e. super-beta).

The second is a wonderful implementation-focused thesis that covers in even more detail than the Appel book how to perform those optimizations on a typed IR. A typed IR is much tougher than an untyped IR because in order to maintain a valid IR can be quite tricky (i.e. if you change a function to take an additional argument, you need to update its type... and everywhere that type occurs, including possible in tuples passed to functions that pass them to other functions, etc.). Further, he includes proofs of correctness that will prepare you for the kinds of things that appear in more modern coverage of compiler optimizations.

Beyond that, getting to specific journal papers, you really can't go wrong just browsing TOPLAS and JFP and looking at particular topics you're interested in. There are some that are, of course, particularly good, but generally the editorial staff on both is just fantastic and you can't go wrong. If you have specific interests, feel free to drop me mail directly for a pointer to a good entry paper in the area.