Page Status: work in progress
GRIN is a compiler backend and an intermediate language.
The goal is to bring the benefits of whole program analysis and optimization for functional languages especially Haskell.
The main benefits are:
- smaller executables (more accurate dead code elimination)
faster programs (better strictness analysis and unboxing)
- utilize recent pointer analysis and control flow analisis results, useful for:
- generate much smaller binaries (better dead code elimination)
- compile faster programs (better strictness analysis)
The project aim is to provide easy to use compiler backend with convenient intermediate language and framework.
HIGHLIGHT: whole program analysis and optimization
- analyse real world programs (GHC/GRIN ; STG/Lambda export)
Urban Boquist’s PhD thesis on Code Optimisation Techniques for Lazy Functional Languages .
Paper: A modern look at GRIN, an optimizing functional language back end
- update tech to use the most recent research results: Souffle/datalog, P4F, Steensgaard based points-to analysis
- update GRIN IR: introduce basic blocks
It is crutial to use GHC as a Haskel frontend to support the widest range of libraries. GHC/GRIN is GHC is patched to emit STG representation. The STG modules are linked together and processed by the GRIN compiler.
GHC does incremental (per module) compilation. That was the best design decision back then.
The goal of the GRIN project is to explore the design space of whole program optimization an unleash the performance and tooling benefits of it.
GHC/GRIN is a Haskel frontend with the standard tooling support: Cabal and Stack.
Compiling from STG linking the whole program into a single STG file.
Whole program optimization and interprocedural dead code elimination.
Generates small binaries.
No RTS yet. We need to build a new RTS from scratch supporting every GHC primop. TODO: why we need a new RTS.
- WASM support
- basic GHC primops (i.e. arithmetic, arrays, refs)
- tooling (profiler, debugger)
- GC implementation
- full GHC primops
Working backend, with multiple sample programs.
Initial stub exists.
- Souffle: efficient datalog compiler for performant program analyses
- P4F: advanced control flow analysis for whole program defunctionalization
- HRC / Measuring the Haskell Gap: research compiler that showed the potential of whole program optimization for modern Haskell
- MLton: leading industrial strength whole program compiler for SML
- ASAP Memory Management
- HRC vectorisation
- LLVM type system
- use Gibbon transformations to obtain packed data representation