Abstract
Programming languages are popular and diverse, and the convenience of programmatically changing the behavior of complex systems is attractive even for the ones with stringent security requirements, which often impose restrictions on the acceptable programs. A very common restriction is that the program must terminate, which is very hard to check because the Halting Problem is undecidable. In this work, we proposed a technique to unroll recursive programs in functional languages to create terminating versions of them. We prove that our strategy itself is guaranteed to terminate. We also formalize term generation and run property-based tests to build confidence that the semantics is preserved through the transformation. Our strategy can be used to compile general purpose functional languages to restrictive targets such as the eBPF and smart contracts for blockchain networks.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Notes
- 1.
Version 5.3 and higher has support for bounded loops only.
- 2.
The term “fuel” is inspired by Petrol Semantics. It is presented, for instance, in [16].
References
Abel, A.: Foetus—termination checker for simple functional programs. Technical report, Ludwigs-Maximilians-University, Munich (1998)
Abel, A.: Specification and verification of a formal system for structurally recursive functions. In: Coquand, T., Dybjer, P., Nordström, B., Smith, J. (eds.) TYPES 1999. LNCS, vol. 1956, pp. 1–20. Springer, Heidelberg (2000). https://doi.org/10.1007/3-540-44557-9_1
Abel, A., Altenkirch, T.: A semantical analysis of structural recursion. In: Fourth International Workshop on Termination WST, pp. 24–25. Darmstadt University of Technology, Dagstuhl, Germany (1999)
Abel, A., Altenkirch, T.: A predicative analysis of structural recursion. J. Funct. Program. 12(1), 1–41 (2002)
Barthe, G., et al.: Type-based termination of recursive definitions. Math. Struct. Comput. Sci. 14(1), 97–141 (2004)
Appel, A.: Modern Compiler Implementation in ML. Cambridge University Press, New York (2004)
Authors of eBPF: eBPF - Introduction, Tutorials and Community Resources (2022). https://ebpf.io/
Barthe, G., Grégoire, B., Riba, C.: A tutorial on type-based termination. In: Bove, A., Barbosa, L.S., Pardo, A., Pinto, J.S. (eds.) LerNet 2008. LNCS, vol. 5520, pp. 100–152. Springer, Heidelberg (2009). https://doi.org/10.1007/978-3-642-03153-3_3
Barthe, G., Grégoire, B., Riba, C.: Type-based termination with sized products. In: Kaminski, M., Martini, S. (eds.) CSL 2008. LNCS, vol. 5213, pp. 493–507. Springer, Heidelberg (2008). https://doi.org/10.1007/978-3-540-87531-4_35
Ringell Developers: Ringell (2022). https://github.com/mayconamaro/ringell
Feitosa, S., Ribeiro, R., Du Bois, A.: A type-directed algorithm to generate random well-typed Java 8 programs. Sci. Comput. Program. 196, 102494 (2020)
GNU: GCC, the GNU Compiler Collection (2022). https://gcc.gnu.org/
Huet, G., Kahn, G., Paulin-Mohring, C.: The CoQ proof assistant a tutorial. Rapport Technique 178 (1997)
Le, T.C., Xu, L., Chen, L., Shi, W.: Proving conditional termination for smart contracts. In: Proceedings of the 2nd ACM Workshop on Blockchains, Cryptocurrencies, and Contracts, BCC 2018, pp. 57–59. Association for Computing Machinery, New York (2018). https://doi.org/10.1145/3205230.3205239
LLVM Project: Clang C Language Family Frontend for LLVM (2022). https://clang.llvm.org/
McBride, C.: Turing-completeness totally free. In: Hinze, R., Voigtländer, J. (eds.) MPC 2015. LNCS, vol. 9129, pp. 257–275. Springer, Cham (2015). https://doi.org/10.1007/978-3-319-19797-5_13
Microsoft: Visual Studio Compiler for Windows (2022). https://visualstudio.microsoft.com/cplusplus/
Norell, U.: Towards a practical programming language based on dependent type theory. Ph.D. thesis, Chalmers University of Technology and Göteborg University, Sweden (2007)
O’Sullivan, B., Goerzen, J., Stewart, D.: Real World Haskell. O’Reilly, Sebastopol (2008)
Pierce, B.C.: Types and Programming Languages. MIT Press, Cambridge (2002)
Rugina, R., Rinard, M.: Recursion unrolling for divide and conquer programs. In: Midkiff, S.P., et al. (eds.) LCPC 2000. LNCS, vol. 2017, pp. 34–48. Springer, Heidelberg (2001). https://doi.org/10.1007/3-540-45574-4_3
Sipser, M.: Introduction to the Theory of Computation, 3rd edn. Cengage Learning, Cambridge (2012)
Wadler, P., Kokke, W., Siek, J.G.: Programming language foundations in Agda (2020). http://plfa.inf.ed.ac.uk/20.07/
Author information
Authors and Affiliations
Corresponding author
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2022 The Author(s), under exclusive license to Springer Nature Switzerland AG
About this paper
Cite this paper
Amaro, M.J.J., Feitosa, S.S., Ribeiro, R.G. (2022). A Sound Strategy to Compile General Recursion into Finite Depth Pattern Matching. In: Lima, L., Molnár, V. (eds) Formal Methods: Foundations and Applications. SBMF 2022. Lecture Notes in Computer Science, vol 13768. Springer, Cham. https://doi.org/10.1007/978-3-031-22476-8_3
Download citation
DOI: https://doi.org/10.1007/978-3-031-22476-8_3
Published:
Publisher Name: Springer, Cham
Print ISBN: 978-3-031-22475-1
Online ISBN: 978-3-031-22476-8
eBook Packages: Computer ScienceComputer Science (R0)