skip to main content
research-article
Open Access

Abstraction-safe effect handlers via tunneling

Published:02 January 2019Publication History
Skip Abstract Section

Abstract

Algebraic effect handlers offer a unified approach to expressing control-flow transfer idioms such as exceptions, iteration, and async/await. Unfortunately, previous attempts to make these handlers type-safe have failed to support the fundamental principle of modular reasoning for higher-order abstractions. We demonstrate that abstraction-safe algebraic effect handlers are possible by giving them a new semantics. The key insight is that code should only handle effects it is aware of. In our approach, the type system guarantees all effects are handled, but it is impossible for higher-order, effect-polymorphic code to accidentally handle effects raised by functions passed in; such effects tunnel through the higher-order, calling procedures polymorphic to them. By contrast, the possibility of accidental handling threatens previous designs for algebraic effect handlers. We prove that our design is not only type-safe, but also abstraction-safe. Using a logical-relations model that we prove sound with respect to contextual equivalence, we derive previously unattainable program equivalence results. Our mechanism offers a viable approach for future language designs aiming for effect handlers with strong abstraction guarantees.

Skip Supplemental Material Section

Supplemental Material

a5-zhang.webm

References

  1. Amal Ahmed. Step-indexed syntactic logical relations for recursive and quantified types. In 15 th European Symposium on Programming, 2006. Extended/corrected version available as Harvard University TR-01-06. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Andrew W. Appel and David McAllester. An indexed model of recursive types for foundational proof-carrying code. ACM Trans. on Programming Languages and Systems, 23(5), September 2001. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Andrew W. Appel, Paul-André Melliès, Christopher D. Richards, and Jérôme Vouillon. A very modal model of a modern, major, general type system. In 34 th ACM Symp. on Principles of Programming Languages (POPL), 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Andrej Bauer and Matija Pretnar. An effect system for algebraic effects and handlers. Logical Methods in Computer Science, Volume 10, Issue 4, December 2014.Google ScholarGoogle ScholarCross RefCross Ref
  5. Andrej Bauer and Matija Pretnar. Programming with algebraic effects and handlers. Journal of Logical and Algebraic Methods in Programming, 84(1), 2015.Google ScholarGoogle ScholarCross RefCross Ref
  6. Nick Benton and Uri Zarfaty. Formalizing and verifying semantic type soundness of a simple compiler. In Proceedings of the 9th ACM SIGPLAN International Conference on Principles and Practice of Declarative Programming, pages 1–12, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Dariusz Biernacki, Maciej Piróg, Piotr Polesiuk, and Filip Sieczkowski. Handle with care: Relational interpretation of algebraic effects and handlers. Proc. ACM on Programming Languages, 2(POPL), December 2017. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Jonathan Immanuel Brachthäuser and Philipp Schuster. Effekt: Extensible algebraic effects in Scala (short paper). In Proceedings of the 8th ACM SIGPLAN International Symposium on Scala, 2017. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Jonathan Immanuel Brachthäuser, Philipp Schuster, and Klaus Ostermann. Algebraic effects for the masses. Proc. ACM on Programming Languages, 2(OOPSLA), October 2018.Google ScholarGoogle Scholar
  10. Oliver Bračevac, Nada Amin, Guido Salvaneschi, Sebastian Erdweg, Patrick Eugster, and Mira Mezini. Versatile event correlation with algebraic effects. Proc. ACM on Programming Languages, 2(ICFP), August 2018. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Karl Crary, David Walker, and Greg Morrisett. Typed memory management in a calculus of capabilities. In 26 th ACM Symp. on Principles of Programming Languages (POPL), 1999. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Olivier Danvy and Andrzej Filinski. Abstracting control. In ACM Conf. on LISP and Functional Programming, pages 151–160, 1990. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. Derek Dreyer. Milner award lecture: The type soundness theorem that you really want to prove (and now you can). In 45 th ACM Symp. on Principles of Programming Languages (POPL), 2018.Google ScholarGoogle Scholar
  14. Derek Dreyer, Amal Ahmed, and Lars Birkedal. Logical step-indexed logical relations. In 24th Annual IEEE Symposium on Logic In Computer Science (LICS), 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Derek Dreyer, Georg Neis, and Lars Birkedal. The impact of higher-order state and control effects on local relational reasoning. Journal of Functional Programming, 22(4-5):477–528, 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. R. Kent Dyvbig, Simon Peyton Jones, and Amr Sabry. A monadic framework for delimited continuations. Journal of Functional Programming, 17(6):687–730, November 2007. ISSN 0956-7968. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. Matthias Felleisen. The calculi of λ-v-CS conversion: A syntactic theory of control and state in imperative higher-order programming languages. PhD thesis, Indiana University, Indianapolis, IN, USA, 1987. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. Mattias Felleisen. The theory and practice of first-class prompts. In 15 th ACM Symp. on Principles of Programming Languages (POPL), pages 180–190, 1988. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides. Design Patterns: Elements of Reusable Object-Oriented Software. Addison Wesley, Reading, MA, 1994. ISBN 0-201-63361-2. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. Dan Grossman, Greg Morrisett, Trevor Jim, Michael Hicks, Yanling Wang, and James Cheney. Region-based memory management in Cyclone. In ACM SIGPLAN Conf. on Programming Language Design and Implementation (PLDI), pages 282–293. ACM Press, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. Carl A. Gunter, Didier Rémy, and Jon G. Riecke. A generalization of exceptions and control in ml-like languages. In 7 th Conf. on Functional Programming Languages and Computer Architecture (FPCA), 1995. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. Daniel Hillerström and Sam Lindley. Liberating effects with rows and handlers. In Proceedings of the 1st International Workshop on Type-Driven Development, 2016. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. Patricia Johann, Alex Simpson, and Janis Voigtländer. A generic operational metatheory for algebraic effects. In 25th Annual IEEE Symposium on Logic In Computer Science (LICS), 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. Ohad Kammar, Sam Lindley, and Nicolas Oury. Handlers in action. In 18 th ACM SIGPLAN Int’l Conf. on Functional Programming, 2013. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. Donald Ervin Knuth. The TEXbook. Addison-Wesley Reading, 1984.Google ScholarGoogle Scholar
  26. Daan Leijen. Koka: Programming with row polymorphic effect types. In 5th Workshop on Mathematically Structured Functional Programming. EPTCS, 2014.Google ScholarGoogle ScholarCross RefCross Ref
  27. Daan Leijen. Type directed compilation of row-typed algebraic effects. In 44 th ACM Symp. on Principles of Programming Languages (POPL), 2017. Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. Jeffrey R. Lewis, John Launchbury, Erik Meijer, and Mark B. Shields. Implicit parameters: Dynamic scoping with static types. In 27 th ACM Symp. on Principles of Programming Languages (POPL), 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. Sam Lindley, Conor McBride, and Craig McLaughlin. Do be do be do. In 44 th ACM Symp. on Principles of Programming Languages (POPL), 2017. Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. Robin Milner. A theory of type polymorphism in programming. Journal of Computer and System Sciences, 17(3):348–375, 1978.Google ScholarGoogle Scholar
  31. Robin Milner, Mads Tofte, and Robert Harper. The Definition of Standard ML. MIT Press, Cambridge, MA, 1990. ISBN 978-0262631327. Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. J. H. Morris, Jr. Lambda-Calculus Models of Programming Languages. PhD thesis, Massachusetts Institute of Technology, 1968.Google ScholarGoogle Scholar
  33. Martin Odersky, Olivier Blanvillain, Fengyun Liu, Aggelos Biboudis, Heather Miller, and Sandro Stucki. Simplicitly: Foundations and applications of implicit function types. Proc. ACM on Programming Languages, 2(POPL), December 2017. Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. Bruno C.d.S. Oliveira, Adriaan Moors, and Martin Odersky. Type classes as objects and implicits. In 25 th ACM SIGPLAN Conf. on Object-Oriented Programming, Systems, Languages and Applications (OOPSLA), 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. Leo Osvald, Grégory Essertel, Xilun Wu, Lilliam I. González Alayón, and Tiark Rompf. Gentrification gone too far? Affordable 2nd-class values for fun and (co-)effect. In 2016 ACM SIGPLAN Conf. on Object-Oriented Programming, Systems, Languages and Applications (OOPSLA), 2016. Google ScholarGoogle ScholarDigital LibraryDigital Library
  36. Andrew M Pitts and Ian Stark. Operational reasoning for functions with local state. Higher order operational techniques in semantics, pages 227–273, 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  37. Gordon Plotkin and John Power. Algebraic operations and generic effects. Applied Categorical Structures, 11(1):69–94, Feb 2003.Google ScholarGoogle ScholarCross RefCross Ref
  38. Gordon Plotkin and Matija Pretnar. Handling algebraic effects. Logical Methods in Computer Science, Volume 9, Issue 4, December 2013.Google ScholarGoogle ScholarCross RefCross Ref
  39. Piotr Polesiuk. IxFree: Step-indexed logical relations in Coq. In 3 rd International Workshop on Coq for Programming Languages (CoqPL), 2017.Google ScholarGoogle Scholar
  40. John C. Reynolds. Types, abstraction and parametric polymorphism. In IFIP Congress, pages 513–523, 1983.Google ScholarGoogle Scholar
  41. Lukas Rytz, Martin Odersky, and Philipp Haller. Lightweight polymorphic effects. In 26 th European Conf. on Object-Oriented Programming, 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  42. Guy L. Steele, Jr. Common LISP: the Language. Digital Press, second edition, 1990. ISBN 1-55558-041-6. Google ScholarGoogle ScholarDigital LibraryDigital Library
  43. Mads Tofte and Jean-Pierre Talpin. Region-based memory management. Information and Computation, 132(2):109–176, 1997. Google ScholarGoogle ScholarDigital LibraryDigital Library
  44. Philip Wadler. Theorems for free! In 4 th Conf. on Functional Programming Languages and Computer Architecture (FPCA), pages 347–359, September 1989. Google ScholarGoogle ScholarDigital LibraryDigital Library
  45. Andrew K. Wright and Matthias Felleisen. A syntactic approach to type soundness. Information and Computation, 115(1): 38–94, 1994. ISSN 0890-5401. Google ScholarGoogle ScholarDigital LibraryDigital Library
  46. Yizhou Zhang and Andrew C. Myers. Abstraction-safe effect handlers via tunneling: technical report. Technical Report 1813– 60202, Cornell University Computing and Information Science, November 2018. URL http://hdl.handle.net/1813/60202 .Google ScholarGoogle Scholar
  47. Yizhou Zhang, Guido Salvaneschi, Quinn Beightol, Barbara Liskov, and Andrew C. Myers. Accepting blame for safe tunneled exceptions. In 37 th ACM SIGPLAN Conf. on Programming Language Design and Implementation (PLDI), pages 281–295, June 2016. URL http://www.cs.cornell.edu/andru/papers/exceptions . Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Abstraction-safe effect handlers via tunneling

    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!