arXiv:2608.23619cs.SEcs.AI2026-08

用可解释的代码语义图辅助老旧代码迁移,提升转换准确性和完整性。

Identifying Latent Declarative Representations of Code for Assisting Repository Migration

  • 通过生成带注释的数据流图显式表达代码隐含的声明式语义。
  • 在50个Fortran仓库上实现85.6%的行为匹配率,93.1%的迁移综合得分。
  • 适合需要高覆盖率、可审计的大型代码库现代化项目使用。

遗留软件仓库中嵌入了数十年的领域知识,但因缺乏文档导致理解和现代化困难。本文将程序视为未观测到的、声明式计算描述的实现,探索显式化这一潜在语义表示是否能提升大规模代码库迁移效果。ADFD-Migrate 通过有注释的数据流图(ADFD)近似该隐式表示,包含过程、数据存储、外部实体、数据流和行为契约。利用大模型从有限仓库上下文中推断源端ADFD,由静态分析覆盖检查引导;依赖感知分块按序处理过程组以生成目标语言代码。源端ADFD与静态恢复的目标端ADFD之间的差异用于指导代码再生。我们在f2x50基准上评估,该基准包含50个Fortran仓库,代码量1.5k–1.6M行,涵盖三个复杂度层级。结果表明,在382个经筛选的Fortran-Oracle探测器下,生成的Python代码通过327个(85.6%),40个仓库全部通过。相比直接翻译和仓库上下文翻译(分别仅暴露99/98个行为),ADFD-Migrate暴露全部382个计划行为;其迁移综合得分达93.1%,在47个仓库上比直接翻译高出17–59个百分点。结果表明,可检查的语义瓶颈能显著提升迁移覆盖率与集成性,并为多数仓库提供低成本生成路径。

原文摘要 · Abstract (English)

Legacy software repositories embed decades of domain knowledge in undocumented code, making understanding and modernization difficult. We treat a program as the implementation of an unobserved, declarative description of its computation and investigate whether making this latent declarative representation explicit improves repository-scale porting. ADFD-Migrate approximates the latent representation with an annotated data-flow diagram (ADFD) of processes, data stores, external entities, flows, and behavioral contracts. An LLM infers the source ADFD from bounded repository context, guided by static-analysis coverage checks. Dependency-aware chunking orders bounded process groups for target-language generation. Differences between the source ADFD and a statically recovered target ADFD then guide regeneration. We evaluate ADFD-Migrate on f2x50, a new benchmark of 50~Fortran repositories spanning 1.5k--1.6M lines of code and three complexity tiers, and assess the resulting ports along two dimensions: porting soundness, measured by source-oracle behavioral agreement, and porting completeness, measured by a composite migration outcome index. Against 382 curated Fortran-oracle probes, the generated Python passes 327 (85.6\%), with 40 repositories passing every attempted probe. ADFD-Migrate exposes all 382 planned behaviors as runnable targets, compared with 99 and 98 for direct and repository-context translation and 69 and 30 for the static-profile and dependency-chunking ablations. It also achieves a 93.1\% mean migration outcome index and a 17--59 percentage-point outcome-index advantage over direct translation on 47 repositories. These results suggest that an inspectable semantic bottleneck can improve the coverage and integration of repository-scale migration while enabling lower-cost generation for many repositories.

代码迁移语义建模大模型应用遗产系统

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