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.
- 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 Scholar
- 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 Scholar
Cross Ref
- 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 Scholar
- 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 Scholar
Cross Ref
- Andrew W. Appel. 2006. Compiling with continuations. Cambridge University Press. https://doi.org/10.1017/ CBO9780511609619 Google Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- Lennart Augustsson and Magnus Carlsson. 1999. An exercise in dependent types: A well-typed interpreter. In Workshop on Dependent Types in Programming.Google Scholar
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Cross Ref
- 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 Scholar
Cross Ref
- Anders Kock. 1972. Strong functors and monoidal monads. Archiv der Mathematik 23, 1 ( 1972 ), 113-120.Google Scholar
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- Xavier Leroy. 2009. Formal verification of a realistic compiler. Commun. ACM 52, 7 ( 2009 ), 107-115. https://doi.org/10.1145/ 1538788.1538814 Google Scholar
Digital Library
- 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 Scholar
- 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 Scholar
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- James McKinna and Joel Wright. 2006. A type-correct, stack-safe, provably correct, expression compiler. Unpublished draft.Google Scholar
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- John C Reynolds. 2000. The meaning of types from intrinsic to extrinsic semantics. BRICS Report Series 7, 32 ( 2000 ).Google Scholar
- 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 Scholar
Digital Library
- Arjen Rouvoet, Robbert Krebbers, and Eelco Visser. 2020b. Intrinsically Typed Compilation with Nameless labels: Agda Sources. https://doi.org/10.5281/zenodo.4072068 Google Scholar
Cross Ref
- Arjen Rouvoet, Robbert Krebbers, and Eelco Visser. 2020c. Intrinsically Typed Compilation with Nameless labels: Virtual Machine. https://doi.org/10.5281/zenodo.4071954 Google Scholar
Digital Library
- 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 Scholar
- 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 Scholar
Cross Ref
Index Terms
Intrinsically typed compilation with nameless labels
Recommendations
Intrinsically-typed definitional interpreters for imperative languages
A definitional interpreter defines the semantics of an object language in terms of the (well-known) semantics of a host language, enabling understanding and validation of the semantics through execution. Combining a definitional interpreter with a ...
Intrinsically-typed definitional interpreters for linear, session-typed languages
CPP 2020: Proceedings of the 9th ACM SIGPLAN International Conference on Certified Programs and ProofsAn intrinsically-typed definitional interpreter is a concise specification of dynamic semantics, that is executable and type safe by construction. Unfortunately, scaling intrinsically-typed definitional interpreters to more complicated object languages ...
Decidability of conversion for type theory in type theory
Type theory should be able to handle its own meta-theory, both to justify its foundational claims and to obtain a verified implementation. At the core of a type checker for intensional type theory lies an algorithm to check equality of types, or in ...






Comments