Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
skip to main content
research-article
Open access

Abstraction-safe effect handlers via tunneling

Published: 02 January 2019 Publication History

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.

Supplementary Material

WEBM File (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.
[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.
[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.
[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.
[5]
Andrej Bauer and Matija Pretnar. Programming with algebraic effects and handlers. Journal of Logical and Algebraic Methods in Programming, 84(1), 2015.
[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.
[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.
[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.
[9]
Jonathan Immanuel Brachthäuser, Philipp Schuster, and Klaus Ostermann. Algebraic effects for the masses. Proc. ACM on Programming Languages, 2(OOPSLA), October 2018.
[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.
[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.
[12]
Olivier Danvy and Andrzej Filinski. Abstracting control. In ACM Conf. on LISP and Functional Programming, pages 151–160, 1990.
[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.
[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.
[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.
[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.
[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.
[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.
[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.
[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.
[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.
[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.
[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.
[24]
Ohad Kammar, Sam Lindley, and Nicolas Oury. Handlers in action. In 18 th ACM SIGPLAN Int’l Conf. on Functional Programming, 2013.
[25]
Donald Ervin Knuth. The TEXbook. Addison-Wesley Reading, 1984.
[26]
Daan Leijen. Koka: Programming with row polymorphic effect types. In 5th Workshop on Mathematically Structured Functional Programming. EPTCS, 2014.
[27]
Daan Leijen. Type directed compilation of row-typed algebraic effects. In 44 th ACM Symp. on Principles of Programming Languages (POPL), 2017.
[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.
[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.
[30]
Robin Milner. A theory of type polymorphism in programming. Journal of Computer and System Sciences, 17(3):348–375, 1978.
[31]
Robin Milner, Mads Tofte, and Robert Harper. The Definition of Standard ML. MIT Press, Cambridge, MA, 1990. ISBN 978-0262631327.
[32]
J. H. Morris, Jr. Lambda-Calculus Models of Programming Languages. PhD thesis, Massachusetts Institute of Technology, 1968.
[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.
[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.
[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.
[36]
Andrew M Pitts and Ian Stark. Operational reasoning for functions with local state. Higher order operational techniques in semantics, pages 227–273, 1998.
[37]
Gordon Plotkin and John Power. Algebraic operations and generic effects. Applied Categorical Structures, 11(1):69–94, Feb 2003.
[38]
Gordon Plotkin and Matija Pretnar. Handling algebraic effects. Logical Methods in Computer Science, Volume 9, Issue 4, December 2013.
[39]
Piotr Polesiuk. IxFree: Step-indexed logical relations in Coq. In 3 rd International Workshop on Coq for Programming Languages (CoqPL), 2017.
[40]
John C. Reynolds. Types, abstraction and parametric polymorphism. In IFIP Congress, pages 513–523, 1983.
[41]
Lukas Rytz, Martin Odersky, and Philipp Haller. Lightweight polymorphic effects. In 26 th European Conf. on Object-Oriented Programming, 2012.
[42]
Guy L. Steele, Jr. Common LISP: the Language. Digital Press, second edition, 1990. ISBN 1-55558-041-6.
[43]
Mads Tofte and Jean-Pierre Talpin. Region-based memory management. Information and Computation, 132(2):109–176, 1997.
[44]
Philip Wadler. Theorems for free! In 4 th Conf. on Functional Programming Languages and Computer Architecture (FPCA), pages 347–359, September 1989.
[45]
Andrew K. Wright and Matthias Felleisen. A syntactic approach to type soundness. Information and Computation, 115(1): 38–94, 1994. ISSN 0890-5401.
[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 .
[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 .

Cited By

View all
  • (2024)Lexical Effect Handlers, DirectlyProceedings of the ACM on Programming Languages10.1145/36897708:OOPSLA2(1670-1698)Online publication date: 8-Oct-2024
  • (2024)Stack-Copying Delimited Continuations for Scala NativeProceedings of the 19th ACM International Workshop on Implementation, Compilation, Optimization of OO Languages, Programs and Systems10.1145/3679005.3685979(2-13)Online publication date: 13-Sep-2024
  • (2024)Abstracting Effect Systems for Algebraic Effect HandlersProceedings of the ACM on Programming Languages10.1145/36746418:ICFP(455-484)Online publication date: 15-Aug-2024
  • Show More Cited By

Recommendations

Comments

Information & Contributors

Information

Published In

cover image Proceedings of the ACM on Programming Languages
Proceedings of the ACM on Programming Languages  Volume 3, Issue POPL
January 2019
2275 pages
EISSN:2475-1421
DOI:10.1145/3302515
Issue’s Table of Contents
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike International 4.0 License.

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 02 January 2019
Published in PACMPL Volume 3, Issue POPL

Permissions

Request permissions for this article.

Check for updates

Author Tags

  1. Algebraic effects
  2. dynamic scoping
  3. exceptions
  4. parametricity
  5. type systems

Qualifiers

  • Research-article

Funding Sources

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)232
  • Downloads (Last 6 weeks)27
Reflects downloads up to 16 Oct 2024

Other Metrics

Citations

Cited By

View all
  • (2024)Lexical Effect Handlers, DirectlyProceedings of the ACM on Programming Languages10.1145/36897708:OOPSLA2(1670-1698)Online publication date: 8-Oct-2024
  • (2024)Stack-Copying Delimited Continuations for Scala NativeProceedings of the 19th ACM International Workshop on Implementation, Compilation, Optimization of OO Languages, Programs and Systems10.1145/3679005.3685979(2-13)Online publication date: 13-Sep-2024
  • (2024)Abstracting Effect Systems for Algebraic Effect HandlersProceedings of the ACM on Programming Languages10.1145/36746418:ICFP(455-484)Online publication date: 15-Aug-2024
  • (2024)Answer Refinement Modification: Refinement Type System for Algebraic Effects and HandlersProceedings of the ACM on Programming Languages10.1145/36332808:POPL(115-147)Online publication date: 5-Jan-2024
  • (2024)Effectful Software ContractsProceedings of the ACM on Programming Languages10.1145/36329308:POPL(2639-2666)Online publication date: 5-Jan-2024
  • (2024)Algebraic Effects Meet Hoare Logic in Cubical AgdaProceedings of the ACM on Programming Languages10.1145/36328988:POPL(1663-1695)Online publication date: 5-Jan-2024
  • (2023)From Capabilities to Regions: Enabling Efficient Compilation of Lexical Effect HandlersProceedings of the ACM on Programming Languages10.1145/36228317:OOPSLA2(941-970)Online publication date: 16-Oct-2023
  • (2023)Capturing TypesACM Transactions on Programming Languages and Systems10.1145/361800345:4(1-52)Online publication date: 20-Nov-2023
  • (2023)A General Fine-Grained Reduction Theory for Effect HandlersProceedings of the ACM on Programming Languages10.1145/36078487:ICFP(511-540)Online publication date: 31-Aug-2023
  • (2023)Hefty Algebras: Modular Elaboration of Higher-Order Algebraic EffectsProceedings of the ACM on Programming Languages10.1145/35712557:POPL(1801-1831)Online publication date: 11-Jan-2023
  • Show More Cited By

View Options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Get Access

Login options

Full Access

Media

Figures

Other

Tables

Share

Share

Share this Publication link

Share on social media