skip to main content
research-article

A systematic derivation of the STG machine verified in Coq

Published:30 September 2010Publication History
Skip Abstract Section

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.

Skip Supplemental Material Section

Supplemental Material

haskell-1030-pirog.mov

References

  1. }}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 ScholarGoogle Scholar
  2. }}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 ScholarGoogle ScholarDigital LibraryDigital Library
  3. }}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 ScholarGoogle ScholarDigital LibraryDigital Library
  4. }}Alberto de la Encina and Ricardo Peña. Formally deriving an STG machine. In Miller {9}, pages 102--112. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. }}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 ScholarGoogle ScholarDigital LibraryDigital Library
  6. }}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 ScholarGoogle ScholarDigital LibraryDigital Library
  7. }}Haskell homepage: http://www.haskell.org.Google ScholarGoogle Scholar
  8. }}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 ScholarGoogle ScholarDigital LibraryDigital Library
  9. }}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 ScholarGoogle Scholar
  10. }}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 ScholarGoogle ScholarDigital LibraryDigital Library
  11. }}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 ScholarGoogle ScholarCross RefCross Ref
  12. }}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 ScholarGoogle ScholarDigital LibraryDigital Library
  13. }}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 ScholarGoogle ScholarDigital LibraryDigital Library
  14. }}John C. Reynolds. Definitional interpreters revisited. Higher-Order and Symbolic Computation, 11(4):355--361, 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. }}Peter Sestoft. Deriving a lazy abstract machine. Journal of Functional Programming, 7(3):231--264, May 1997. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. A systematic derivation of the STG machine verified in Coq

        Recommendations

        Comments

        Login options

        Check if you have access through your login credentials or your institution to get full access on this article.

        Sign in

        Full Access

        • Published in

          cover image ACM SIGPLAN Notices
          ACM SIGPLAN Notices  Volume 45, Issue 11
          HASKELL '10
          November 2010
          156 pages
          ISSN:0362-1340
          EISSN:1558-1160
          DOI:10.1145/2088456
          Issue’s Table of Contents
          • cover image ACM Conferences
            Haskell '10: Proceedings of the third ACM Haskell symposium on Haskell
            September 2010
            166 pages
            ISBN:9781450302524
            DOI:10.1145/1863523

          Copyright © 2010 ACM

          Publisher

          Association for Computing Machinery

          New York, NY, United States

          Publication History

          • Published: 30 September 2010

          Check for updates

          Qualifiers

          • research-article

        PDF Format

        View or Download as a PDF file.

        PDF

        eReader

        View online with eReader.

        eReader
        About Cookies On This Site

        We use cookies to ensure that we give you the best experience on our website.

        Learn more

        Got it!