paperbot · PL 论文追踪

全部论文 待读 收藏

P2 Mœbius: metaprogramming using contextual types: the stage where system f can pattern match on itself

Mœbius:使用上下文类型的元编程——System F 能对自身进行模式匹配的阶段
POPL 6(POPL)2022匹配度 1/10 · 该论文是纯类型论与元编程语言基础研究,关注多态代码生成、开放代码模式匹配与类型保持,属于 PL 理论,但与用户核心方向(ML/Agentic 程序静态分析、LLM 辅助静态分析/形式化验证、浮点程序分析、贝叶斯程序分析)没有直接关联。引用 28 inbox
Junyoung Jang, Samuel Gélineau, Stefan Monnier, Brigitte Pientka
crossref: 2026-09-10

AI 速览

一句话:提出 Mœbius 元编程语言基础,支持多态代码生成与对开放代码的模式匹配,并证明类型保持。

元编程中生成多态代码已具挑战,而分析多态代码——尤其是对开放代码和代码模板进行模式匹配——更缺乏类型论基础。Mœbius 通过上下文模态类型描述开放代码及其有意义的上下文,允许开放代码依赖第 0 层的类型与项变量以及第 1 层的代码变量,从而形成支持 System-F 风格多态的多级模态 λ 演算。论文进一步扩展该演算以支持对代码的模式匹配,并生成和追踪因精化多态类型变量而产生的类型约束。作者给出操作语义并证明类型保持。该基础在不固定变量绑定与上下文具体表示的前提下,为多阶段元编程提供了兼具强类型保证与代码生成/操作便利性的抽象。

问题
如何为多阶段元编程提供类型论基础,使其既能生成多态代码,又能对开放代码和代码模板进行模式匹配。
方法
利用上下文模态类型与多级模态 λ 演算表示开放代码及其上下文,支持第 0 层类型/项变量与第 1 层代码变量;扩展演算以对代码模式匹配并追踪类型约束,并定义操作语义、证明类型保持。
评估
以操作语义定义和类型保持性定理作为主要形式化验证,摘要中未报告原型实现或实证评估。
原文摘要(Abstract)

We describe the foundation of the metaprogramming language, Mœbius, which supports the generation of polymorphic code and, more importantly, the analysis of polymorphic code via pattern matching. Mœbius has two main ingredients: 1) we exploit contextual modal types to describe open code together with the context in which it is meaningful. In Mœbius, open code can depend on type and term variables (level 0) whose values are supplied at a later stage, as well as code variables (level 1) that stand for code templates supplied at a later stage. This leads to a multi-level modal lambda-calculus that supports System-F style polymorphism and forms the basis for polymorphic code generation. 2) we extend the multi-level modal lambda-calculus to support pattern matching on code. As pattern matching on polymorphic code may refine polymorphic type variables, we extend our type-theoretic foundation to generate and track typing constraints that arise. We also give an operational semantics and prove type preservation. Our multi-level modal foundation for Mœbius provides the appropriate abstractions for both generating and pattern matching on open code without committing to a concrete representation of variable binding and contexts. Hence, our work is a step towards building a general type-theoretic foundation for multi-staged metaprogramming that, on the one hand, enforces strong type guarantees and, on the other hand, makes it easy to generate and manipulate code. This will allow us to exploit the full potential of metaprogramming without sacrificing the reliability of and trust in the code we are producing and running.

链接与引用

DOI 原文 · PDF(开放获取) ·

BibTeX
@article{paperbot1598,
  title = {Mœbius: metaprogramming using contextual types: the stage where system f can pattern match on itself},
  author = {Junyoung Jang and Samuel Gélineau and Stefan Monnier and Brigitte Pientka},
  journal = {Proceedings of the ACM on Programming Languages},
  volume = {6},
  number = {POPL},
  year = {2022},
  doi = {10.1145/3498700}
}