skip to main content
research-article
Open Access

Type-preserving CPS translation of Σ and Π types is not not possible

Published:27 December 2017Publication History
Skip Abstract Section

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.

Skip Supplemental Material Section

Supplemental Material

typepreservingcps.webm

References

  1. Martín Abadi. 1998. Protection in Programming-language Translations. In International Colloquium on Automata, Languages, and Programming. Google ScholarGoogle ScholarCross RefCross Ref
  2. Amal Ahmed. 2015. Verified Compilers for a Multi-Language World. In 1st Summit on Advances in Programming Languages (SNAPL 2015). Google ScholarGoogle ScholarCross RefCross Ref
  3. Amal Ahmed and Matthias Blume. 2008. Typed Closure Conversion Preserves Observational Equivalence. In International Conference on Functional Programming (ICFP). Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Amal Ahmed and Matthias Blume. 2011. An Equivalence-preserving CPS Translation Via Multi-language Semantics. In International Conference on Functional Programming (ICFP). Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. 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 ScholarGoogle Scholar
  6. Andrew W. Appel. 2015. Verification of a Cryptographic Primitive: SHA-256. ACM Transactions on Programming Languages and Systems 37, 2 (April 2015). Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  8. 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 ScholarGoogle ScholarCross RefCross Ref
  9. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  10. Gilles Barthe and Tarmo Uustalu. 2002. CPS Translating Inductive and Coinductive Types. In Workshop on Partial Evaluation and Semantics-based Program Manipulation (PEPM). Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  12. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  13. William J. Bowman and Amal Ahmed. 2015. Noninterference for Free. In International Conference on Functional Programming (ICFP). Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. 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 ScholarGoogle Scholar
  15. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  16. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  17. Thierry Coquand. 1986. An Analysis of Girard’s Paradox. In Symposium on Logic in Computer Science (LICS). https: //hal.inria.fr/inria- 00076023Google ScholarGoogle Scholar
  18. Thierry Coquand. 1989. Metamathematical Investigations of a Calculus of Constructions. Ph.D. Dissertation. INRIA. https: //hal.inria.fr/inria- 00075471Google ScholarGoogle Scholar
  19. Pierre-louis Curien and Hugo Herbelin. 2000. The Duality of Computation. In International Conference on Functional Programming (ICFP). Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. Matthias Felleisen. 1991. On the Expressive Power of Programming Languages. Science of Computer Programming 17, 1-3 (Dec. 1991). Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  22. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  23. Jan Herman Geuvers. 1993. Logics and Type Systems. Ph.D. Dissertation. University of Nijmegen. http://www.ru.nl/publish/ pages/682191/geuvers_jh.pdfGoogle ScholarGoogle Scholar
  24. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  25. Hugo Herbelin. 2005. On the Degeneracy of Σ-Types in Presence of Computational Classical Logic. In International Conference on Typed Lambda Calculi and Applications. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. Hugo Herbelin. 2012. A Constructive Proof of Dependent Choice, Compatible with Classical Logic. In Symposium on Logic in Computer Science (LICS). Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  28. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  29. 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 ScholarGoogle Scholar
  30. Andrew Kennedy. 2006. Securing the .NET Programming Model. Theoretical Computer Science 364, 3 (Nov. 2006). Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. Andrew Kennedy. 2007. Compiling with Continuations, Continued. In International Conference on Functional Programming (ICFP). Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. 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 ScholarGoogle ScholarCross RefCross Ref
  33. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  34. Xavier Leroy. 2009. A Formally Verified Compiler Back-end. Journal of Automated Reasoning 43, 4 (Nov. 2009). Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. Jacob Matthews and Robert Bruce Findler. 2007. Operational semantics for multi-language programs. In Symposium on Principles of Programming Languages (POPL). Google ScholarGoogle ScholarDigital LibraryDigital Library
  36. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  37. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  38. Max S. New, William J. Bowman, and Amal Ahmed. 2016. Fully Abstract Compilation Via Universal Embedding. In International Conference on Functional Programming (ICFP). Google ScholarGoogle ScholarDigital LibraryDigital Library
  39. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  40. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  41. 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 ScholarGoogle ScholarCross RefCross Ref
  42. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  43. 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 ScholarGoogle ScholarCross RefCross Ref
  44. James T. Perconti and Amal Ahmed. 2014. Verifying an Open Compiler Using Multi-language Semantics. In European Symposium on Programming (ESOP). Google ScholarGoogle ScholarDigital LibraryDigital Library
  45. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  46. Matthieu Sozeau and Nicolas Tabareau. 2014. Universe Polymorphism in Coq. In International Conference on Interactive Theorem Proving (ITP). Google ScholarGoogle ScholarCross RefCross Ref
  47. The Coq Development Team. 2017. The Coq Proof Assistant Reference Manual. (Oct. 2017). https://coq.inria.fr/doc/ Reference- Manual006.htmlGoogle ScholarGoogle Scholar
  48. Hayo Thielecke. 2003. From Control Effects to Typed Continuation Passing. In Symposium on Principles of Programming Languages (POPL). Google ScholarGoogle ScholarDigital LibraryDigital Library
  49. Hayo Thielecke. 2004. Answer Type Polymorphism in Call-by-name Continuation Passing. In European Symposium on Programming (ESOP). Google ScholarGoogle ScholarCross RefCross Ref

Index Terms

  1. Type-preserving CPS translation of Σ and Π types is not not possible

              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

              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!