Gradually typed languages allow programmers to mix statically and dynamically typed code, enabling them to incrementally reap the benefits of static typing as they add type annotations to their code. However, this type migration process is typically a manual effort with limited tool support. This paper examines the problem of \emph{automated type migration}: given a dynamic program, infer additional or improved type annotations. Existing type migration algorithms prioritize different goals, such as maximizing type precision, maintaining compatibility with unmigrated code, and preserving the semantics of the original program. We argue that the type migration problem involves fundamental compromises: optimizing for a single goal often comes at the expense of others. Ideally, a type migration tool would flexibly accommodate a range of user priorities. We present TypeWhich, a new approach to automated type migration for the gradually-typed lambda calculus with some extensions. Unlike prior work, which relies on custom solvers, TypeWhich produces constraints for an off-the-shelf MaxSMT solver. This allows us to easily express objectives, such as minimizing the number of necessary syntactic coercions, and constraining the type of the migration to be compatible with unmigrated code. We present the first comprehensive evaluation of GTLC type migration algorithms, and compare TypeWhich to four other tools from the literature. Our evaluation uses prior benchmarks, and a new set of ``challenge problems.'' Moreover, we design a new evaluation methodology that highlights the subtleties of gradual type migration. In addition, we apply TypeWhich to a suite of benchmarks for Grift, a programming language based on the GTLC. TypeWhich is able to reconstruct all human-written annotations on all but one program.
翻译:渐渐打印语言允许程序员将静态和动态键入代码混合, 使其能够在代码中添加批注时逐步获取静态打字的好处。 但是, 这种类型的迁移过程通常是一种人工操作, 工具支持有限。 本文审视了 kemph{ 自动迁移类型的问题 : 给一个动态程序, 推断额外或改进类型说明 。 现有类型的迁移算法优先考虑不同的目标, 如尽量扩大类型精确度, 保持与未移动代码的兼容性, 并保存原始程序的语义 。 我们认为, 类型迁移问题涉及根本性的妥协: 优化单一目标往往以牺牲其他目标为代价。 理想的是, 类型迁移工具将灵活地适应一系列用户的优先事项。 我们展示了类型 类型 类型, 与先前的工作不同, 它依赖于定制解析器, Typeat