Raj Bandyopadhyay, Compiling dynamic languages via statically typed functional languages

Dynamic languages enable rapid prototyping, while statically typed languages offer early error-detection and efficient execution. As a result, the usual practice in software development is to build a prototype in a dynamic language and then rewrite the application in C or Fortran for high performance. This costly rewriting step can be avoided if we can obtain better performance for dynamic languages. Dynamic languages are usually interpreted for faster implementation. The traditional approach to improve their performance is to build an optimizing compiler from scratch. Building a correct compiler, followed by platform and hardware specific optimizations, is a time-consuming process. Our thesis is that we can build fast compilers for dynamic languages by translating them to a statically typed functional language with an efficient compiler and automatic memory management. To test this theory, we have built a compiler for Python, a dynamic language, by translating it to OCaml, a statically typed functional language. Our implementation currently provides a speedup relative to the standard Python implementation for over 50% of a 370-benchmark suite.

We have shown that a Hindley-Milner typed language such as OCaml can be effectively used as the target language of a compiler. The translation from Python to OCaml is a concise representation of Python semantics. Our approach not only increases programmer productivity by improving performance of dynamic languages, but also provides language developers with an effective technique for building efficient compilers.