Compiling with continuations, correctly
Authors:
Open Access
- 15 October 2021
- journal article
- research article
- Published by Association for Computing Machinery (ACM) in Proceedings of the ACM on Programming Languages
- Vol. 5 (OOPSLA) , 1-29
Abstract
In this paper we present a novel simulation relation for proving correctness of program transformations that combines syntactic simulations and logical relations. In particular, we establish a new kind of simulation diagram that uses a small-step or big-step semantics in the source language and an untyped, step-indexed logical relation in the target language. Our technique provides a practical solution for proving semantics preservation for transformations that do not preserve reductions in the source language. This is common when transformations generate new binder names, and hence α-conversion must be explicitly accounted for, or when transformations introduce administrative redexes. Our technique does not require reductions in the source language to correspond directly to reductions in the target language. Instead, we enforce a weaker notion of semantic preorder, which suffices to show that semantics are preserved for both whole-program and separate compilation. Because our logical relation is transitive, we can transition between intermediate program states in a small-step fashion and hence the shape of the proof resembles that of a simple small-step simulation. We use this technique to revisit the semantic correctness of a continuation-passing style (CPS) transformation and we demonstrate how it allows us to overcome well-known complications of this proof related to α-conversion and administrative reductions. In addition, by using a logical relation that is indexed by invariants that relate the resource consumption of two programs, we are able show that the transformation preserves diverging behaviors and that our CPS transformation asymptotically preserves the running time of the source program. Our results are formalized in the Coq proof assistant. Our continuation-passing style transformation is part of the CertiCoq compiler for Gallina, the specification language of Coq.Keywords
Funding Information
- NSF (CCF-1521602 and 2030859)
This publication has 26 references indexed in Scilit:
- Imperative self-adjusting computationACM SIGPLAN Notices, 2008
- Compiling with continuations, continuedACM SIGPLAN Notices, 2007
- A certified type-preserving compiler from lambda calculus to assembly languageACM SIGPLAN Notices, 2007
- A first-order one-pass CPS transformationTheoretical Computer Science, 2003
- An indexed model of recursive types for foundational proof-carrying codeACM Transactions on Programming Languages and Systems, 2001
- From system F to typed assembly languageACM Transactions on Programming Languages and Systems, 1999
- Shrinking lambda expressions in linear timeJournal of Functional Programming, 1997
- Representing Control: a Study of the CPS TransformationMathematical Structures in Computer Science, 1992
- Reasoning about programs in continuation-passing style.ACM SIGPLAN Lisp Pointers, 1992
- ORBIT: an optimizing compiler for schemeACM SIGPLAN Notices, 1986