skip to main content

Monadic compiler calculation (functional pearl)

Published:31 August 2022Publication History
Skip Abstract Section

Abstract

Bahr and Hutton recently developed a new approach to calculating correct compilers directly from specifications of their correctness. However, the methodology only considers converging behaviour of the source language, which means that the compiler could potentially produce arbitrary, erroneous code for source programs that diverge. In this article, we show how the methodology can naturally be extended to support the calculation of compilers that address both convergent and divergent behaviour simultaneously, without the need for separate reasoning for each aspect. Our approach is based on the use of the partiality monad to make divergence explicit, together with the use of strong bisimilarity to support equational-style calculations, but also generalises to other forms of effect by changing the underlying monad.

References

  1. Mads Sig Ager, Dariusz Biernacki, Olivier Danvy, and Jan Midtgaard. 2003. From Interpreter to Compiler and Virtual Machine: A Functional Derivation.. Department of Computer Science, University of Aarhus. Google ScholarGoogle Scholar
  2. Roland Backhouse. 2003. Program Construction: Calculating Implementations from Specifications. John Wiley and Sons. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Patrick Bahr. 2015. Calculating Certified Compilers for Non-Deterministic Languages. In Proceedings of the Symposium on Mathematics of Program Construction. https://doi.org/10.1007/978-3-319-19797-5_8 Google ScholarGoogle ScholarCross RefCross Ref
  4. Patrick Bahr and Graham Hutton. 2015. Calculating Correct Compilers. Journal of Functional Programming, 25 (2015), https://doi.org/10.1017/S0956796815000180 Google ScholarGoogle ScholarCross RefCross Ref
  5. Patrick Bahr and Graham Hutton. 2020. Calculating Correct Compilers II: Return of the Register Machines. Journal of Functional Programming, 30 (2020), https://doi.org/10.1017/S0956796820000209 Google ScholarGoogle ScholarCross RefCross Ref
  6. Patrick Bahr and Graham Hutton. 2022. Supplementary Material for “Monadic Compiler Calculation”. https://doi.org/10.5281/zenodo.6794696 Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Lennart Beringer, Gordon Stewart, Robert Dockins, and Andrew W. Appel. 2014. Verified Compilation for Shared-Memory C. In Programming Languages and Systems. https://doi.org/10.1007/978-3-642-54833-8_7 Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Edwin Brady. 2013. Idris, a General-Purpose Dependently Typed Programming Language: Design and Implementation. Journal of Functional Programming, 23, 05 (2013), https://doi.org/10.1017/S095679681300018X Google ScholarGoogle ScholarCross RefCross Ref
  9. Venanzio Capretta. 2005. General Recursion via Coinductive Types. Logical Methods in Computer Science, 1, 2 (2005), https://doi.org/10.2168/LMCS-1(2:1)2005 Google ScholarGoogle ScholarCross RefCross Ref
  10. Nils Anders Danielsson. 2012. Operational Semantics Using the Partiality Monad. In Proceedings of the International Conference on Functional Programming. https://doi.org/10.1145/2364527.2364546 Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Maulik A. Dave. 2003. Compiler Verification: A Bibliography. Software Engineering Notes, 28, 6 (2003), https://doi.org/10.1145/966221.966235 Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Jeremy Gibbons and Ralf Hinze. 2011. Just Do It: Simple Monadic Equational Reasoning. In Proceedings of the International Conference on Functional Programming. https://doi.org/10.1145/2034773.2034777 Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. Benjamin Grégoire and Xavier Leroy. 2002. A Compiled Implementation of Strong Reduction. In Proceedings of the International Conference on Functional Programming. https://doi.org/10.1145/581478.581501 Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. John Hughes, Lars Pareto, and Amr Sabry. 1996. Proving the Correctness of Reactive Systems Using Sized Types. In Proceedings of the Symposium on Principles of Programming Languages. https://doi.org/10.1145/237721.240882 Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Chung-kil Hur, Paul He, Yannick Zakowski, and Steve Zdancewic. 2020. An Equational Theory for Weak Bisimulation via Generalized Parameterized Coinduction. In Proceedings of the International Conference on Certified Programs and Proofs. https://doi.org/10.1145/3372885.3373813 Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. Graham Hutton and Joel Wright. 2007. What is the Meaning of These Constant Interruptions? Journal of Functional Programming, 17, 6 (2007), https://doi.org/10.1017/S0956796807006363 Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. Jeehoon Kang, Yoonseung Kim, Chung-Kil Hur, Derek Dreyer, and Viktor Vafeiadis. 2016. Lightweight Verification of Separate Compilation. In Proceedings of the Symposium Principles of Programming Languages. https://doi.org/10.1145/2837614.2837642 Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. Xavier Leroy. 2006. Coinductive Big-Step Operational Semantics. In Proceedings of the European Symposium on Programming Languages and Systems. https://doi.org/10.1007/11693024_5 Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. Xavier Leroy. 2006. Formal Certification of a Compiler Back-End or: Programming a Compiler with a Proof Assistant. In Proceedings of the Symposium on Principles of Programming Languages. https://doi.org/10.1145/1111037.1111042 Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. Erik Meijer. 1992. Calculating Compilers. Katholieke Universiteit Nijmegen. Google ScholarGoogle Scholar
  21. Rasmus Ejlers Møgelberg and Niccolò Veltri. 2019. Bisimulation As Path Type for Guarded Recursive Types. Proceedings of the ACM on Programming Languages, 3, POPL (2019), https://doi.org/10.1145/3290317 Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. 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 Proceedings of the International Conference on Functional Programming. https://doi.org/10.1145/2784731.2784764 Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. David Park. 1981. Concurrency and Automata on Infinite Sequences. In Theoretical Computer Science. https://doi.org/10.1007/BFb0017309 Google ScholarGoogle ScholarCross RefCross Ref
  24. Daniel Patterson and Amal Ahmed. 2019. The Next 700 Compiler Correctness Theorems (Functional Pearl). Proceedings of the ACM on Programming Languages, 3, ICFP (2019), https://doi.org/10.1145/3341689 Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. James T. Perconti and Amal Ahmed. 2014. Verifying an Open Compiler Using Multi-Language Semantics. In Proceedings of the European Symposium on Programming Languages and Systems. https://doi.org/10.1007/978-3-642-54833-8_8 Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. Mitchell Pickard and Graham Hutton. 2021. Calculating Dependently-Typed Compilers. Proceedings of the ACM on Programming Languages, 5, ICFP (2021), https://doi.org/10.1145/3473587 Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. John C Reynolds. 1972. Definitional Interpreters for Higher-Order Programming Languages. In Proceedings of the ACM Annual Conference. ACM. https://doi.org/10.1145/800194.805852 Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. Peter Sestoft. 1997. Deriving a Lazy Abstract Machine. Journal of Functional Programming, 7, 03 (1997), https://doi.org/10.1017/S0956796897002712 Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. Mike Spivey. 1990. A Functional Theory of Exceptions. Science of Computer Programming, 14, 1 (1990), https://doi.org/10.1016/0167-6423(90)90056-J Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. Gordon Stewart, Lennart Beringer, Santiago Cuellar, and Andrew W. Appel. 2015. Compositional CompCert. In Proceedings of the Symposium on Principles of Programming Languages. https://doi.org/10.1145/2676726.2676985 Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. Mitchell Wand. 1982. Deriving Target Code as a Representation of Continuation Semantics. Transactions on Programming Languages and Systems, 4, 3 (1982), https://doi.org/10.1145/357172.357179 Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. Li-yao Xia, Yannick Zakowski, Paul He, Chung-Kil Hur, Gregory Malecha, Benjamin C. Pierce, and Steve Zdancewic. 2019. Interaction Trees: Representing Recursive and Impure Programs in Coq. Proceedings of the ACM on Programming Languages, 4, POPL (2019), https://doi.org/10.1145/3371119 Google ScholarGoogle ScholarDigital LibraryDigital Library
  33. Angel Zúñiga and Gemma Bel-Enguix. 2020. Coinductive Natural Semantics for Compiler Verification in Coq. Mathematics, 8, 9 (2020), https://doi.org/10.3390/math8091573 Google ScholarGoogle ScholarCross RefCross Ref

Index Terms

  1. Monadic compiler calculation (functional pearl)

          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

          • Article Metrics

            • Downloads (Last 12 months)403
            • Downloads (Last 6 weeks)17

            Other Metrics

          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!