一句话:用图表示加 MapReduce 实现可扩展至数亿行代码的类型迁移重构,98% 生成补丁被接受。
类型迁移是一种重构,把源码中的某个类型整体替换为另一个类型。手工完成十分繁琐,程序员必须找出该类型的所有出现位置,以及沿赋值操作、方法层次与子类型传播的依赖。已有自动化方法执行代价高昂的整程序分析,无法扩展到超大规模代码库。本文提出把程序的类型结构表示为图,并据此采用 MapReduce 并行分布式流程,使其可扩展至数亿行代码。作者实现了与 IDE 无关、可集成多数构建系统的工具 T2R,并在七个开源项目与一个 3 亿行(300M LOC)的专有代码库上评估准确性、有用性与可扩展性。T2R 共生成 130 个类型迁移补丁,其中 98% 被原开发者接受。
Type migration is a refactoring activity in which an existing type is replaced with another one throughout the source code. Manually performing type migration is tedious as programmers need to find all instances of the type to be migrated, along with its dependencies that propagate over assignment operations, method hierarchies, and subtypes. Existing automated approaches for type migration are not adequate for ultra-large-codebases - they perform an intensive whole-program analysis that does not scale. If we could represent the type structure of the program as graphs, then we could employ a MAPREDUCE parallel and distributed process that scales to hundreds of millions of LOC. We implemented this approach as an IDE-independent tool called T2R, which integrates with most build systems. We evaluated T2R's accuracy, usefulness and scalability on seven open source projects and one proprietary codebase of 300M LOC. T2R generated 130 type migration patches, of which the original developers accepted 98%.