Towards Scalable and Automated Program Translation
AS6 Level 5
MR6, AS6-05-10

Abstract:
Long-lived codebases eventually face pressure to move: off an unmaintained software stack, onto a different platform, or into a memory-safe language. Automated code translation promises to make such moves affordable, but it has been a long-standing challenge: a useful translation must be correct, must scale to real programs, and must be idiomatic in the target language. Well-engineered compilers may translate correctly and at scale, but such translations often end up faithfully emulating the source language in a non-idiomatic subset of the target language, producing bloated or unsafe code that defeats the purpose of migration. Large language models produce idiomatic code, but introduce semantic mistakes that compound as programs grow. This thesis argues that the tension may be reduced by choosing a suitable level of abstraction at which to decompose the translation task.
Across two language pairs, we explored several levels of abstraction for decomposing idiomatic translation, each with different advantages and scope. For Python to JavaScript, we worked up from AST-level translation rules and statement-level trace alignment to decomposition by lexical scope. Paired with a semantic model shared by both languages, the scope-level decomposition lets each fragment be rewritten in the target language's own idioms and validated on its own, while guaranteeing that the assembled program still passes the original tests. It scales to libraries of around 2k LoC. For C to Rust, our user study shows that producing safe Rust requires rewriting the program rather than mimicking its structure. Correctness is the main difficulty in such rewrites, and it becomes increasingly challenging as programs grow longer and more complex. We therefore built two agentic workflows. ACToR pairs a translator agent with an adversarial one that searches for inputs on which the C and Rust versions disagree. Reboot decomposes the C program by feature, so that every intermediate step remains a runnable program that can be tested before the next feature is added. With Reboot, we translated six real-world language interpreters of up to 23k LoC into Rust with no unsafe code. Known memory errors and related CVEs in these programs are eliminated or mitigated, suggesting that the security benefit of moving to Rust is achievable with automated translation.

