skip to main content

A separation logic for effect handlers

Published:04 January 2021Publication History
Skip Abstract Section

Abstract

User-defined effects and effect handlers are advertised and advocated as a relatively easy-to-understand and modular approach to delimited control. They offer the ability of suspending and resuming a computation and allow information to be transmitted both ways between the computation, which requests a certain service, and the handler, which provides this service. Yet, a key question remains, to this day, largely unanswered: how does one modularly specify and verify programs in the presence of both user-defined effect handlers and primitive effects, such as heap-allocated mutable state? We answer this question by presenting a Separation Logic with built-in support for effect handlers, both shallow and deep. The specification of a program fragment includes a protocol that describes the effects that the program may perform as well as the replies that it can expect to receive. The logic allows local reasoning via a frame rule and a bind rule. It is based on Iris and inherits all of its advanced features, including support for higher-order functions, user-defined ghost state, and invariants. We illustrate its power via several case studies, including (1) a generic formulation of control inversion, which turns a producer that ``pushes'' elements towards a consumer into a producer from which one can ``pull'' elements on demand, and (2) a simple system for cooperative concurrency, where several threads execute concurrently, can spawn new threads, and communicate via promises.

References

  1. Andrej Bauer and Matija Pretnar. 2015. Programming with algebraic efects and handlers. Journal of Logical and Algebraic Methods in Programming 84, 1 ( 2015 ), 108-123. http://math.andrej.com/wp-content/uploads/2012/03/ef.pdfGoogle ScholarGoogle ScholarCross RefCross Ref
  2. Andrej Bauer and Matija Pretnar. 2020. Ef. http://www.ef-lang.org/Google ScholarGoogle Scholar
  3. Martin Berger. 2009. Program Logics for Sequential Higher-Order Control. In Fundamentals of Software Engineering (Lecture Notes in Computer Science, Vol. 5961 ). Springer, 194-211. http://users.sussex.ac.uk/~mfb21/publications/fsen09/fsen09-short.pdfGoogle ScholarGoogle Scholar
  4. Dariusz Biernacki, Maciej Piróg, Piotr Polesiuk, and Filip Sieczkowski. 2019. Abstracting algebraic efects. Proceedings of the ACM on Programming Languages 3, POPL ( 2019 ), 6 : 1-6 : 28. http://www.ii.uni.wroc.pl/~mpirog/papers/biernacki-alpopl19.pdfGoogle ScholarGoogle Scholar
  5. Jonathan Immanuel Brachthäuser, Philipp Schuster, and Klaus Ostermann. 2020. Efekt: Capability-passing style for type-and efect-safe, extensible efect handlers in Scala. Journal of Functional Programming 30 ( 2020 ), e8. http://ps.informatik.unituebingen.de/publications/brachthaeuser19efekt-revision.pdfGoogle ScholarGoogle Scholar
  6. Edwin C. Brady. 2013. Programming and reasoning with algebraic efects and dependent types. In International Conference on Functional Programming (ICFP). 133-144. https://eb.host.cs. st-andrews.ac.uk/drafts/efects.pdfGoogle ScholarGoogle Scholar
  7. Edwin C. Brady. 2014. Resource-Dependent Algebraic Efects. In Trends in Functional Programming (TFP) (Lecture Notes in Computer Science, Vol. 8843 ). Springer, 18-33. https://eb.host.cs. st-andrews.ac.uk/drafts/dep-ef.pdfGoogle ScholarGoogle Scholar
  8. Tristan Crolard and Emmanuel Polonowski. 2012. Deriving a Floyd-Hoare logic for non-local jumps from a formulaeas-types notion of control. Journal of Logical and Algebraic Methods in Programming 81, 3 ( 2012 ), 181-208. http://cedric.cnam.fr/sys/crolard/publications/Hoare.pdfGoogle ScholarGoogle Scholar
  9. Paulo Emílio de Vilhena. 2020. A Separation Logic for Efect Handlers: Coq formalization. https://gitlab.inria.fr/pdevilhe/ hazel.Google ScholarGoogle Scholar
  10. Paulo Emílio de Vilhena and François Pottier. 2020a. Control inversion in Multicore OCaml. https://gitlab.inria.fr/pdevilhe/ hazel/-/blob/master/src/invert.ml.Google ScholarGoogle Scholar
  11. Paulo Emílio de Vilhena and François Pottier. 2020b. Cooperative concurrency in Multicore OCaml. https://gitlab.inria.fr/ pdevilhe/hazel/-/blob/master/src/promises.ml.Google ScholarGoogle Scholar
  12. Paulo Emílio de Vilhena and François Pottier. 2020c. Problems with multi-shot continuations in Multicore OCaml. https: //gitlab.inria.fr/pdevilhe/hazel/-/blob/master/src/test.ml.Google ScholarGoogle Scholar
  13. Germán Andrés Delbianco and Aleksandar Nanevski. 2013. Hoare-style reasoning with (algebraic) continuations. In International Conference on Functional Programming (ICFP). 363-376. http://software.imdea.org/~aleks/papers/callcc/ icfp2013.pdfGoogle ScholarGoogle ScholarDigital LibraryDigital Library
  14. Stephen Dolan, Spiros Eliopoulos, Daniel Hillerström, Anil Madhavapeddy, K. C. Sivaramakrishnan, and Leo White. 2017. Concurrent System Programming with Efect Handlers. In Trends in Functional Programming (TFP) (Lecture Notes in Computer Science, Vol. 10788 ). Springer, 98-117. http://kcsrk.info/papers/system_efects_feb_18.pdfGoogle ScholarGoogle Scholar
  15. Stephan Dolan, Anil Madhavapeddy, and KC Sivaramakrishnan. 2020. Multicore OCaml. https://github.com/ocamlmulticore/ocaml-multicore/wikiGoogle ScholarGoogle Scholar
  16. Derek Dreyer, Georg Neis, and Lars Birkedal. 2012. The impact of higher-order state and control efects on local relational reasoning. Journal of Functional Programming 22, 4-5 ( 2012 ), 477-528. https://people.mpi-sws.org/~dreyer/papers/stslr/ journal.pdfGoogle ScholarGoogle ScholarDigital LibraryDigital Library
  17. Jean-Christophe Filliâtre and Mário Pereira. 2016. A Modular Way to Reason About Iteration. In NASA Formal Methods (NFM) (Lecture Notes in Computer Science, Vol. 9690 ). Springer, 322-336. https://hal.inria.fr/hal-01281759Google ScholarGoogle Scholar
  18. Daniel Hillerström and Sam Lindley. 2018. Shallow Efect Handlers. In Asian Symposium on Programming Languages and Systems (APLAS) (Lecture Notes in Computer Science, Vol. 11275 ). Springer, 415-435. http://homepages.inf.ed.ac.uk/ slindley/papers/shallow-extended.pdfGoogle ScholarGoogle Scholar
  19. Daniel Hillerström, Sam Lindley, and Robert Atkey. 2020. Efect handlers via generalised continuations. Journal of Functional Programming 30 ( 2020 ), e5. https://www.dhil.net/research/papers/generalised_continuations-jfp-draft.pdfGoogle ScholarGoogle Scholar
  20. Jonas Kastberg Hinrichsen, Jesper Bengtson, and Robbert Krebbers. 2020. Actris: session-type based reasoning in separation logic. Proceedings of the ACM on Programming Languages 4, POPL ( 2020 ), 6 : 1-6 : 30. https://iris-project.org/pdfs/2020-popl-actris-final.pdfGoogle ScholarGoogle ScholarDigital LibraryDigital Library
  21. Ralf Jung, Robbert Krebbers, Jacques-Henri Jourdan, Aleš Bizjak, Lars Birkedal, and Derek Dreyer. 2018. Iris from the ground up: A modular foundation for higher-order concurrent separation logic. Journal of Functional Programming 28 ( 2018 ), e20. https://people.mpi-sws.org/~dreyer/papers/iris-ground-up/paper.pdfGoogle ScholarGoogle Scholar
  22. Ohad Kammar, Sam Lindley, and Nicolas Oury. 2013. Handlers in action. In International Conference on Functional Programming (ICFP). 145-158. http://homepages.inf.ed.ac.uk/slindley/papers/handlers.pdfGoogle ScholarGoogle ScholarDigital LibraryDigital Library
  23. Johannes Kloos, Rupak Majumdar, and Viktor Vafeiadis. 2015. Asynchronous Liquid Separation Types. In European Conference on Object-Oriented Programming (ECOOP). 396-420. https://www.mpi-sws.org/~viktor/papers/ecoop2015-alstypes.pdfGoogle ScholarGoogle Scholar
  24. Daan Leijen. 2014. Koka: Programming with Row Polymorphic Efect Types. In Workshop on Mathematically Structured Functional Programming (MSFP), Vol. 153. 100-126. https://www.microsoft.com/en-us/research/wp-content/uploads/ 2016/02/paper-20.pdfGoogle ScholarGoogle Scholar
  25. Daan Leijen. 2017. Structured asynchrony with algebraic efects. In Type-Driven Development (TyDe). 16-29. https: //www.microsoft.com/en-us/research/wp-content/uploads/2017/05/asyncefects-msr-tr-2017-21.pdfGoogle ScholarGoogle Scholar
  26. Daan Leijen. 2020. Koka. https://www.microsoft.com/en-us/research/project/koka/Google ScholarGoogle Scholar
  27. Thomas Letan, Yann Régis-Gianas, Pierre Chiflier, and Guillaume Hiet. 2018. Modular Verification of Programs with Efects and Efect Handlers in Coq. In Formal Methods (FM) (Lecture Notes in Computer Science, Vol. 10951 ). Springer, 338-354. https://hal.inria.fr/hal-01799712Google ScholarGoogle Scholar
  28. Sam Lindley, Conor McBride, and Craig McLaughlin. 2017. Do Be Do Be Do. In Principles of Programming Languages (POPL). http://homepages.inf.ed.ac.uk/slindley/papers/frankly.pdfGoogle ScholarGoogle Scholar
  29. Peter W. O'Hearn. 2019. Separation logic. Commun. ACM 62, 2 ( 2019 ), 86-95. https://doi.org/10.1145/3211968 Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. Gordon D. Plotkin and A. John Power. 2004. Computational Efects and Operations: An Overview. Electronic Notes in Theoretical Computer Science 73 ( 2004 ), 149-163. https://doi.org/10.1016/j.entcs. 2004. 08.008 Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. Gordon D. Plotkin and Matija Pretnar. 2008. A Logic for Algebraic Efects. In Logic in Computer Science (LICS). 118-129. http://homepages.inf.ed.ac.uk/gdp/publications/Logic_Algebraic_Efects.pdfGoogle ScholarGoogle Scholar
  32. Gordon D. Plotkin and Matija Pretnar. 2009. Handlers of Algebraic Efects. In European Symposium on Programming (ESOP) (Lecture Notes in Computer Science, Vol. 5502 ). Springer, 80-94. http://homepages.inf.ed.ac.uk/gdp/publications/Efect_Handlers.pdfGoogle ScholarGoogle Scholar
  33. Gordon D. Plotkin and Matija Pretnar. 2013. Handling Algebraic Efects. Logical Methods in Computer Science 9, 4 (Dec. 2013 ). https://lmcs.episciences. org/705Google ScholarGoogle ScholarCross RefCross Ref
  34. François Pottier. 2017. Verifying a hash table and its iterators in higher-order separation logic. In Certified Programs and Proofs (CPP). 3-16. http://gallium.inria.fr/~fpottier/publis/fpottier-hashtable.pdfGoogle ScholarGoogle ScholarDigital LibraryDigital Library
  35. John C. Reynolds. 2002. Separation Logic: A Logic for Shared Mutable Data Structures. In Logic in Computer Science (LICS). 55-74. http://www.cs.cmu.edu/~jcr/seplogic.pdfGoogle ScholarGoogle Scholar
  36. Amin Timany and Lars Birkedal. 2019. Mechanized Relational Verification of Concurrent Programs with Continuations. Proceedings of the ACM on Programming Languages 3, ICFP ( July 2019 ), 105 : 1-105 : 28. http://doi.acm.org/10.1145/3341709 Google ScholarGoogle ScholarDigital LibraryDigital Library
  37. Li-yao Xia, Yannick Zakowski, Paul He, Chung-Kil Hur, Gregory Malecha, Benjamin C. Pierce, and Steve Zdancewic. 2020. Interaction trees: representing recursive and impure programs in Coq. Proceedings of the ACM on Programming Languages 4, POPL ( 2020 ), 51 : 1-51 : 32. https://www.cis.upenn.edu/~stevez/papers/XZHH+20.pdfGoogle ScholarGoogle Scholar
  38. Yizhou Zhang and Andrew C. Myers. 2019. Abstraction-safe efect handlers via tunneling. Proceedings of the ACM on Programming Languages 3, POPL ( 2019 ), 5 : 1-5 : 29. http://www.cs.cornell.edu/andru/papers/tunnel-ef/tunnel-ef.pdfGoogle ScholarGoogle Scholar

Index Terms

  1. A separation logic for effect handlers

      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!