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.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Notes
- 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.
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.
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.
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
CakeML: A Verified Implementation of ML. https://github.com/CakeML/cakeml. Accessed 15 Sept 2017
CakeML Compiler Explorer. https://cakeml.org/explorer.cgi. Accessed 4 Apr 2017
Compiler Explorer. https://github.com/mattgodbolt/compiler-explorer. Accessed 2 May 2017
LLVM Visualization Tool User Guide. https://llvm.org/svn/llvm-project/television/trunk/docs/UserGuide.html. Accessed 28 Apr 2017
Saser/compiler-explorer-react. https://github.com/Saser/compiler-explorer-react. Accessed 11 May 2017
Bray, T.: The javascript object notation (JSON) data interchange format (2014). https://tools.ietf.org/html/rfc7159.html
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)
Farmer, A.: HERMIT: mechanized reasoning during compilation in the Glasgow Haskell Compiler. Ph.D. thesis, The University of Kansas, April 2015
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
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
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)
Sarkar, D., Waddell, O., Dybvig, R.K.: A nanopass framework for compiler education. J. Funct. Program. 15(05), 653–667 (2005)
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
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
Corresponding author
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2018 Springer International Publishing AG, part of Springer Nature
About this paper
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)