skip to main content
10.1145/3635800.3636968acmconferencesArticle/Chapter ViewAbstractPublication PagespepmConference Proceedingsconference-collections
research-article

An Intrinsically Typed Compiler for Algebraic Effect Handlers

Published: 11 January 2024 Publication History

Abstract

A type-preserving compiler converts a well-typed input program into a well-typed output program. Previous studies have developed type-preserving compilers for various source languages, including the simply-typed lambda calculus and calculi with control constructs. Our goal is to realize type-preserving compilation of languages that have facilities for manipulating first-class continuations. In this paper, we focus on algebraic effects and handlers, a generalization of exceptions and their handlers with resumable continuations. Specifically, we choose an effect handler calculus and a typed stack-machine-based assembly language as the source and the target languages, respectively, and formalize the target language and a type preserving compiler. The main challenge posed by first-class continuation is how to ensure safety of continuation capture and resumption, which involves concatenation of unknown stacks. We solve this challenge by incorporating stack polymorphism, a technique that has been used for compilation from a language without first-class continuations to a stack-based assembly language. To prove that our compiler is type preserving, we implemented the compiler in Agda as a function between intrinsically typed ASTs. We believe that our contributions could lead to correct and efficient compilation of continuation-manipulating facilities in general.

References

[1]
Robert Atkey. 2018. Syntax and Semantics of Quantitative Type Theory. LICS ’18. https://doi.org/10.1145/3209108.3209189
[2]
Patrick Bahr and Graham Hutton. 2022. Monadic Compiler Calculation (Functional Pearl). Proc. ACM Program. Lang., 6, ICFP (2022), Article 93, Aug, 29 pages. https://doi.org/10.1145/3547624
[3]
William J. Bowman, Youyou Cong, Nick Rioux, and Amal Ahmed. 2017. Type-Preserving CPS Translation of Σ and Π Types is Not Not Possible. Proc. ACM Program. Lang., 2, POPL (2017), Article 22, dec, 33 pages. https://doi.org/10.1145/3158110
[4]
Edwin Brady. 2021. Idris 2: Quantitative Type Theory in Practice. In 35th European Conference on Object-Oriented Programming (ECOOP ’21). https://doi.org/10.4230/DARTS.7.2.10
[5]
James Cheney and Ralf Hinze. 2003. First-class phantom types. Cornell University.
[6]
Adam Chlipala. 2007. A Certified Type-Preserving Compiler from Lambda Calculus to Assembly Language. In Proceedings of the 28th ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI ’07). Association for Computing Machinery, New York, NY, USA. 54–65. isbn:9781595936332 https://doi.org/10.1145/1250734.1250742
[7]
Yannick Forster, Ohad Kammar, Sam Lindley, and Matija Pretnar. 2017. On the Expressive Power of User-Defined Effects: Effect Handlers, Monadic Reflection, Delimited Control. Proc. ACM Program. Lang., 1, ICFP (2017), Article 13, aug, 29 pages. https://doi.org/10.1145/3110257
[8]
Louis-Julien Guillemette and Stefan Monnier. 2008. A Type-Preserving Compiler in Haskell. In Proceedings of the 13th ACM SIGPLAN International Conference on Functional Programming (ICFP ’08). Association for Computing Machinery, New York, NY, USA. 75–86. isbn:9781595939197 https://doi.org/10.1145/1411204.1411218
[9]
Daniel Hillerström, Sam Lindley, Robert Atkey, and K. C. Sivaramakrishnan. 2017. Continuation Passing Style for Effect Handlers. In 2nd International Conference on Formal Structures for Computation and Deduction, Dale Miller (Ed.) (FSCD ’17, Vol. 84). Schloss Dagstuhl–Leibniz-Zentrum fuer Informatik, Dagstuhl, Germany. 18:1–18:19. isbn:978-3-95977-047-7 issn:1868-8969 https://doi.org/10.4230/LIPIcs.FSCD.2017.18
[10]
Daan Leijen. 2014. Koka: Programming with row polymorphic effect types. In 5th Workshop on Mathematically Structured Functional Programming (MSFP ’14).
[11]
Paul Blain Levy, John Power, and Hayo Thielecke. 2003. Modelling Environments in Call-by-Value Programming Languages. Inf. Comput., 185, 2 (2003), sep, 182–210. issn:0890-5401 https://doi.org/10.1016/S0890-5401(03)00088-9
[12]
Marek Materzok and Dariusz Biernacki. 2011. Subtyping Delimited Continuations. In Proceedings of the 16th ACM SIGPLAN International Conference on Functional Programming (ICFP ’11). Association for Computing Machinery, New York, NY, USA. 81–93. isbn:9781450308656 https://doi.org/10.1145/2034773.2034786
[13]
Greg Morrisett, Karl Crary, Neal Glew, and David Walker. 2002. Stack-based typed assembly language. Journal of Functional Programming, 12, 1 (2002), 43–88. https://doi.org/10.1017/S0956796801004178
[14]
Greg Morrisett, David Walker, Karl Crary, and Neal Glew. 1999. From System F to Typed Assembly Language. ACM Trans. Program. Lang. Syst., 21, 3 (1999), may, 527–568. issn:0164-0925 https://doi.org/10.1145/319301.319345
[15]
Ulf Norell. 2007. Towards a practical programming language based on dependent type theory. Ph. D. Dissertation. Chalmers University of Technology. https://api.semanticscholar.org/CorpusID:118357515
[16]
Mitchell Pickard and Graham Hutton. 2021. Calculating Dependently-Typed Compilers (Functional Pearl). Proc. ACM Program. Lang., 5, ICFP (2021), Article 82, Aug, 27 pages. https://doi.org/10.1145/3473587
[17]
Maciej Piróg, Piotr Polesiuk, and Filip Sieczkowski. 2019. Typed Equivalence of Effect Handlers and Delimited Control. In 4th International Conference on Formal Structures for Computation and Deduction (FSCD 2019), Herman Geuvers (Ed.) (Leibniz International Proceedings in Informatics (LIPIcs), Vol. 131). Schloss Dagstuhl – Leibniz-Zentrum für Informatik, Dagstuhl, Germany. 30:1–30:16. isbn:978-3-95977-107-8 issn:1868-8969 https://doi.org/10.4230/LIPIcs.FSCD.2019.30
[18]
Gordon Plotkin and Matija Pretnar. 2009. Handlers of Algebraic Effects. In Programming Languages and Systems, Giuseppe Castagna (Ed.). Springer Berlin Heidelberg, Berlin, Heidelberg. 80–94. isbn:978-3-642-00590-9 https://doi.org/10.1007/978-3-642-00590-9_7
[19]
Arjen Rouvoet, Robbert Krebbers, and Eelco Visser. 2021. Intrinsically Typed Compilation with Nameless Labels. Proceedings of the ACM on Programming Languages, 5, POPL (2021), Article 22, Jan, 28 pages. https://doi.org/10.1145/3434303
[20]
Philipp Schuster, Jonathan Immanuel Brachthäuser, Marius Müller, and Klaus Ostermann. 2022. A Typed Continuation-Passing Translation for Lexical Effect Handlers. In Proceedings of the 43rd ACM SIGPLAN International Conference on Programming Language Design and Implementation (PLDI 2022). Association for Computing Machinery, New York, NY, USA. 566–579. isbn:9781450392655 https://doi.org/10.1145/3519939.3523710
[21]
Hongwei Xi, Chiyan Chen, and Gang Chen. 2003. Guarded Recursive Datatype Constructors. In Proceedings of the 30th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’03). Association for Computing Machinery, New York, NY, USA. 224–235. isbn:1581136285 https://doi.org/10.1145/604131.604150
[22]
Ningning Xie, Jonathan Immanuel Brachthäuser, Daniel Hillerström, Philipp Schuster, and Daan Leijen. 2020. Effect Handlers, Evidently. Proc. ACM Program. Lang., 4, ICFP (2020), Article 99, Aug, 29 pages. https://doi.org/10.1145/3408981

Recommendations

Comments

Information & Contributors

Information

Published In

cover image ACM Conferences
PEPM 2024: Proceedings of the 2024 ACM SIGPLAN International Workshop on Partial Evaluation and Program Manipulation
January 2024
145 pages
ISBN:9798400704871
DOI:10.1145/3635800
Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than the author(s) must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected].

Sponsors

In-Cooperation

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 11 January 2024

Permissions

Request permissions for this article.

Check for updates

Author Tags

  1. algebraic effect handlers
  2. dependent types
  3. type-preserving compilers

Qualifiers

  • Research-article

Funding Sources

Conference

PEPM '24
Sponsor:

Acceptance Rates

Overall Acceptance Rate 66 of 120 submissions, 55%

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • 0
    Total Citations
  • 358
    Total Downloads
  • Downloads (Last 12 months)63
  • Downloads (Last 6 weeks)4
Reflects downloads up to 07 Mar 2025

Other Metrics

Citations

View Options

Login options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Figures

Tables

Media

Share

Share

Share this Publication link

Share on social media