一句话:提出渐进类型的稳健动态嵌入准则,要求动态代码嵌入后赋予静态类型时在任意渐进上下文中失败仅源于上下文,并用 Rocq 形式化。
渐进类型旨在桥接静态与动态类型,其可用性常用 Siek 等人的细化准则评估,其中动态嵌入准则要求动态语言可充分嵌入渐进语言。本文指出原有准则未捕捉一个重要性质:嵌入后的动态代码若语义上满足某静态类型,则赋予该静态类型后,应与任意渐进上下文可靠交互。为此作者提出渐进项的稳健性概念:在与任意上下文交互时,运行时失败应由上下文而非稳健项自身造成;并形式化稳健动态嵌入准则:若动态组件语义满足静态类型,则其嵌入并赋予该类型后应为稳健项。文章证明该准则不被已有元理论性质蕴含,且多种现有渐进语言不满足;随后在渐变化的简单类型语言中实现该准则。所有结果均在 Rocq 证明助手中形式化。
Gradual typing has long been advocated as a means to bridge the gap between static and dynamic typing disciplines, enabling a range of use cases such as the gradual migration of existing dynamically typed code to more statically typed code, as well as making advanced static typing disciplines more accessible. To assess whether a given gradual language can effectively support these use cases, several formal properties have been proposed, most notably the refined criteria set forth by Siek et al. One criterion asserts that the dynamic extreme of the spectrum should be expressible in the gradual language, formalized by the existence of an adequate embedding from the corresponding dynamic language. We observe that the existing dynamic embedding criterion does not capture the desirable property of being able to ascribe embedded code to a static type that it semantically satisfies, and ensure reliable interactions with other components within the gradual language. Specifically, we introduce the notion of robustness for gradual terms, meaning that when interacting with any gradual context, runtime failures that may occur ought to be caused by the context, not by the robust term itself. We then formulate the robust dynamic embedding criterion: if a dynamic component semantically satisfies a given static type, then its embedding subsequently ascribed to that static type should be a robust term. We demonstrate that robust dynamic embedding is not implied by any existing metatheoretical property from the literature, and is not upheld by various existing gradual languages. We show that robust dynamic embedding is achievable with a gradualized simply-typed language. All the results are formalized in the Rocq proof assistant. This novel criterion complements the set of criteria for gradual languages and opens several venues for further exploration, in particular for typing disciplines that enforce rich semantic properties.
@article{paperbot3061,
title = {Robust Dynamic Embedding for Gradual Typing},
author = {Koen Jacobs and Matías Toro and Nicolas Tabareau and Éric Tanter},
journal = {Proceedings of the ACM on Programming Languages},
volume = {9},
number = {ICFP},
year = {2025},
doi = {10.1145/3747507}
}