Skip to main content

The CakeML Compiler Explorer

Tracking Intermediate Representations in a Verified Compiler

  • Conference paper
  • First Online:
Trends in Functional Programming (TFP 2017)

Abstract

It is difficult to understand how a compiler’s different phases transform a program, especially if the only way to do so is by studying the compiler’s source code. We have constructed a tool for the verified CakeML compiler which allows programmers to step through its phases, much like stepping through a program with a debugger. In particular, we allow a programmer to see how a piece of source code is represented in intermediate languages during compilation, and how pieces of intermediate code at different phases relate to each other. It is our hope that this feature will let the developers of CakeML more easily identify compiler optimizations, and that it will make it easier for new developers to quickly gain an intuition for the compiler.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 44.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 60.00
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Notes

  1. 1.

    This intermediate representation is abbreviated. The actual representation contains a large number of pre-defined functions which can be referenced as global variables. For instance, here + has been compiled to Var_global 155.

  2. 2.

    Thus, even though we will sometimes use the term “state”, it has nothing to do with program state, but rather with various stages of evaluation.

  3. 3.

    The decision to use this form of annotation rather than adding a new annotating constructor to each language was made in collaboration with the core CakeML development team. The reasoning is that new mutually recursive datatypes would complicate the compiler semantics and therefore the existing proofs, especially since we do not wish to force the annotation to always be present. Furthermore, modifying each constructor should be a one-off modification, since adding more metadata to the compilation process in the future could be accomplished by modifying the tra datatype.

  4. 4.

    The names “b” and “a” are used instead of the source code names, “f” and “g”. This is because in the conversion to PatLang, the original names are discarded. It might be possible to reconstruct the original names using traces to determine the origin of each variable in PatLang. However, this may not be feasible for the exact reason that De Bruijn indices are used, namely the risk of naming conflicts. A transformation may put two variables in the same namespace in a way that would cause a conflict if the original names were used. We therefore opted instead to create new variable names in a safe manner.

References

  1. CakeML: A Verified Implementation of ML. https://github.com/CakeML/cakeml. Accessed 15 Sept 2017

  2. CakeML Compiler Explorer. https://cakeml.org/explorer.cgi. Accessed 4 Apr 2017

  3. Compiler Explorer. https://github.com/mattgodbolt/compiler-explorer. Accessed 2 May 2017

  4. LLVM Visualization Tool User Guide. https://llvm.org/svn/llvm-project/television/trunk/docs/UserGuide.html. Accessed 28 Apr 2017

  5. Saser/compiler-explorer-react. https://github.com/Saser/compiler-explorer-react. Accessed 11 May 2017

  6. Bray, T.: The javascript object notation (JSON) data interchange format (2014). https://tools.ietf.org/html/rfc7159.html

  7. De Bruijn, N.G.: Lambda calculus notation with nameless dummies: a tool for automatic formula manipulation, with application to the Church-Rosser theorem. In: Indagationes Mathematicae (Proceedings), vol. 75, pp. 381–392. Elsevier (1972)

    Google Scholar 

  8. Farmer, A.: HERMIT: mechanized reasoning during compilation in the Glasgow Haskell Compiler. Ph.D. thesis, The University of Kansas, April 2015

    Google Scholar 

  9. Hjort, R., Holmgren, J., Persson, C.: The CakeML compiler explorer: visualizing how a verified compiler transforms expressions. Bachelor’s thesis, Chalmers University of Technology, Department of Computer Science and Engineering, SE-412 96 Göteborg (2017). http://publications.lib.chalmers.se/records/fulltext/251308/251308.pdf

  10. Kumar, R.: Self-compilation and self-verification, chap. 3, pp. 37–48, Technical report, UCAM-CL-TR-879, University of Cambridge, Computer Laboratory, February 2016. http://www.cl.cam.ac.uk/techreports/UCAM-CL-TR-879.pdf

  11. Kumar, R., Myreen, M.O., Norrish, M., Owens, S.: CakeML: a verified implementation of ML. In: Symposium on Principles of Programming Languages [POPL]. ACM Press (2014)

    Google Scholar 

  12. Sarkar, D., Waddell, O., Dybvig, R.K.: A nanopass framework for compiler education. J. Funct. Program. 15(05), 653–667 (2005)

    Article  Google Scholar 

  13. Tan, Y.K., Myreen, M.O., Kumar, R., Fox, A., Owens, S., Norrish, M.: A new verified compiler backend for CakeML. In: International Conference on Functional Programming [ICFP]. ACM Press, September 2016

    Google Scholar 

Download references

Acknowledgements

The Compiler Explorer is a Bachelor’s thesis project conducted by the authors of this paper at Chalmers University of Technology, and this paper summarizes the main points of the thesis [9]. We want to especially thank our supervisor, Magnus Myreen, for his great ideas and quick feedback. We also want to thank Ramana Kumar for patiently answering our questions in the CakeML and HOL IRC channels and the CakeML developer mailing lists, as well as the entire developer team behind CakeML, Magnus Myreen and Ramana Kumar included, for inviting us to contribute. Finally, we want to thank the anonymous reviewers for their constructive feedback.

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Rikard Hjort .

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2018 Springer International Publishing AG, part of Springer Nature

About this paper

Check for updates. Verify currency and authenticity via CrossMark

Cite this paper

Hjort, R., Holmgren, J., Persson, C. (2018). The CakeML Compiler Explorer. In: Wang, M., Owens, S. (eds) Trends in Functional Programming. TFP 2017. Lecture Notes in Computer Science(), vol 10788. Springer, Cham. https://doi.org/10.1007/978-3-319-89719-6_8

Download citation

  • DOI: https://doi.org/10.1007/978-3-319-89719-6_8

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-319-89718-9

  • Online ISBN: 978-3-319-89719-6

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics