Handling Scope Checks: A Comparative Framework for Dynamic Scope Extrusion Checks
Michael Lee, Ningning Xie, Oleg Kiselyov, Jeremy Yallop
Abstract
Metaprogramming and effect handlers interact in unexpected, and sometimes undesirable, ways. One example is scope extrusion: the generation of ill-scoped code. Scope extrusion can either be preemptively prevented, via static type systems, or retroactively detected, via dynamic checks. Static type systems exist in theory, but struggle with a range of implementation and usability problems in practice. In contrast, dynamic checks exist in practice (e.g. in MetaOCaml), but are understudied in theory. Designers of metaprogramming languages are thus given little guidance regarding the design and implementation of checks. We present the first formal study of dynamic scope extrusion checks, introducing a calculus (𝜆 ⟨ ⟨op⟩ ⟩ ) for describing and evaluating checks. Further, we introduce a novel dynamic check -the "Cause-for-Concern" check -which we prove correct, characterise without reference to its implementation, and argue combines the advantages of existing dynamic checks. Finally, we extend our framework with refined environment classifiers, which statically prevent scope extrusion, and compare their expressivity with the dynamic checks.
CCS Concepts: • Software and its engineering → Control structures.
Ask about this paper
Your agent reads all of it.
Lune indexed this paper to the last equation, along with the top-tier papers that cite it. Ask a question and the answer quotes them.
Your agent calls
Luneget_paper_fulltext
Free to start. No credit card required.
Terminal
Install the CLIlune papers fulltext 1f5fb722-fe83-442e-9d11-71519efe7d76Cited by top-tier papers1
Ask how each one uses itBuilds on5
- Retrofitting effect handlers onto OCamlK. C. Sivaramakrishnan, Stephen Dolan, Leo White, Tom Kelly et al.PLDI 2021 · 56 citations
- Staging with class: a specification for typed template HaskellNingning Xie, Matthew Pickering, Andres Löh, Nicolas Wu et al.POPL 2022 · 17 citations
- flap: A Deterministic Parser with Fused LexingJeremy Yallop, Ningning Xie, Neel KrishnaswamiPLDI 2023 · 10 citations
- Compiler and runtime support for continuation marksMatthew Flatt, R. Kent DybvigPLDI 2020 · 9 citations
- Handling the Selection MonadGordon D. Plotkin, Ningning XiePLDI 2025 · 1 citation
Related papers
- Refined² Environment ClassifiersYuito Murase, Atsushi IgarashiOOPSLA 2026
- Modal Effect TypesWenhao Tang, Leo White, Stephen Dolan, Daniel Hillerström et al.OOPSLA 2025 · 4 citations
- From Capabilities to Regions: Enabling Efficient Compilation of Lexical Effect HandlersMarius Müller, Philipp Schuster, Jonathan Lindegaard Starup, Klaus Ostermann et al.OOPSLA 2023 · 7 citations
- When Do Staging Annotations Preserve Semantics? Mechanizing Typed Semantics-Preserving Multi-stage Programming with Let-InsertionJun Tan, Guannan WeiOOPSLA 2026
- Dynamic Wind for Effect HandlersDavid Voigt, Philipp Schuster, Jonathan Immanuel BrachthäuserOOPSLA 2025
