arXiv:2511.00160cs.SEcs.AI2025-11

用大模型自动迁移代码,结合变更差异显著提升准确率

What a diff makes: automating code migration with large language models

  • 利用代码变更差分(diff)作为上下文增强大模型理解
  • 单次运行正确识别65%修改,多次运行达80%,47%生成完全正确
  • 开源工具与数据集支持真实项目迁移,适合维护依赖库的开发者

现代软件依赖复杂的依赖栈,版本更新可能破坏兼容性。本文探索使用大语言模型(LLM)进行代码迁移,重点解决依赖项在语义版本升级时的兼容性维护问题。通过测试覆盖率和变更对比等指标,我们证明包含变更差分(diff)的上下文能显著提升性能,某些情况下优于直接使用代码。为此,我们提供了一个新数据集,并开源了Python工具AIMigrate,用于辅助代码库迁移。在真实项目TYPHOIDSIM从STARSIM版本迁移中,单次运行成功识别65%所需修改,多次运行提升至80%,其中47%的修改生成完全正确。

原文摘要 · Abstract (English)

Modern software programs are built on stacks that are often undergoing changes that introduce updates and improvements, but may also break any project that depends upon them. In this paper we explore the use of Large Language Models (LLMs) for code migration, specifically the problem of maintaining compatibility with a dependency as it undergoes major and minor semantic version changes. We demonstrate, using metrics such as test coverage and change comparisons, that contexts containing diffs can significantly improve performance against out of the box LLMs and, in some cases, perform better than using code. We provide a dataset to assist in further development of this problem area, as well as an open-source Python package, AIMigrate, that can be used to assist with migrating code bases. In a real-world migration of TYPHOIDSIM between STARSIM versions, AIMigrate correctly identified 65% of required changes in a single run, increasing to 80% with multiple runs, with 47% of changes generated perfectly.

代码迁移大模型自动化

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