Identifying Latent Declarative Representations of Code for Assisting Repository Migration
Organizations: Department of Computer Science and Information Systems, BITS Pilani, K. K. Birla Goa Campus, NH 17B, Zuarinagar, 403726, Goa, India · School of Computer Science and Engineering, UNSW Sydney, Sydney, NSW, 2052, Australia
Abstract
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.
Figures & tables
| Property | f2py | fable | LFortran | Ours |
| Target language | Py (bind) | C++ | Py (AST) | Python |
| Readable output | ✗ | Partial | ✗ | ✓ |
| Idiomatic target | ✗ | ✗ | ✗ | ✓ |
| Preserves structure | N/A | ✗ | ✗ | ✓ |
| Inspectable IR | ✗ | ✗ | LLVM IR | ADFD |
| Human checkpoint | ✗ | ✗ | ✗ | ✓ |
| Tier | LoC Range | Files | Examples | |
| Low | 20 | 1.5k–41k | 4–112 | ABAQUS, fftpack, tsunami |
| Medium | 20 | 4.8k–192k | 9–405 | minpack, stdlib, xtb |
| Complex | 10 | 29k–1.6M | 158–3.6k | hdf5, lapack, pymc2 |
| Setting | Value |
| Generator (low) | Qwen-3-Coder 30B (local) |
| Generator (medium) | Qwen-3-Coder 30B (4), 480B (16) |
| Generator (complex) | Claude Sonnet 4.5 (API) |
| Judge model | Claude Opus 4.6 (evaluation only) |
| Temperature | 0.3 (generation), 0.2 (judge) |
| ADFD iterations | 3–5 |
| Method | Planned | Runnable | Pass | Failures | Behavioral agreement | ||
| Wrong output | No runnable target | Over all 382 | Over runnable only | ||||
| ADFD-Migrate | 382 | 382 | 327 | 55 | 0 | 85.6% | 85.6% |
| Direct translation | 382 | 99 | 83 | 16 | 283 | 21.7% | 83.8% |
| Repo-context direct | 382 | 98 | 83 | 15 | 284 | 21.7% | 84.7% |
| Static profile (no ADFD) | 382 | 69 | 42 | 27 | 313 | 11.0% | 60.9% |
| Dependency chunking (no ADFD) | 382 | 30 | 14 | 16 | 352 | 3.7% | 46.7% |
| Tier | Sem. | Syn. | Imp. | ADFD outcome | Direct | Direct outcome | ||
| Low | 20 | 95.2% | 99.9% | 77.2% | 93.0% | 20 | 76.1% | +16.9 |
| Medium | 20 | 98.3% | 98.1% | 72.5% | 91.9% | 20 | 65.3% | +26.6 |
| Complex | 10 | 99.0% | 100.0% | 79.8% | 95.7% | 7 | 37.2% | +58.5 |
| All | 50 | 97.2% | 99.2% | 75.9% | 93.1% |
Appendix figures & tables5 assets
Supplementary material from the paper’s appendix.
Appendix
| Repository | LoC | Files | Chunks | Syntax | Import | Semantic | Beh. | Outcome | Time | Model | |
| fortran2018-ex. | 3.1k | 75 | 19 | 7 | 100% | 100% | 100% | 4/4 | 100.0% | 25 min | 30B |
| roots-fortran | 5.2k | 4 | 1 | 1 | 100% | 100% | 95% | 0/7 | 97.0% | 13 min | 30B |
| forpy | 13.8k | 9 | 3 | 1 | 100% | 100% | 95% | 4/4 | 97.0% | 2 min | 30B |
| tsunami | 3.1k | 33 | 31 | 11 | 100% | 100% | 95% | 7/7 | 97.0% | 214 min | 30B |
| IO-Fortran-Lib. | 40.9k | 34 | 6 | 2 | 100% | 70% | 100% | 4/4 | 96.4% | 21 min | 30B |
| functional-fortran | 6.6k | 27 | 10 | 4 | 100% | 67% | 100% | 7/7 | 96.0% | 13 min | 30B |
| Repository | LoC | Files | Chunks | Syntax | Import | Semantic | Beh. | Outcome | Time | Model | |
| stdlib | 35k | 405 | 16 | 6 | 100% | 100% | 100% | 11/11 | 98.9% | 61 min | 480B |
| FOODIE | 19k | 44 | 14 | 5 | 100% | 97% | 100% | 4/4 | 96.8% | 31 min | 480B |
| arpack-ng | 148k | 334 | 16 | 6 | 100% | 69% | 100% | 7/7 | 96.3% | 71 min | 480B |
| atomsk | 86k | 166 | 12 | 4 | 100% | 72% | 100% | 4/4 | 96.1% | 47 min | 480B |
| WPS | 32k | 123 | 16 | 6 | 100% | 73% | 100% | 4/4 | 96.1% | 53 min | 480B |
| packmol | 13k | 40 | 132 | 42 | 99% | 74% | 100% | 8/8 | 96.0% | 177 min | 480B |
| Repository | LoC | Files | Chunks | Syntax | Import | Semantic | Beh. | Outcome | Time | Model | |
| lapack | 1.56M | 3,587 | 52 | 18 | 100% | 90% | 100% | 16/16 | 98.3% | 105 min | S4.5 |
| pymc2 | 132k | 410 | 22 | 7 | 100% | 80% | 100% | 10/10 | 96.7% | 98 min | S4.5 |
| ccpp-physics | 325k | 240 | 45 | 15 | 100% | 78% | 99.9% | 7/11 | 96.6% | 135 min | S4.5 |
| Nek5000 | 281k | 327 | 33 | 12 | 100% | 90% | 98% | 13/13 | 96.5% | 232 min | S4.5 |
| petsc | 29k | 200 | 25 | 9 | 100% | 80% | 100% | 8/8 | 96.2% | 115 min | S4.5 |
| hdf5 | 94k | 158 | 85 | 29 | 100% | 77% | 100% | 10/10 | 95.7% | 107 min | S4.5 |
Code Translation
Code translation converts programs between languages, frameworks, and representations while aiming to preserve behavior and sometimes improve safety or performance.
See all 42 papers