skip to main content
research-article
Open Access
Artifacts Evaluated & Functional

Closure conversion is safe for space

Published:26 July 2019Publication History
Skip Abstract Section

Abstract

We formally prove that closure conversion with flat environments for CPS lambda calculus is correct (preserves semantics) and safe for time and space, meaning that produced code preserves the time and space required for the execution of the source program.

We give a cost model to pre- and post-closure-conversion code by formalizing profiling semantics that keep track of the time and space resources needed for the execution of a program, taking garbage collection into account. To show preservation of time and space we set up a general, "garbage-collection compatible", binary logical relation that establishes invariants on resource consumption of the related programs, along with functional correctness. Using this framework, we show semantics preservation and space and time safety for terminating source programs, and divergence preservation and space safety for diverging source programs.

We formally prove that closure conversion with flat environments for CPS lambda calculus is correct (preserves semantics) and safe for time and space, meaning that produced code preserves the time and space required for the execution of the source program.

We give a cost model to pre- and post-closure-conversion code by formalizing profiling semantics that keep track of the time and space resources needed for the execution of a program, taking garbage collection into account. To show preservation of time and space we set up a general, "garbage-collection compatible", binary logical relation that establishes invariants on resource consumption of the related programs, along with functional correctness. Using this framework, we show semantics preservation and space and time safety for terminating source programs, and divergence preservation and space safety for diverging source programs.

This is the first formal proof of space-safety of a closure-conversion transformation. The transformation and the proof are parts of the CertiCoq compiler pipeline from Coq (Gallina) through CompCert Clight to assembly language. Our results are mechanized in the Coq proof assistant.

Skip Supplemental Material Section

Supplemental Material

a83-paraskevopoulou.webm

