arXiv:2602.01107cs.SEcs.AI2026-02被引 3

用大模型生成代码迁移脚本,无需历史数据也能自动改库。

SPELL: Synthesis of Programmatic Edits using LLMs

  • 用大模型提取迁移示例,再转成可复用的代码变换脚本
  • 在多个Python库上验证,能生成适配真实项目的迁移逻辑
  • 无需人工编写或历史数据,适合自动化库迁移场景

库迁移是软件开发中常见但易出错的任务。开发者可能因需求变化或许可证问题需替换库,通常需手动重写代码。现有自动化工具依赖已有迁移案例,但这类数据稀少且难以获取任意库对的迁移数据。此外,这些工具常未能利用现代代码转换框架。本文提出新方法:不直接使用大模型进行转换,而是用大模型提取迁移示例,再通过智能体将这些示例泛化为可复用的转换脚本(基于PolyglotPiranha)。该方法将大模型中的隐含迁移知识转化为结构化、可测试、可重复的迁移逻辑,无需预存语料或人工工程。实验表明,系统在多个Python库上能生成多样化的迁移示例,并合成可泛化至真实代码库的转换脚本。

原文摘要 · Abstract (English)

Library migration is a common but error-prone task in software development. Developers may need to replace one library with another due to reasons like changing requirements or licensing changes. Migration typically entails updating and rewriting source code manually. While automated migration tools exist, most rely on mining examples from real-world projects that have already undergone similar migrations. However, these data are scarce, and collecting them for arbitrary pairs of libraries is difficult. Moreover, these migration tools often miss out on leveraging modern code transformation infrastructure. In this paper, we present a new approach to automated API migration that sidesteps the limitations described above. Instead of relying on existing migration data or using LLMs directly for transformation, we use LLMs to extract migration examples. Next, we use an Agent to generalize those examples to reusable transformation scripts in PolyglotPiranha, a modern code transformation tool. Our method distills latent migration knowledge from LLMs into structured, testable, and repeatable migration logic, without requiring preexisting corpora or manual engineering effort. Experimental results across Python libraries show that our system can generate diverse migration examples and synthesize transformation scripts that generalize to real-world codebases.

代码迁移大模型应用自动化重构

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。