Refined² Environment Classifiers
Yuito Murase, Atsushi Igarashi
Key points
From the paper's conclusion- Our system builds on refined environment classifiers (RECs), a discipline that annotates code types with the variable scopes on which generated code depends.
Abstract
MetaML-style multi-stage programming (MSP) supports quasi-quotation-based code generation, runtime execution of generated code, and cross-stage persistence (CSP). However, its interaction with computational effects is subtle: mutable state can cause scope extrusion, where generated code escapes the scope of variables on which it depends. This paper presents a type system for MetaML-style MSP with mutable state that statically rules out harmful scope extrusion while supporting multi-level code generation, runtime execution, and a variant of CSP. Our system builds on refined environment classifiers (RECs), a discipline that annotates code types with the variable scopes on which generated code depends. To scale RECs to the MetaML-style setting, we refine classifiers so that they track not only variable scopes, but also the scopes of classifiers themselves. Further, we integrated polymorphism over classifiers, enabling more general and reusable code generation patterns in a multi-level setting. For the resulting system, we define an operational semantics via a definitional interpreter and prove type soundness and safety of offline code generation, showing that generated code can be extracted as standalone well-typed programs. We provide working implementations and mechanized proofs in Rocq.
Read the paper
Discussion
Science Skim's AI key points, plus readers' public thoughts
Readers' thoughts
No reader thoughts yet.
Related papers
- Compiling Environment Classifiers to Contextual Modal TypesarXiv · 2026
- When Do Staging Annotations Preserve Semantics? Mechanizing Typed Semantics-Preserving Multi-stage Programming with Let-InsertionProceedings of the ACM on Programming Languages · 2026
- Polymorphic First-Class EnvironmentsarXiv · 2026
- Linking as Evaluation: Correct Separate Compilation via First-Class EnvironmentsarXiv · 2026
- SkillEffect: Checked Lowering for Memory-Bounded Agent ToolsarXiv · 2026
- Classifying CapabilitiesProceedings of the ACM on Programming Languages · 2026