Skip to main content

A systematic derivation of the STG machine verified in Coq

Maciej Pirog and Dariusz Biernacki

Abstract

Shared Term Graph (STG) is a lazy functional language used as an intermediate language in the Glasgow Haskell Compiler (GHC). In this article, we present a natural operational semantics for STG and we mechanically derive a lazy abstract machine from this semantics, which turns out to coincide with Peyton-Jones and Salkild's Spineless Tagless G-machine (STG machine) used in GHC. Unlike other constructions of STG-like machines present in the literature, ours is based on a systematic and scalable derivation method (inspired by Danvy et al.'s functional correspondence between evaluators and abstract machines) and it leads to an abstract machine that differs from the original STG machine only in inessential details. In particular, it handles non-trivial update scenarios and partial applications identically as the STG machine.

The entire derivation has been formalized in the Coq proof assistant. Thus, in effect, we provide a machine checkable proof of the correctness of the STG machine with respect to the natural semantics.

Address
New York‚ NY‚ USA
Book Title
Haskell '10: Proceedings of the third ACM Haskell symposium on Haskell
ISBN
978−1−4503−0252−4
Location
Baltimore‚ Maryland‚ USA
Pages
25–36
Publisher
ACM
Year
2010