References

  1. Elvira Albert, Samir Genaim, and Miguel Gómez-Zamalloa. 2010. Parametric Inference of Memory Requirements for Garbage Collected Languages. In Proceedings of the 2010 International Symposium on Memory Management (ISMM ’10). ACM, New York, NY, USA, 121–130. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Roberto M. Amadio and Yann Régis-Gianas. 2012. Certifying and Reasoning on Cost Annotations of Functional Programs. In Proceedings of the Second International Conference on Foundational and Practical Aspects of Resource Analysis (FOPARA’11). Springer-Verlag, Berlin, Heidelberg, 72–89. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Abhishek Anand, Andrew W. Appel, John Gregory Morrisett, Zoe Paraskevopoulou, Randy Pollack, Olivier Savary Bélanger, Matthieu Sozeau, and Matthew Weaver. 2017. CertiCoq : A verified compiler for Coq. In CoqPL’17: The Third International Workshop on Coq for Programming Languages. 2.Google ScholarGoogle Scholar
  4. Andrew W. Appel. 1992. Compiling with Continuations. Cambridge University Press, New York. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. Andrew W. Appel and Marcelo J. R. Gonçalves. 1993. Hash-consing garbage collection. Technical Report CS-TR-412-93. Princeton University Department of Computer Science.Google ScholarGoogle Scholar
  6. Andrew W. Appel and Trevor Jim. 1989. Continuation-Passing, Closure-Passing Style. In 16th ACM Symp. on Principles of Programming Languages. ACM Press, New York, 293–302. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Andrew W. Appel and Zhong Shao. 1996. Empirical and Analytic Study of Stack Versus Heap Cost for Languages with Closures. J. Funct. Program. 6 (01 1996), 47–74.Google ScholarGoogle Scholar
  8. Frédéric Besson, Sandrine Blazy, and Pierre Wilke. 2017. CompCertS: A Memory-Aware Verified C Compiler using Pointer as Integer Semantics. In ITP 2017 - 8th International Conference on Interactive Theorem Proving (ITP 2017: Interactive Theorem Proving), Vol. 10499. Springer, Brasilia, Brazil, 81–97.Google ScholarGoogle ScholarCross RefCross Ref
  9. Quentin Carbonneaux, Jan Hoffmann, Tahina Ramananandro, and Zhong Shao. 2014. End-to-end Verification of Stack-space Bounds for C Programs. SIGPLAN Not. 49, 6 (June 2014), 270–281. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Ezgi Çiçek, Gilles Barthe, Marco Gaboardi, Deepak Garg, and Jan Hoffmann. 2017. Relational Cost Analysis. In Proceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages (POPL 2017). ACM, New York, NY, USA, 316–329. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Ezgi Çiçek, Zoe Paraskevopoulou, and Deepak Garg. 2016. A Type Theory for Incremental Computational Complexity with Control Flow Changes. In Proceedings of the 21st ACM SIGPLAN International Conference on Functional Programming (ICFP 2016). ACM, New York, NY, USA, 132–145. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Ezgi Çiçek, Deepak Garg, and Umut Acar. 2015. Refinement Types for Incremental Computational Complexity. In Programming Languages and Systems, Jan Vitek (Ed.). Springer, Heidelberg, 406–431.Google ScholarGoogle Scholar
  13. Karl Crary and Stephanie Weirich. 2000. Resource Bound Certification. In Proceedings of the 27th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’00). ACM, New York, NY, USA, 184–198. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Amer Diwan, Eliot Moss, and Richard Hudson. 1992. Compiler Support for Garbage Collection in a Statically Typed Language. In Proceedings of the ACM SIGPLAN 1992 Conference on Programming Language Design and Implementation (PLDI ’92). ACM, New York, NY, USA, 273–282. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Vyacheslav Egorov. 2012. Grokking V8 closures for fun (and profit?). https://mrale.ph/blog/2012/09/23/grokking- v8- closuresfor- fun.html/ .Google ScholarGoogle Scholar
  16. David Glasser. 2013. An interesting kind of JavaScript memory leak. https://blog.meteor.com/an- interesting- kind- ofjavascript- memory- leak- 8b47d2e7f156/ .Google ScholarGoogle Scholar
  17. Jörgen Gustavsson and David Sands. 1999. A Foundation for Space-Safe Transformations of Call-by-Need Programs. Electronic Notes in Theoretical Computer Science 26 (1999), 69 – 86.Google ScholarGoogle ScholarCross RefCross Ref
  18. Jörgen Gustavsson and David Sands. 2001. Possibilities and Limitations of Call-by-need Space Improvement. In Proceedings of the Sixth ACM SIGPLAN International Conference on Functional Programming (ICFP ’01). ACM, New York, NY, USA, 265–276. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. Jan Hoffmann, Ankush Das, and Shu-Chun Weng. 2017. Towards Automatic Resource Bound Analysis for OCaml. In Proceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages (POPL 2017). ACM, New York, NY, USA, 359–373. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. Chung-Kil Hur and Derek Dreyer. 2011. A Kripke Logical Relation Between ML and Assembly. In Proceedings of the 38th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’11). ACM, New York, NY, USA, 133–146. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. Chung-Kil Hur, Derek Dreyer, Georg Neis, and Viktor Vafeiadis. 2012. The Marriage of Bisimulations and Kripke Logical Relations. In Proceedings of the 39th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’12). ACM, New York, NY, USA, 59–72. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. Steffen Jost, Kevin Hammond, Hans-Wolfgang Loidl, and Martin Hofmann. 2010. Static Determination of Quantitative Resource Usage for Higher-order Programs. In Proceedings of the 37th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’10). ACM, New York, NY, USA, 223–236. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. Andrew W. Keep, Alex Hearn, and R. Kent Dybvig. 2012. Optimizing Closures in O(0) Time. In Proceedings of the 2012 Annual Workshop on Scheme and Functional Programming (Scheme ’12). ACM, New York, NY, USA, 30–35. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. Richard Kelsey and Paul Hudak. 1989. Realistic Compilation by Program Transformation. In 16th ACM Symp. on Principles of Programming Languages. ACM Press, New York, 281–92. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. Ramana Kumar, Magnus O Myreen, Michael Norrish, and Scott Owens. 2014. CakeML: A Verified Implementation of ML. In POPL’14: 41st ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages. ACM Press, 179–191. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. Xavier Leroy. 2009. A Formally Verified Compiler Back-end. Journal of Automated Reasoning 43, 4 (2009), 363–446. Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. Andrew McCreight, Tim Chevalier, and Andrew Tolmach. 2010. A Certified Framework for Compiling and Executing Garbagecollected Languages. In Proceedings of the 15th ACM SIGPLAN International Conference on Functional Programming (ICFP ’10). ACM, New York, NY, USA, 273–284. Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. Yasuhiko Minamide. 1999. Space-Profiling Semantics of the Call-by-Value Lambda Calculus and the CPS Transformation. Electr. Notes Theor. Comput. Sci. 26 (1999), 105–120.Google ScholarGoogle ScholarCross RefCross Ref
  29. Greg Morrisett and Robert Harper. 1997. Semantics of Memory Management for Polymorphic Languages. In Higher Order Operational Techniques in Semantics, Publications of the Newton Institute. Cambridge University Press, 175–226. Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. 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 20th ACM SIGPLAN International Conference on Functional Programming (ICFP 2015). ACM, New York, NY, USA, 166–178. Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. David Sands. 1992. Operational Theories of Improvement in Functional Languages. In Functional Programming, Glasgow 1991, Rogardt Heldal, Carsten Kehler Holst, and Philip Wadler (Eds.). Springer London, London, 298–311. Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. David Sands. 1998. Improvement Theory and Its Applications. In Higher Order Operational Techniques in Semantics, Andrew D. Gordon and Andrew M. Pitts (Eds.). Cambridge University Press, New York, NY, USA, 275–306. http: //dl.acm.org/citation.cfm?id=309656.309672 Google ScholarGoogle ScholarDigital LibraryDigital Library
  33. Olivier Savary Bélanger and Andrew W. Appel. 2017. Shrink Fast Correctly!. In PPDP’17: International Symposium on Principles and Practice of Declarative Programming. ACM Press, 49–60. Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. Zhong Shao and Andrew W. Appel. 1994. Space-efficient Closure Representations. In Proceedings of the 1994 ACM Conference on LISP and Functional Programming (LFP ’94). ACM, New York, NY, USA, 150–161. Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. Zhong Shao and Andrew W. Appel. 2000. Efficient and Safe-for-space Closure Conversion. ACM Trans. Program. Lang. Syst. 22, 1 (Jan. 2000), 129–161. Google ScholarGoogle ScholarDigital LibraryDigital Library
  36. Leena Unnikrishnan and Scott D. Stoller. 2009. Parametric Heap Usage Analysis for Functional Programs. In Proceedings of the 2009 International Symposium on Memory Management (ISMM ’09). ACM, New York, NY, USA, 139–148. Google ScholarGoogle ScholarDigital LibraryDigital Library
  37. Peng Wang, Di Wang, and Adam Chlipala. 2017. TiML: A Functional Language for Practical Complexity Analysis with Invariants. Proc. ACM Program. Lang. 1, OOPSLA, Article 79 (Oct. 2017), 26 pages. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Closure conversion is safe for space

    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

    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!