paperbot · PL 论文追踪

全部论文 待读 收藏

P2 Dynamically Checked Deep Immutability in Python

Python 中的动态检查深度不可变性
PLDI 10(PLDI)2026匹配度 1/10 · 该论文属于纯 PL 运行时/语言设计方向,研究 Python 深度不可变性的动态检查与子解释器零拷贝共享,不涉及静态分析、LLM/Agent、浮点程序分析或贝叶斯程序分析等用户核心研究兴趣。引用 0 inbox
Fridtjof Stoldt, Sylvan Clebsch, Matthew A. Johnson, Matthew J. Parkinson, Tobias Wrigstad
crossref: 2026-09-10

AI 速览

一句话:为 Python 设计并实现动态检查的深度不可变性,通过 detachment 与 freezability 实现子解释器间零拷贝共享对象。

不可变性在编程主流中很常见,但 Python 等动态命令式语言的可变性根深蒂固:多数对象可变,模块、类和函数本身也是运行时可变对象,库亦依赖这种可变性,因此引入深度不可变性十分困难。本文旨在让多个子解释器直接共享对象引用,避免昂贵的序列化。其可靠性挑战在于:违反不可变性可能破坏解释器状态。作者识别了数十年语言设计决策遗留的诸多挑战,提出两种互补技术:detachment 切断会导致不可变性过度传播的运行时链接;freezability 让对象在运行时控制是否以及如何变为不可变。二者构成动态语言中深度不可变性的通用设计模式。评估基于 CPython 3.15 的实现,保持向后兼容,并支持不可变对象在子解释器间直接零拷贝共享。

问题
Python 中可变性根深蒂固,如何为其添加深度不可变性,并让多个子解释器安全地直接共享对象引用而无需序列化?核心难点是避免不可变性违规破坏解释器状态。
方法
提出 detachment 与 freezability 两种互补机制:前者切断导致不可变性过度传播的运行时链接,后者让对象在运行时控制其不可变行为;二者形成动态语言深度不可变性的设计模式。
评估
在 CPython 3.15 上实现,验证其向后兼容现有程序,并支持不可变对象跨子解释器直接零拷贝共享。
原文摘要(Abstract)

Immutability is common in the programming mainstream: deep immutability is the default in functional languages while imperative languages typically provide opt-in support for shallow immutability, usually enforced through static checking. Python is a dynamic imperative language where mutability is inherent: not only are most objects mutable, but programs themselves---modules, classes, functions---are represented by mutable objects at run-time, and libraries routinely rely on this mutability. This makes adding immutability to Python a significant challenge. This paper presents the design and implementation of deep immutability for Python. Our primary motivation is to permit multiple sub-interpreters to directly share object references, which currently requires costly serialisation. Sharing via immutability introduces a soundness challenge, as a violation could corrupt the interpreter's state. We identify numerous challenges that stem from decades of design decisions that did not anticipate immutability, and show how they can be overcome through two complementary techniques: detachment, which severs run-time links that would cause immutability to propagate too widely, and freezability, which gives objects run-time control over whether and how they may become immutable. Together, these principles form a general design pattern for deep immutability in dynamic languages. We validate our design with an implementation on CPython 3.15 that is backwards-compatible with existing programs and enables direct, zero-copy sharing of immutable objects across sub-interpreters.

链接与引用

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

BibTeX
@article{StoldtCJPW26,
  title = {Dynamically Checked Deep Immutability in Python},
  author = {Fridtjof Stoldt and Sylvan Clebsch and Matthew A. Johnson and Matthew J. Parkinson and Tobias Wrigstad},
  journal = {Proceedings of the ACM on Programming Languages},
  volume = {10},
  number = {PLDI},
  year = {2026},
  doi = {10.1145/3808352}
}