Library migration is the process of replacing a library with a similar one in a software project. Manual library migration is time consuming and error prone, as it requires developers to understand the Application Programming Interfaces (API) of both libraries, map equivalent APIs, and perform the necessary code transformations. Due to the difficulty of the library migration process, most of the existing automated techniques and tooling stop at the API mapping stage or support a limited set of libraries and code transformations. In this paper, we develop an end-to-end solution that can automatically migrate code between any arbitrary pair of Python libraries that provide similar functionality. Due to the promising capabilities of Large Language Models (LLMs) in code generation and transformation, we use LLMs as the primary engine for migration. Before building the tool, we first study the capabilities of LLMs for library migration on a benchmark of 321 real-world library migrations. We find that LLMs can effectively perform library migration, but some post-processing steps can further improve the performance. Based on this, we develop MigrateLib, a command line application that combines the power of LLMs, static analysis, and dynamic analysis to provide accurate library migration. We evaluate MigrateLib on 717 real-world Python applications that are not from our benchmark. We find that MigrateLib can migrate 32% of the migrations with complete correctness. Of the remaining migrations, only 14% of the migration-related changes are left for developers to fix for more than half of the projects.
Evolution of Deprecated APIs and Their Replacements in Python Libraries
College of Computer Science and Technology, Nanjing University of Aeronautics and Astronautics(南京航空航天大学计算机科学与技术学院);Key Laboratory for Safety-critical Software Development and Verification, Nanjing University of Aeronautics and Astronautics(南京航空航天大学安全关键软件开发与验证重点实验室);State Key Laboratory for Novel Software Technology, Nanjing University(南京大学软件新技术国家重点实验室)
LibRec: Benchmarking Retrieval-Augmented LLMs for Library Migration Recommendations
School of Computer and Computing Science, Hangzhou City University(杭州城市大学计算机与计算科学学院);Polytechnic Institute, Zhejiang University(浙江大学多技术学院);School of Computer Science, Shanghai Jiao Tong University(上海交通大学计算机科学学院);School of Computer Science and Technology, Harbin Institute of Technology(哈尔滨工业大学深圳学院);College of Computer Science and Technology, Huazhong University of Science and Technology(华中科技大学计算机科学与技术学院);School of Computing and Information Systems, Singapore Management University(新加坡管理大学计算机与信息科学学院);College of Computer Science and Technology, Zhejiang University(浙江大学计算机科学与技术学院)
CODEMENV: Benchmarking Large Language Models on Code Migration
Provable Responsible AI and Data Analytics (PRADA) Lab(可证明责任人工智能与数据分析实验室);King Abdullah University of Science and Technology(国王 Abdullah 科学与技术大学);Peking University(北京大学);South China University of Technology(华南理工大学)
成功的跨语言克隆检测可以使研究人员和开发人员创建强大的语言迁移工具,一旦掌握了一种程序设计语言,就可以方便地学习其他语言,并促进代码片段在更广泛的代码库中的重用。然而,识别跨语言克隆提出了特殊的挑战,克隆检测问题。任意语言之间缺乏公共的底层表示意味着检测克隆需要以下解决方案之一:1)跨每个目标语言复制的静态分析框架,其注释匹配所有语言的语言特征,或者2)基于运行时行为检测克隆的动态分析框架。在这项工作中,我们证明了后者的解决方案,一个动态分析方法称为SLACC跨语言克隆检测的可行性。与之前的克隆检测技术一样,我们使用输入/输出行为来匹配克隆,尽管我们通过放大输入的数量和覆盖更多的数据类型来克服之前工作的局限性;因此,实现了比之前尝试更好的聚类。由于聚类是基于输入/输出行为生成的,因此SLACC支持跨语言克隆检测。作为一个额外的挑战,我们的目标是静态类型语言Java和动态类型语言Python。与最近的Java克隆检测工具HitoshiIO相比,SLACC检索的集群数量是HitoshiIO的6倍,并且精度更高(86.7% vs. 30.7%)。这是第一个对动态类型语言执行克隆检测的工作(精度= 87.3%),也是第一个对缺乏公共底层表示的语言执行克隆检测的工作(精度= 94.1%)。它为实现可伸缩语言迁移工具的更大目标迈出了第一步。