一句话:提出 PICO 类型系统,用 readonly 引用与 viewpoint adaptation 支持传递、抽象及类多态不可变性,并证明类型可靠性与状态保持保证。
状态突变易导致不变量破坏与安全漏洞,而传递/抽象不可变性、readonly 引用、子类型多态及可变/不可变类变体重复难以兼顾。本文提出 PICO 类型系统,用新的 viewpoint adaptation 规则实现传递抽象不可变性,避免可变与不可变跨类型别名的不可靠,并定义抽象状态以允许对象图局部可变。PICO 在单一系统中提供抽象、具体、readonly 与传递四类状态保持保证,支持类可变性多态,避免重复变体且可改造既有层次。作者在 Rocq 中证明类型可靠性与四类保证,基于 Checker Framework 实现 Java 检查器,在 OpenJDK 17 集合框架等约 26,000 行代码上评估,表明能有效实施不可变性且无需复制代码。
State mutations can often lead to silent program errors, including broken invariants and security vulnerabilities. Object-oriented languages offer basic mechanisms to prevent mutation; however, enforcing desired guarantees remains challenging. Two such guarantees are transitive immutability, which disallows mutation of all objects reachable from a reference, and abstract immutability, which permits controlled mutation of otherwise immutable objects. Furthermore, introducing readonly references to support subtype polymorphism often complicates the soundness of the type system. The integration of immutability into a class hierarchy introduces challenges, primarily manifesting as duplicated code between mutable and immutable variants. We present Precise Immutability for Classes and Objects (PICO), a type system that enforces transitive abstract immutability with readonly references. PICO introduces novel viewpoint adaptation rules to achieve transitivity. These rules prevent unsoundness caused by mutable and immutable cross-type aliasing, a long-standing issue for systems combining immutability and assignability. Additionally, PICO formally defines the abstract state, which allows developers to permit mutation for selected parts of the object graph. PICO provides four state-preservation guarantees within a single system by selecting corresponding viewpoint adaptation rules: abstract-, concrete-, readonly-, and transitive-state preservation. Finally, the system supports safe class mutability polymorphism: one class can express both mutable and immutable uses, avoiding duplicate mutable/immutable class variants while also enabling backward-compatible retrofitting of existing hierarchies. We formalize PICO and prove its type soundness and four state-preservation guarantees in the Rocq proof assistant. We also implement a type checker for Java using the Checker Framework. We evaluate this implementation on the Java Collections Framework in OpenJDK 17 and other benchmarks, covering approximately 26,000 non-comment lines of code. The results demonstrate that PICO effectively enforces immutability guarantees and can successfully retrofit existing libraries without duplicating code.
@article{paperbot12140,
title = {Transitive, Abstract, and Class Polymorphic Immutability},
author = {Aosen Xiong and Yudi Bai and Haifeng Shi and Lian Sun and Mier Ta and Werner Dietl},
journal = {Proceedings of the ACM on Programming Languages},
volume = {10},
number = {OOPSLA2},
year = {2026},
doi = {10.1145/3839491}
}