skip to main content

Intrinsically typed compilation with nameless labels

Authors Info & Claims
Published:04 January 2021Publication History
Skip Abstract Section

Abstract

To avoid compilation errors it is desirable to verify that a compiler is type correct—i.e., given well-typed source code, it always outputs well-typed target code. This can be done intrinsically by implementing it as a function in a dependently typed programming language, such as Agda. This function manipulates data types of well-typed source and target programs, and is therefore type correct by construction. A key challenge in implementing an intrinsically typed compiler is the representation of labels in bytecode. Because label names are global, bytecode typing appears to be inherently a non-compositional, whole-program property. The individual operations of the compiler do not preserve this property, which requires the programmer to reason about labels, which spoils the compiler definition with proof terms.

In this paper, we address this problem using a new nameless and co-contextual representation of typed global label binding, which is compositional. Our key idea is to use linearity to ensure that all labels are defined exactly once. To write concise compilers that manipulate programs in our representation, we develop a linear, dependently typed, shallowly embedded language in Agda, based on separation logic. We show that this language enables the concise specification and implementation of intrinsically typed operations on bytecode, culminating in an intrinsically typed compiler for a language with structured control-flow.

References

  1. Andreas Abel. 2020. Type-preserving compilation via dependently typed syntax in Agda. Abstract of a talk at TYPES, available online at http://www.cse.chalmers.se/~abela/types20.pdf, slides available online at http://www.cse.chalmers.se/ ~abela/talkTYPES2020.pdf.Google ScholarGoogle Scholar
  2. Thorsten Altenkirch, James Chapman, and Tarmo Uustalu. 2015. Monads need not be endofunctors. Logical Methods in Computer Science (LMCS) 11, 1 ( 2015 ). https://doi.org/10.2168/LMCS-11 ( 1 :3) 2015 Google ScholarGoogle ScholarCross RefCross Ref
  3. Davide Ancona, Ferruccio Damiani, Sophia Drossopoulou, Elena Zucca, et al. 2004. Even more principal typings for Java-like languages. In Formal Techniques for Java-like Programs Workshop (FTfJP).Google ScholarGoogle Scholar
  4. Andrew W. Appel. 2001. Foundational proof-carrying code. In Logic in Computer Science (LICS). 247-256. https://doi.org/10. 1109/LICS. 2001.932501 Google ScholarGoogle ScholarCross RefCross Ref
  5. Andrew W. Appel. 2006. Compiling with continuations. Cambridge University Press. https://doi.org/10.1017/ CBO9780511609619 Google ScholarGoogle Scholar
  6. Robert Atkey. 2009. Parameterised notions of computation. Journal of Functional Programming (JFP) 19, 3-4 ( 2009 ), 335-376. https://doi.org/10.1017/S095679680900728X Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Robert Atkey. 2018. Syntax and semantics of quantitative type theory. In Logic in Computer Science (LICS). 56-65. https: //doi.org/10.1145/3209108.3209189 Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Lennart Augustsson and Magnus Carlsson. 1999. An exercise in dependent types: A well-typed interpreter. In Workshop on Dependent Types in Programming.Google ScholarGoogle Scholar
  9. Olivier Savary Bélanger, Stefan Monnier, and Brigitte Pientka. 2015. Programming type-safe transformations using higherorder abstract syntax. Journal of Formalized Reasoning (JFR) 8, 1 ( 2015 ), 49-91. https://doi.org/10.6092/issn.1972-5787 / 5122 Google ScholarGoogle ScholarCross RefCross Ref
  10. Nick Benton, Chung-Kil Hur, Andrew Kennedy, and Conor McBride. 2012. Strongly typed term representations in Coq. Journal of Automated Reasoning (JAR) 49, 2 ( 2012 ). https://doi.org/10.1007/s10817-011-9219-0 Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Jean-Philippe Bernardy, Mathieu Boespflug, Ryan R. Newton, Simon Peyton Jones, and Arnaud Spiwack. 2018. Linear Haskell: Practical linearity in a higher-order polymorphic language. PACMPL 2, ACM SIGPLAN Symposium on Principle of Programming Languages (POPL) ( 2018 ), 5 : 1-5 : 29. https://doi.org/10.1145/3158093 Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Edwin Brady. 2013. Idris, a general-purpose dependently typed programming language: Design and implementation. The Journal of Functional Programming (JFP) 23, 5 ( 2013 ), 552. https://doi.org/10.1017/S095679681300018X Google ScholarGoogle ScholarCross RefCross Ref
  13. Edwin C. Brady and Kevin Hammond. 2012. Resource-safe systems programming with embedded domain specific languages. In Practical Aspects of Declarative Languages (PADL). 242-257. https://doi.org/10.1007/978-3-642-27694-1_18 Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Cristiano Calcagno, Peter W. O'Hearn, and Hongseok Yang. 2007. Local Action and Abstract Separation Logic. In Logic in Computer Science (LICS). 366-378. https://doi.org/10.1109/LICS. 2007.30 Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Adam Chlipala. 2007. A certified type-preserving compiler from lambda calculus to assembly language. In ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI). 54-65. https://doi.org/10.1145/1250734.1250742 Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. Jesper Cockx. 2020. Type Theory Unchained: Extending Agda with User-Defined Rewrite Rules. In Types for Proofs and Programs (TYPES) (Leibniz International Proceedings in Informatics (LIPIcs)), Vol. 175. Schloss Dagstuhl-Leibniz-Zentrum für Informatik, 2 : 1-2 : 27. https://doi.org/10.4230/LIPIcs.TYPES. 2019.2 Google ScholarGoogle ScholarCross RefCross Ref
  17. Karl Crary. 2003. Toward a foundational typed assembly language. In ACM SIGPLAN Symposium on Principle of Programming Languages (POPL). 198-212. https://doi.org/10.1145/640128.604149 Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. Robert Dockins, Aquinas Hobor, and Andrew W. Appel. 2009. A fresh look at separation algebras and share accounting. In Asian Symposium on Programming Languages and Systems (APLAS) (LNCS), Vol. 5904. 161-177. https://doi.org/10.1007/ 978-3-642-10672-9_13 Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. Sebastian Erdweg, Oliver Bracevac, Edlira Kuci, Matthias Krebs, and Mira Mezini. 2015. A co-contextual formulation of type rules and its application to incremental type checking. In ACM SIGPLAN Conference on Object-Oriented Programming Systems, Languages & Applications (OOPSLA). 880-897. https://doi.org/10.1145/2814270.2814277 Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. Louis-Julien Guillemette and Stefan Monnier. 2008. A type-preserving compiler in Haskell. In ACM SIGPLAN International Conference on Functional Programming (ICFP). 75-86. https://doi.org/10.1145/1411204.1411218 Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. Trevor Jim. 1996. What are principal typings and what are they good for?. In ACM SIGPLAN Symposium on Principle of Programming Languages (POPL). 42-53. https://doi.org/10.1145/237721.237728 Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. Ralf Jung, Robbert Krebbers, Jacques-Henri Jourdan, Ales Bizjak, Lars Birkedal, and Derek Dreyer. 2018. Iris from the ground up: A modular foundation for higher-order concurrent separation logic. Journal of Functional Programming (JFP) 28 ( 2018 ), e20. https://doi.org/10.1017/S0956796818000151 Google ScholarGoogle ScholarCross RefCross Ref
  23. Gerwin Klein and Tobias Nipkow. 2006. A machine-checked model for a Java-like language, virtual machine, and compiler. ACM Transactions on Programming Languages and Systems (TOPLAS) 28, 4 ( 2006 ), 619-695. https://doi.org/10.1145/1146811 Google ScholarGoogle ScholarCross RefCross Ref
  24. Anders Kock. 1972. Strong functors and monoidal monads. Archiv der Mathematik 23, 1 ( 1972 ), 113-120.Google ScholarGoogle Scholar
  25. Edlira Kuci, Sebastian Erdweg, Oliver Bracevac, Andi Bejleri, and Mira Mezini. 2017. A co-contextual type checker for Featherweight Java. In European Conference on Object-Oriented Programming (ECOOP). 18 : 1-18 : 26. https://doi.org/10. 4230/LIPIcs.ECOOP. 2017.18 Google ScholarGoogle ScholarCross RefCross Ref
  26. Ramana Kumar, Magnus O. Myreen, Michael Norrish, and Scott Owens. 2014. CakeML: A verified implementation of ML. In ACM SIGPLAN Symposium on Principle of Programming Languages (POPL). 179-192. https://doi.org/10.1145/2535838. 2535841 Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. Xavier Leroy. 2009. Formal verification of a realistic compiler. Commun. ACM 52, 7 ( 2009 ), 107-115. https://doi.org/10.1145/ 1538788.1538814 Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. Tim Lindholm, Frank Yellin, Gilad Bracha, Alex Buckley, and Daniel Smith. 2020. The Java Virtual Machine specification: Java SE 14 edition. Available online at https://docs.oracle.com/javase/specs/jvms/se14/jvms14.pdf.Google ScholarGoogle Scholar
  29. Conor McBride. 2012. Agda-curious? https://dl.acm.org/doi/pdf/10.1145/2364527.2364529 Keynote at the ACM SIGPLAN International Conference of Functional Programming (ICFP).Google ScholarGoogle Scholar
  30. Conor McBride. 2018. Everybody's got to be somewhere. In Workshop on Mathematically Structured Functional Programming (MSFP) (EPTCS), Vol. 275. 53-69. https://doi.org/10.4204/EPTCS.275.6 Google ScholarGoogle ScholarCross RefCross Ref
  31. Conor Thomas McBride. 2014. How to keep your neighbours in order. In ACM SIGPLAN International Conference of Functional Programming (ICFP). 297-309. https://doi.org/10.1145/2628136.2628163 Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. James McKinna and Joel Wright. 2006. A type-correct, stack-safe, provably correct, expression compiler. Unpublished draft.Google ScholarGoogle Scholar
  33. Robin Milner. 1978. A theory of type polymorphism in programming. Journal of Computer and System Sciences (JCSS) 17, 3 ( 1978 ), 348-375. https://doi.org/10.1016/ 0022-0000 ( 78 ) 90014-4 Google ScholarGoogle ScholarCross RefCross Ref
  34. Eugenio Moggi. 1991. Notions of computation and monads. Information and Computation 93, 1 ( 1991 ), 55-92. https: //doi.org/10.1016/ 0890-5401 ( 91 ) 90052-4 Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. Greg Morrisett, Karl Crary, Neal Glew, Dan Grossman, Richard Samuels, Frederick Smith, David Walker, Stephanie Weirich, and Steve Zdancewic. 1999a. TALx86: A realistic typed assembly language. In Workshop on Compiler Support for System Software. 25-35.Google ScholarGoogle Scholar
  36. Greg Morrisett, David Walker, Karl Crary, and Neal Glew. 1999b. From system F to typed assembly language. ACM Transactions on Programming Languages and Systems (TOPLAS) 21, 3 ( 1999 ), 527-568. https://doi.org/10.1145/319301. 319345 Google ScholarGoogle ScholarDigital LibraryDigital Library
  37. Tobias Nipkow and Gerwin Klein. 2014. IMP: A Simple Imperative Language. In Concrete Semantics, Benjamin C Pierce (Ed.). Springer, Chapter 7, 75-94. https://doi.org/10.1007/978-3-319-10542-0_7 Google ScholarGoogle ScholarCross RefCross Ref
  38. Ulf Norell. 2009. Dependently typed programming in Agda. In ACM SIGPLAN Workshop on Types in Language Design and Implementation (TLDI). 1-2. https://doi.org/10.1145/1481861.1481862 Google ScholarGoogle ScholarDigital LibraryDigital Library
  39. Peter W. O'Hearn and David J. Pym. 1999. The logic of bunched implications. Bulletin of Symbolic Logic 5, 2 ( 1999 ), 215-244. https://doi.org/10.2307/421090 Google ScholarGoogle ScholarCross RefCross Ref
  40. Dominic Orchard, Vilem-Benjamin Liepelt, and Harley Eades III. 2019. Quantitative program reasoning with graded modal types. PACMPL 3, ACM SIGPLAN International Conference on Functional Programming (ICFP) ( 2019 ), 110 : 1-110 : 30. https://doi.org/10.1145/3341714 Google ScholarGoogle ScholarDigital LibraryDigital Library
  41. Alberto Pardo, Emmanuel Gunther, Miguel Pagano, and Marcos Viera. 2018. An internalist approach to correct-byconstruction compilers. In International Symposium on Principles and Practice of Declarative Programming (PPDP). 17 : 1-17 : 12. https://doi.org/10.1145/3236950.3236965 Google ScholarGoogle ScholarDigital LibraryDigital Library
  42. Casper Bach Poulsen, Arjen Rouvoet, Andrew Tolmach, Robbert Krebbers, and Eelco Visser. 2018. Intrinsically-typed definitional interpreters for imperative languages. PACMPL 2, ACM SIGPLAN Symposium on Principle of Programming Languages (POPL) ( 2018 ), 16 : 1-16 : 34. https://doi.org/10.1145/3158104 Google ScholarGoogle ScholarDigital LibraryDigital Library
  43. John C Reynolds. 2000. The meaning of types from intrinsic to extrinsic semantics. BRICS Report Series 7, 32 ( 2000 ).Google ScholarGoogle Scholar
  44. Arjen Rouvoet, Casper Bach Poulsen, Robbert Krebbers, and Eelco Visser. 2020a. Intrinsically-typed definitional interpreters for linear, session-typed languages. In ACM SIGPLAN Conference on Certified Programming and Proofs (CPP). 284-298. https://doi.org/10.1145/3372885.3373818 Google ScholarGoogle ScholarDigital LibraryDigital Library
  45. Arjen Rouvoet, Robbert Krebbers, and Eelco Visser. 2020b. Intrinsically Typed Compilation with Nameless labels: Agda Sources. https://doi.org/10.5281/zenodo.4072068 Google ScholarGoogle ScholarCross RefCross Ref
  46. Arjen Rouvoet, Robbert Krebbers, and Eelco Visser. 2020c. Intrinsically Typed Compilation with Nameless labels: Virtual Machine. https://doi.org/10.5281/zenodo.4071954 Google ScholarGoogle ScholarDigital LibraryDigital Library
  47. David Walker. 2005. Substructural type systems. In Advanced topics in types and programming languages, Benjamin C Pierce (Ed.). The MIT press, Chapter 1, 3-43.Google ScholarGoogle Scholar
  48. Joe B. Wells. 2002. The essence of principal typings. In International Colloquium on Automata, Languages, and Programming (ICALP). 913-925. https://doi.org/10.1007/3-540-45465-9_78 Google ScholarGoogle ScholarCross RefCross Ref

Index Terms

  1. Intrinsically typed compilation with nameless labels

        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!