Previous Up Next

2  Features of MLton

whole-program optimization
       
Because MLton compiles the whole program at once, it can perform optimization across module boundaries. As a consequence, MLton often reduces or eliminates the run-time penalty that arises with separate compilation of SML features such as functors, modules, polymorphism, and higher-order functions. MLton takes advantage of having the entire program to perform transformations such as: defunctorization, monomorphisation, higher-order control-flow analysis, inlining, unboxing, argument flattening, redundant-argument removal, constant folding, and representation selection. Whole-program compilation is an integral part of the design of MLton and is not likely to change.

supports the full SML 97 language
       
MLton compiles the Standard ML language as given in The Definition of Standard ML (Revised)[MTHM97]. If there is a program that is valid according to The Definition that is rejected by MLton, or a program that is invalid according to the Definition that is accepted by MLton, it is a bug. For a list of known bugs, see Section 15.

complete basis library
       
MLton implements the latest Standard ML basis library specification, with a complete implementation of all the required modules, as well as many of the optional modules. See Section 9 for details.

excellent running times
       
MLton generates executables with excellent running times. For a comparison with other SML compilers, see http://www.mlton.org/performance.html. For a comparison of compilers for many languages, see http://shootout.alioth.debian.org/.

native integers, reals, and words
       
In MLton, integers and words are 32 bits and arithmetic does not have any overhead due to tagging. Also, reals are stored unboxed, avoiding any overhead due to boxing.

unboxed native arrays
       
In MLton, an array (or vector) of integers, reals, or words uses the natural C-like representation. This is fast and supports easy exchange of data with C. Monomorphic arrays (and vectors) use the same C-like representations as their polymorphic counterparts.

runtime system supports large arrays
       
In MLton, array lengths can be up to 231 - 1, the largest possible twos-complement 32 bit integer.

support for large files
       
In MLton, file positions and sizes are 64-bit integers, so files can be as large as is supported by the underlying platform.

several garbage collection strategies
       
The MLton runtime system uses copying, mark-compact, and generational collection, automatically deciding which to use based on the amount of live data relative to the amount of RAM. The runtime system tries to keep the heap within RAM if at all possible.

standalone executables
       
MLton generates standalone executables. No additional code or libraries are necessary in order to run an executable, except for the standard shared libraries. MLton can also generate statically linked executables.

small executables
       
Because of whole-program compilation, MLton can use very aggressive dead-code elimination, which often leads to smaller executables than with other SML compilers.

compiles large programs
       
MLton is sufficiently efficient and robust that it can compile large programs, including itself (over 100K lines). The distributed version of MLton was compiled by MLton.

fast IntInf based on GNU multiprecision library
       
The MLton implementation of arbitrary precision arithmetic (the IntInf structure) uses the GNU multiprecision library (GNUmp). Hence, for IntInf intensive programs, MLton can be an order of magnitude or more faster than Poly/ML or SML/NJ.

simple and fast C FFI
       
MLton has a straightforward and fast FFI for calling from SML to C and from C to SML. See Section 6 for details.

source-level profiling of allocation and time
       
MLton and mlprof provide source-level profiling information. See Section 7 for details.

useful libraries
       
MLton has a collection of libraries that provide useful functionality that cannot be implemented with the standard basis library. See below for an overview and Section 10 for details.
continuations
       
MLton supports continuations via callcc and throw.

finalization
       
MLton supports finalizable values of arbitrary type.

interval timers
       
MLton supports the functionality of the C setitimer function.

random numbers
       
MLton has functions similar to the C rand and srand functions, as well as support for access to /dev/random and /dev/urandom.

resource limits
       
MLton has functions similar to the C getrlimit and setrlimit functions.

resource usage
       
MLton supports a subset of the functionality of the C getrusage function.

signal handlers
       
MLton supports signal handlers written in SML. Signal handlers run in a separate MLton thread, and have access to the thread that was interrupted by the signal. Signal handlers can be used in conjunction with threads to implement preemptive multitasking.

size primitive
       
MLton includes a primitive that returns the size (in bytes) of any object. This can be useful in understanding the space behavior of a program.

system logging
       
MLton has a complete interface to the C syslog function.

threads
       
MLton has support for its own threads, upon which either preemptive or non-preemptive multitasking can be implemented. At some point in the future, MLton will support Concurrent ML (CML).

weak pointers
       
MLton suports weak pointers, which allow the garbage collector to reclaim objects that it would otherwise be forced to keep. Weak pointers are also used to provide finalization.

world save and restore
       
MLton has a facility for saving the entire state of a computation to a file and restarting it later. This facility can be used for staging and for checkpointing computations. It can even be used from within signal handlers, allowing interrupt driven checkpointing.


Previous Up Next