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.
Supplemental Material
- }}Mads Sig Ager, Dariusz Biernacki, Olivier Danvy, and Jan Midtgaard. A functional correspondence between evaluators and abstract machines. In Miller {9}, pages 8--19.Google Scholar
- }}Mads Sig Ager, Olivier Danvy, and Jan Midtgaard. A functional correspondence between call-by-need evaluators and lazy abstract machines. Information Processing Letters, 90(5):223--232, 2004. Google Scholar
Digital Library
- }}Olivier Danvy and Lasse R. Nielsen. Defunctionalization at work. In Harald Søndergaard, editor, Proceedings of the Third International ACM SIGPLAN Conference on Principles and Practice of Declarative Programming (PPDP'01), pages 162--174, Firenze, Italy, September 2001. ACM Press. Google Scholar
Digital Library
- }}Alberto de la Encina and Ricardo Peña. Formally deriving an STG machine. In Miller {9}, pages 102--112. Google Scholar
Digital Library
- }}Alberto de la Encina and Ricardo Peña. Proving the correctness of the STG machine. In Ricardo Pena and Thomas Arts, editors, IFL, volume 2670 of Lecture Notes in Computer Science, pages 88--104. Springer, 2003. Google Scholar
Digital Library
- }}Alberto de la Encina and Ricardo Peña. From natural semantics to C: A formal derivation of two STG machines. Journal of Functional Programming, 19(1):47--94, 2009. Google Scholar
Digital Library
- }}Haskell homepage: http://www.haskell.org.Google Scholar
- }}John Launchbury. A natural semantics for lazy evaluation. In Susan L. Graham, editor, Proceedings of the Twentieth Annual ACM Symposium on Principles of Programming Languages, pages 144--154, Charleston, South Carolina, January 1993. ACM Press. Google Scholar
Digital Library
- }}Dale Miller, editor. Proceedings of the Fifth ACM-SIGPLAN International Conference on Principles and Practice of Declarative Programming (PPDP'03), Uppsala, Sweden, August 2003. ACM Press.Google Scholar
- }}Jon Mountjoy. The spineless tagless G-machine, naturally. In Paul Hudak and Christian Queinnec, editors, Proceedings of the 1998 ACM SIGPLAN International Conference on Functional Programming, SIGPLAN Notices, Vol. 34, No. 1, pages 163--173, Baltimore, Maryland, September 1998. ACM Press. Google Scholar
Digital Library
- }}Simon L. Peyton Jones. Implementing lazy functional languages on stock hardware: The spineless tagless G-machine. Journal of Functional Programming, 2(2):127--202, 1992.Google Scholar
Cross Ref
- }}Simon L. Peyton Jones and Jon Salkild. The spineless tagless G-machine. In Joseph E. Stoy, editor, Proceedings of the Fourth International Conference on Functional Programming and Computer Architecture, pages 184--201, London, England, September 1989. ACM Press. Google Scholar
Digital Library
- }}John C. Reynolds. Definitional interpreters for higher-order programming languages. In Proceedings of 25th ACM National Conference, pages 717--740, Boston, Massachusetts, 1972. Reprinted in Higher-Order and Symbolic Computation 11(4):363--397, 1998, with a foreword {14}. Google Scholar
Digital Library
- }}John C. Reynolds. Definitional interpreters revisited. Higher-Order and Symbolic Computation, 11(4):355--361, 1998. Google Scholar
Digital Library
- }}Peter Sestoft. Deriving a lazy abstract machine. Journal of Functional Programming, 7(3):231--264, May 1997. Google Scholar
Digital Library
Index Terms
A systematic derivation of the STG machine verified in Coq
Recommendations
A systematic derivation of the STG machine verified in Coq
Haskell '10: Proceedings of the third ACM Haskell symposium on HaskellShared 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 ...
Completeness and decidability of converse PDL in the constructive type theory of Coq
CPP 2018: Proceedings of the 7th ACM SIGPLAN International Conference on Certified Programs and ProofsThe completeness proofs for Propositional Dynamic Logic (PDL) in the literature are non-constructive and usually presented in an informal manner. We obtain a formal and constructive completeness proof for Converse PDL by recasting a completeness proof ...
Call-by-push-value in Coq: operational, equational, and denotational theory
CPP 2019: Proceedings of the 8th ACM SIGPLAN International Conference on Certified Programs and ProofsCall-by-push-value (CBPV) is an idealised calculus for functional and imperative programming, introduced as a subsuming paradigm for both call-by-value (CBV) and call-by-name (CBN). We formalise weak and strong operational semantics for (effect-free) ...







Comments