Abstract
Static Single Assignment form (SSA) is widely adopted as an intermediate representation (IR) of production compilers as it enables aggressive compiler optimizations based on data-flow analysis. We are concerned with developing verified compilers for functional programming languages that exploit the benefits of SSA. The most obvious approach to achieving our goal is to verify the transformation from Continuation-Passing Style (CPS)—an intermediate representation widely adopted by both production and verified functional compilers—to SSA. In this paper, we show how to verify the translation from CPS to SSA and how to apply the verified translation towards building verified functional compilers. Concretely, we develop and verify a transformation algorithm from PCF programs in CPS to SSA. By extending the transformation with a verified CPS transformation from PCF, we get a verified compilation chain from PCF to SSA. We have also connected this chain with LLVM at the target level to provide a foundation for building more sophisticated verified functional compilers targeting SSA IRs.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Notes
- 1.
The complete artifact in Coq is at https://doi.org/10.5281/zenodo.7882331.
References
Appel, A.W.: SSA is functional programming. ACM SIGPLAN Notices 33(4), 17–20 (1998). https://doi.org/10.1145/278283.278285
Balasubramanian, A., Baranowski, M.S., Burtsev, A., Panda, A., Rakamarić, Z., Ryzhyk, L.: System programming in rust: Beyond safety. In: Proceedings of the 16th Workshop on Hot Topics in Operating Systems, pp. 156–161 (2017). https://doi.org/10.1145/3139645.3139660
Barthe, G., Demange, D., Pichardie, D.: Formal verification of an SSA-based middle-end for CompCert. ACM Trans. Program. Lang. Syst. 36(1) (mar 2014). https://doi.org/10.1145/2579080
Bélanger, O.S., Monnier, S., Pientka, B.: Programming type-safe transformations using higher-order abstract syntax. In: Gonthier, G., Norrish, M. (eds.) Certified Programs and Proofs - Third International Conference, CPP 2013, Melbourne, VIC, Australia, December 11–13, 2013, Proceedings. Lecture Notes in Computer Science, vol. 8307, pp. 243–258. Springer (2013). https://doi.org/10.1007/978-3-319-03545-1_16
Bélanger, O.S., Weaver, M.Z., Appel, A.W.: Certified code generation from CPS to C. preparation. (2019), https://www.cs.princeton.edu/~appel/papers/CPStoC.pdf
Danvy, O., Millikin, K., Nielsen, L.R.: On one-pass CPS transformations. BRICS Report Series 14(6) (2007)
Dargaye, Z.: Vérification formelle d’un compilateur optimisant pour langages fonctionnels. Ph.D. thesis, Université Paris-Diderot-Paris VII (2009)
Demange, D., Pichardie, D., Stefanesco, L.: Verifying fast and sparse SSA-based optimizations in Coq. In: Franke, B. (ed.) Compiler Construction, pp. 233–252. Springer, Berlin Heidelberg, Berlin, Heidelberg (2015). https://doi.org/10.1007/978-3-662-46663-6_12
Dowek, G., Lévy, J.J.: Introduction to the theory of programming languages. Springer Science & Business Media (2010)
Farvardin, K., Reppy, J.: A new backend for Standard ML of New Jersey. In: Proceedings of the 32nd Symposium on Implementation and Application of Functional Languages,pp. 55–66 (2020). https://doi.org/10.1145/3462172.3462191
Herklotz, Y., Demange, D., Blazy, S.: Mechanised semantics for gated static single assignment. In: Krebbers, R., Traytel, D., Pientka, B., Zdancewic, S. (eds.) Proceedings of the 12th ACM SIGPLAN International Conference on Certified Programs and Proofs, CPP 2023, Boston, MA, USA, January 16–17, 2023, pp. 182–196. ACM (2023). https://doi.org/10.1145/3573105.3575681
Kelsey, R.A.: A correspondence between continuation passing style and static single assignment form. ACM SIGPLAN Notices 30(3), 13–22 (1995). https://doi.org/10.1145/202530.202532
Kennedy, A.: Compiling with continuations, continued. In: Proceedings of the 12th ACM SIGPLAN International Conference on Functional Programming, pp. 177–190 (2007). https://doi.org/10.1145/1291151.1291179
L. Beringer, J.S., Rastello, F.: Static Single Assignment Book. Springer Science & Business Media (2018)
Lattner, C.: Introduction to the LLVM compiler infrastructure. In: Itanium conference and expo (2006)
Leroy, X.: A formally verified compiler back-end. J. Autom. Reason. 43(4), 363–446 (2009). https://doi.org/10.1007/s10817-009-9155-4
Paraskevopoulou, Z., Appel, A.W.: Closure conversion is safe for space. Proceedings of the ACM on Programming Languages 3(ICFP), pp. 1–29 (2019). https://doi.org/10.1145/3341687
Paraskevopoulou, Z., Grover, A.: Compiling with continuations, correctly. Proc. ACM Program. Lang. 5(OOPSLA) (oct 2021). https://doi.org/10.1145/3485491
Paraskevopoulou, Z., Li, J.M., Appel, A.W.: Compositional optimizations for CertiCoq. Proc. ACM Program. Lang. 5(ICFP) (aug 2021). https://doi.org/10.1145/3473591
Plotkin, G.D.: Call-by-name, call-by-value and the \(\lambda \)-calculus. Theoret. Comput. Sci. 1(2), 125–159 (1975). https://doi.org/10.1016/0304-3975(75)90017-1
Plotkin, G.D.: LCF considered as a programming language. Theoret. Comput. Sci. 5(3), 223–255 (1977)
Smith, J.B.: Ocamllex and Ocamlyacc. Practical OCaml, pp. 193–211 (2007)
Wang, Y., Nadathur, G.: A higher-order abstract syntax approach to verified transformations on functional programs. In: Thiemann, P. (ed.) Programming Languages and Systems, pp. 752–779. Springer, Berlin Heidelberg, Berlin, Heidelberg (2016). https://doi.org/10.1007/978-3-662-49498-1_29
Zakowski, Y., Beck, C., Yoon, I., Zaichuk, I., Zaliva, V., Zdancewic, S.: Modular, compositional, and executable formal semantics for LLVM IR. Proceedings of the ACM on Programming Languages 5(ICFP), 1–30 (2021). https://doi.org/10.1145/3473572
Zhang, Y., Yang, M., Zhou, B., Yang, Z., Zhang, W., Zang, B.: Swift: a register-based JIT compiler for embedded JVMs. In: Proceedings of the 8th ACM SIGPLAN/SIGOPS conference on Virtual Execution Environments, pp. 63–74 (2012). https://doi.org/10.1145/2365864.2151035
Zhao, J., Nagarakatte, S., Martin, M.M., Zdancewic, S.: Formalizing the LLVM intermediate representation for verified program transformations. In: Proceedings of the 39th annual ACM SIGPLAN-SIGACT symposium on Principles of programming languages, pp. 427–440 (2012). https://doi.org/10.1145/2103621.2103709
Acknowledgments
We would like to thank the anonymous referees for their helpful feedback which improved this paper significantly. This work was supported by the National Natural Science Foundation of China (NSFC) under Grant No. 62002217.
Author information
Authors and Affiliations
Corresponding author
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2023 The Author(s), under exclusive license to Springer Nature Switzerland AG
About this paper
Cite this paper
Liu, S., Wang, Y. (2023). Verified Transformation of Continuation-Passing Style into Static Single Assignment Form. In: David, C., Sun, M. (eds) Theoretical Aspects of Software Engineering. TASE 2023. Lecture Notes in Computer Science, vol 13931. Springer, Cham. https://doi.org/10.1007/978-3-031-35257-7_2
Download citation
DOI: https://doi.org/10.1007/978-3-031-35257-7_2
Published:
Publisher Name: Springer, Cham
Print ISBN: 978-3-031-35256-0
Online ISBN: 978-3-031-35257-7
eBook Packages: Computer ScienceComputer Science (R0)