Abstract
Dependently typed languages such as Coq are used to specify and prove functional correctness of source programs, but what we ultimately need are guarantees about correctness of compiled code. By preserving dependent types through each compiler pass, we could preserve source-level specifications and correctness proofs into the generated target-language programs. Unfortunately, type-preserving compilation of dependent types is hard. In 2002, Barthe and Uustalu showed that type-preserving CPS is not possible for languages such as Coq. Specifically, they showed that for strong dependent pairs (Σ types), the standard typed call-by-name CPS is not type preserving. They further proved that for dependent case analysis on sums, a class of typed CPS translations—including the standard translation—is not possible. In 2016, Morrisett noticed a similar problem with the standard call-by-value CPS translation for dependent functions (Π types). In essence, the problem is that the standard typed CPS translation by double-negation, in which computations are assigned types of the form (A → ⊥) → ⊥, disrupts the term/type equivalence that is used during type checking in a dependently typed language.
In this paper, we prove that type-preserving CPS translation for dependently typed languages is not not possible. We develop both call-by-name and call-by-value CPS translations from the Calculus of Constructions with both Π and Σ types (CC) to a dependently typed target language, and prove type preservation and compiler correctness of each translation. Our target language is CC extended with an additional equivalence rule and an additional typing rule, which we prove consistent by giving a model in the extensional Calculus of Constructions. Our key observation is that we can use a CPS translation that employs answer-type polymorphism, where CPS-translated computations have type ∀ α. (A → α) → α. This type justifies, by a free theorem, the new equality rule in our target language and allows us to recover the term/type equivalences that CPS translation disrupts. Finally, we conjecture that our translation extends to dependent case analysis on sums, despite the impossibility result, and provide a proof sketch.
Supplemental Material
Available for Download
Auxiliary material including a technical appendix with extended figure and proofs, and a Coq implementation of a key lemma.
- Martín Abadi. 1998. Protection in Programming-language Translations. In International Colloquium on Automata, Languages, and Programming. Google Scholar
Cross Ref
- Amal Ahmed. 2015. Verified Compilers for a Multi-Language World. In 1st Summit on Advances in Programming Languages (SNAPL 2015). Google Scholar
Cross Ref
- Amal Ahmed and Matthias Blume. 2008. Typed Closure Conversion Preserves Observational Equivalence. In International Conference on Functional Programming (ICFP). Google Scholar
Digital Library
- Amal Ahmed and Matthias Blume. 2011. An Equivalence-preserving CPS Translation Via Multi-language Semantics. In International Conference on Functional Programming (ICFP). Google Scholar
Digital Library
- Abhishek Anand, A. Appel, Greg Morrisett, Zoe Paraskevopoulou, Randy Pollack, Olivier Savary Bélanger, Matthieu Sozeau, and Matthew Weaver. 2017. CertiCoq: A Verified Compiler for Coq. In The International Workshop on Coq for Programming Languages (CoqPL). http://www.cs.princeton.edu/~appel/papers/certicoq- coqpl.pdfGoogle Scholar
- Andrew W. Appel. 2015. Verification of a Cryptographic Primitive: SHA-256. ACM Transactions on Programming Languages and Systems 37, 2 (April 2015). Google Scholar
Digital Library
- Gilles Barthe, Benjamin Grégoire, and Santiago Zanella-béguelin. 2009. Formal Certification of Code-based Cryptographic Proofs. In Symposium on Principles of Programming Languages (POPL). Google Scholar
Digital Library
- Gilles Barthe, John Hatcliff, and Morten Heine Sørensen. 2001. Weak Normalization Implies Strong Normalization in a Class of Non-dependent Pure Type Systems. Theoretical Computer Science 269, 1-2 (Oct. 2001). Google Scholar
Cross Ref
- Gilles Barthe, John Hatcliff, and Morten Heine B. Sørensen. 1999. CPS Translations and Applications: The Cube and Beyond. Higher-Order and Symbolic Computation 12, 2 (Sept. 1999). Google Scholar
Digital Library
- Gilles Barthe and Tarmo Uustalu. 2002. CPS Translating Inductive and Coinductive Types. In Workshop on Partial Evaluation and Semantics-based Program Manipulation (PEPM). Google Scholar
Digital Library
- Jean-philippe Bernardy, Patrik Jansson, and Ross Paterson. 2012. Proofs for Free: Parametricity for Dependent Types. Journal of Functional Programming 22, 02 (March 2012). Google Scholar
Digital Library
- Simon Boulier, Pierre-marie Pédrot, and Nicolas Tabareau. 2017. The Next 700 Syntactical Models of Type Theory. In Conference on Certified Programs and Proofs (CPP). Google Scholar
Digital Library
- William J. Bowman and Amal Ahmed. 2015. Noninterference for Free. In International Conference on Functional Programming (ICFP). Google Scholar
Digital Library
- William J. Bowman, Youyou Cong, Nick Rioux, and Amal Ahmed. 2017. Type-Preserving CPS Translation of Σ and Π Types Is Not Not Possible (Supplementary Materials. (Oct. 2017). https://williamjbowman.com/resources/cps- sigma.tar.gzGoogle Scholar
- Juan Chen, Ravi Chugh, and Nikhil Swamy. 2010. Type-preserving Compilation of End-to-end Verification of Security Enforcement. In International Conference on Programming Language Design and Implementation (PLDI). Google Scholar
Digital Library
- Jesper Cockx, Dominique Devriese, and Frank Piessens. 2016. Unifiers As Equivalences: Proof-relevant Unification of Dependently Typed Data. In International Conference on Functional Programming (ICFP). Google Scholar
Digital Library
- Thierry Coquand. 1986. An Analysis of Girard’s Paradox. In Symposium on Logic in Computer Science (LICS). https: //hal.inria.fr/inria- 00076023Google Scholar
- Thierry Coquand. 1989. Metamathematical Investigations of a Calculus of Constructions. Ph.D. Dissertation. INRIA. https: //hal.inria.fr/inria- 00075471Google Scholar
- Pierre-louis Curien and Hugo Herbelin. 2000. The Duality of Computation. In International Conference on Functional Programming (ICFP). Google Scholar
Digital Library
- Matthias Felleisen. 1991. On the Expressive Power of Programming Languages. Science of Computer Programming 17, 1-3 (Dec. 1991). Google Scholar
Digital Library
- Cormac Flanagan, Amr Sabry, Bruce F. Duba, and Matthias Felleisen. 1993. The Essence of Compiling with Continuations. In International Conference on Programming Language Design and Implementation (PLDI). Google Scholar
Digital Library
- Cedric Fournet, Nikhil Swamy, Juan Chen, Pierre-evariste Dagand, Pierre-yves Strub, and Benjamin Livshits. 2013. Fully Abstract Compilation to JavaScript. In Symposium on Principles of Programming Languages (POPL). Google Scholar
Digital Library
- Jan Herman Geuvers. 1993. Logics and Type Systems. Ph.D. Dissertation. University of Nijmegen. http://www.ru.nl/publish/ pages/682191/geuvers_jh.pdfGoogle Scholar
- Ronghui Gu, Jérémie Koenig, Tahina Ramananandro, Zhong Shao, Xiongnan (newman) Wu, Shu-chun Weng, Haozhong Zhang, and Yu Guo. 2015. Deep Specifications and Certified Abstraction Layers. In Symposium on Principles of Programming Languages (POPL). Google Scholar
Digital Library
- Hugo Herbelin. 2005. On the Degeneracy of Σ-Types in Presence of Computational Classical Logic. In International Conference on Typed Lambda Calculi and Applications. Google Scholar
Digital Library
- Hugo Herbelin. 2012. A Constructive Proof of Dependent Choice, Compatible with Classical Logic. In Symposium on Logic in Computer Science (LICS). Google Scholar
Digital Library
- James G. Hook and Douglas J. Howe. 1986. Impredicative Strong Existential Equivalent to Type:type. Technical Report. Cornell University. http://hdl.handle.net/1813/6600Google Scholar
Digital Library
- Jeehoon Kang, Yoonseung Kim, Chung-kil Hur, Derek Dreyer, and Viktor Vafeiadis. 2016. Lightweight Verification of Separate Compilation. In Symposium on Principles of Programming Languages (POPL). Google Scholar
Digital Library
- Chantal Keller and Marc Lasson. 2012. Parametricity in an Impredicative Sort. In International Workshop on Computer Science Logic (CSL). https://hal.inria.fr/hal- 00730913Google Scholar
- Andrew Kennedy. 2006. Securing the .NET Programming Model. Theoretical Computer Science 364, 3 (Nov. 2006). Google Scholar
Digital Library
- Andrew Kennedy. 2007. Compiling with Continuations, Continued. In International Conference on Functional Programming (ICFP). Google Scholar
Digital Library
- Neelakantan R. Krishnaswami and Derek Dreyer. 2013. Internalizing Relational Parametricity in the Extensional Calculus of Constructions. In International Workshop on Computer Science Logic (CSL). Google Scholar
Cross Ref
- Xavier Leroy. 2006. Formal Certification of a Compiler Back-end or: Programming a Compiler with a Proof Assistant. In Symposium on Principles of Programming Languages (POPL). Google Scholar
Digital Library
- Xavier Leroy. 2009. A Formally Verified Compiler Back-end. Journal of Automated Reasoning 43, 4 (Nov. 2009). Google Scholar
Digital Library
- Jacob Matthews and Robert Bruce Findler. 2007. Operational semantics for multi-language programs. In Symposium on Principles of Programming Languages (POPL). Google Scholar
Digital Library
- Luke Maurer, Paul Downen, Zena M. Ariola, and Simon L. Peyton Jones. 2017. Compiling without Continuations. In International Conference on Programming Language Design and Implementation (PLDI). Google Scholar
Digital Library
- Georg Neis, Chung-kil Hur, Jan-oliver Kaiser, Craig Mclaughlin, Derek Dreyer, and Viktor Vafeiadis. 2015. Pilsner: A Compositionally Verified Compiler for a Higher-order Imperative Language. In International Conference on Functional Programming (ICFP). Google Scholar
Digital Library
- Max S. New, William J. Bowman, and Amal Ahmed. 2016. Fully Abstract Compilation Via Universal Embedding. In International Conference on Functional Programming (ICFP). Google Scholar
Digital Library
- Andreas Nuyts, Andrea Vezzosi, and Dominique Devriese. 2017. Parametric Quantifiers for Dependent Type Theory. Proceedings of the ACM on Programming Languages 1, ICFP (Aug. 2017). Google Scholar
Digital Library
- Marco Patrignani, Pieter Agten, Raoul Strackx, Bart Jacobs, Dave Clarke, and Frank Piessens. 2015. Secure Compilation to Protected Module Architectures. ACM Transactions on Programming Languages and Systems 37, 2, Article 6 (April 2015). Google Scholar
Digital Library
- Daniel Patterson and Amal Ahmed. 2017. Linking Types for Multi-Language Software: Have Your Cake and Eat It Too. In 2nd Summit on Advances in Programming Languages (SNAPL 2017). Google Scholar
Cross Ref
- Daniel Patterson, Jamie Perconti, Christos Dimoulas, and Amal Ahmed. 2017. FunTAL: Reasonably Mixing a Functional Language with Assembly. In International Conference on Programming Language Design and Implementation (PLDI). http://www.ccs.neu.edu/home/amal/papers/funtal.pdfGoogle Scholar
Digital Library
- Pierre-marie Pédrot and Nicolas Tabareau. 2017. An Effectful Way to Eliminate Addiction to Dependence. In Symposium on Logic in Computer Science (LICS). Google Scholar
Cross Ref
- James T. Perconti and Amal Ahmed. 2014. Verifying an Open Compiler Using Multi-language Semantics. In European Symposium on Programming (ESOP). Google Scholar
Digital Library
- Zhong Shao, Valery Trifonov, Bratin Saha, and Nikolaos Papaspyrou. 2005. A Type System for Certified Binaries. ACM Transactions on Programming Languages and Systems 27, 1 (Jan. 2005). Google Scholar
Digital Library
- Matthieu Sozeau and Nicolas Tabareau. 2014. Universe Polymorphism in Coq. In International Conference on Interactive Theorem Proving (ITP). Google Scholar
Cross Ref
- The Coq Development Team. 2017. The Coq Proof Assistant Reference Manual. (Oct. 2017). https://coq.inria.fr/doc/ Reference- Manual006.htmlGoogle Scholar
- Hayo Thielecke. 2003. From Control Effects to Typed Continuation Passing. In Symposium on Principles of Programming Languages (POPL). Google Scholar
Digital Library
- Hayo Thielecke. 2004. Answer Type Polymorphism in Call-by-name Continuation Passing. In European Symposium on Programming (ESOP). Google Scholar
Cross Ref
Index Terms
Type-preserving CPS translation of Σ and Π types is not not possible
Recommendations
Parametric quantifiers for dependent type theory
Polymorphic type systems such as System F enjoy the parametricity property: polymorphic functions cannot inspect their type argument and will therefore apply the same algorithm to any type they are instantiated on. This idea is formalized mathematically ...
CPS translating inductive and coinductive types
We investigate CPS translatability of typed λ-calculi with inductive and coinductive types. We show that tenable Plotkin-style call-by-name CPS translations exist for simply typed λ-calculi with a natural number type and stream types and, more generally,...
CPS translating inductive and coinductive types
PEPM '02: Proceedings of the 2002 ACM SIGPLAN workshop on Partial evaluation and semantics-based program manipulationWe investigate CPS translatability of typed λ-calculi with inductive and coinductive types. We show that tenable Plotkin-style call-by-name CPS translations exist for simply typed λ-calculi with a natural number type and stream types and, more generally,...






Comments