一句话:提出 migrational typing,高效计算渐进类型程序中所有动态到静态类型的替换方式,支持自动迁移与最小动态类型修复。
渐进类型允许程序兼得静态与动态类型的好处,但本身不提供在两者之间迁移的机制,程序员必须手动增删类型标注。由于渐进类型中标注之间存在微妙交互,要迁移到尽可能静态通常需尝试所有参数标注组合。本文提出 migrational typing,可高效计算将渐进类型程序中动态类型替换为完全静态类型的所有可能方式。类型结果为自动迁移提供支持:既可将程序迁移到尽可能静态,也可引入最少数量的动态类型以消除类型错误,并可扩展以支持用户自定义标注修改准则。作者实现了该系统并在大型程序上评估,结果显示其随程序规模线性扩展,仅比普通渐进类型慢 2–4 倍。
Abstract Gradual typing allows programs to enjoy the benefits of both static typing and dynamic typing. While it is often desirable to migrate a program from more dynamically typed to more statically typed or vice versa, gradual typing itself does not provide a way to facilitate this migration. This places the burden on programmers who have to manually add or remove type annotations. Besides the general challenge of adding type annotations to dynamically typed code, there are subtle interactions between these annotations in gradually typed code that exacerbate the situation. For example, to migrate a program to be as static as possible, in general, all possible combinations of adding or removing type annotations from parameters must be tried out and compared. In this paper, we address this problem by developing migrational typing , which efficiently types all possible ways of replacing dynamic types with fully static types for a gradually typed program. The typing result supports automatically migrating a program to be as static as possible or introducing the least number of dynamic types necessary to remove a type error. The approach can be extended to support user-defined criteria about which annotations to modify. We have implemented migrational typing and evaluated it on large programs. The results show that migrational typing scales linearly with the size of the program and takes only 2–4 times longer than plain gradual typing.