Handling bidirectional control flow: Technical report

dc.contributor.authorZhang, Yizhou
dc.contributor.authorSalvaneschi, Guido
dc.contributor.authorMyers, Andrew C.
dc.date.accessioned2026-07-30T17:57:17Z
dc.date.issued2020-10
dc.description.abstractPressed by the difficulty of writing asynchronous, event-driven code, mainstream languages have recently been building in support for a variety of advanced control-flow features. Meanwhile experimental language designs have suggested effect handlers as a unifying solution to programmer-defined control effects, subsuming exceptions, generators, and async-await. However, despite these trends, complex control flow - in particular, control flow that exhibits a bidirectional pattern - remains challenging to manage. We introduce bidirectional algebraic effects, a new programming abstraction that supports bidirectional control transfer in a more natural way. Handlers of bidirectional effects can raise further effects to transfer control back to the site where the initiating effect was raised, and can use themselves to handle their own effects. We present applications of this expressive power, which falls out naturally as we push toward the unification of effectful programming with object-oriented programming. We pin down the mechanism and the unification formally using a core language that makes generalization to effect operations and effect handlers. The usual propagation semantics of control effects such as exceptions conflicts with modular reasoning in the presence of effect polymorphism - it breaks parametricity. Bidirectionality exacerbates the problem. Hence, we set out to show the core language, which builds on the existing tunneling semantics for algebraic effects, is not only type-safe (no effects go unhandled), but also abstraction-safe (no effects are accidentally handled). We devise a step-indexed logical-relations model, and construct its parametricity and soundness proofs. These core results are fully mechanized in Coq. While a full-featured compiler is left to future work, experiments show that as a first-class language feature, bidirectional handlers can be implemented efficiently.
dc.identifier.urihttps://hdl.handle.net/10012/23894
dc.language.isoen
dc.publisherUniversity of Waterloo
dc.relation.ispartofseriesComputer Science Technical Reports; CS-2020-07
dc.titleHandling bidirectional control flow: Technical report
dc.typeTechnical Report
uws.contributor.affiliation1Faculty of Mathematics
uws.contributor.affiliation2David R. Cheriton School of Computer Science
uws.peerReviewStatusUnreviewed
uws.scholarLevelFaculty
uws.typeOfResourceTexten

Files

Original bundle

Now showing 1 - 1 of 1
Loading...
Thumbnail Image
Name:
cs-2020-07.pdf
Size:
1.01 MB
Format:
Adobe Portable Document Format

License bundle

Now showing 1 - 1 of 1
Loading...
Thumbnail Image
Name:
license.txt
Size:
4.47 KB
Format:
Item-specific license agreed upon to submission
Description: