Resources / Blog
H2LooP Porter: Converting Entire Legacy C Projects to Rust with Reinforcement Learning
We post-trained a model to translate real C projects into Rust that compiles and passes its tests. H2LooP Porter (currently in Beta) roughly triples the base model on CRUST-bench, solving 18 of 79 projects versus 6 for the base model.
From the team at h2loop.
Summary. We post-trained a model to translate real C projects into Rust that compiles and passes its tests. The model, H2LooP Porter (currently in Beta), roughly triples the base model on CRUST-bench, published at Conference on Language Modeling 2025 (COLM), solving 18 of 79 projects with iterative repair against 6 for the base model. We then folded the repair loop into training itself through multi-turn reinforcement learning. That step matched the base model rather than improving on it, and understanding why is the central result of this report: the limiting factor on this task is cross-file consistency, a capability that reinforcement learning sharpens but does not teach.
Why C-to-Rust Is Hard
Translating C to Rust looks like a transpilation problem, but it is really a reasoning problem. C relies on raw pointers, manual memory management, and behavior that is only correct by convention. Rust requires ownership, lifetimes, and trait bounds, and its borrow checker rejects patterns that are perfectly valid in C. A naive port rarely compiles, and even when it compiles it often does not preserve the original behavior.
This is what makes the task a useful test. There is no surface pattern for the model to imitate. Either it understands what the C code does and reconstructs it under Rust's rules, or it does not.
We measure progress on CRUST-bench, a set of real C-to-Rust translation tasks. Each task provides the C source together with Rust interface stubs, and scores the result by running the project's test suite. A project counts as solved when its tests pass, and partial passes receive partial credit. We use the average score across all projects as our primary metric, since it rewards genuine progress and does not advantage a model for skipping difficult problems. The base model solves only a single-digit fraction of the benchmark out of the box.
Approach
Our work progressed through four stages, each motivated by the limitation of the previous one. The first three operate in a single-turn setting, in which the model produces one translation and receives a score. The fourth, repair, operates at inference time. Multi-turn training, discussed later, moves repair inside the training loop.
Supervised fine-tuning learns surface form, not correctness
The natural starting point is to train on examples of good translations. We assembled a corpus of C-to-Rust pairs from several sources and fine-tuned on it.
This degraded performance. The cause is instructive: our reference translations had not been compile-verified, so the model learned what correct-looking Rust resembles without learning to produce Rust that is actually correct. When correctness is defined by a verifier, training on unverified data teaches the model to be confidently wrong. On a task where correctness requires a verifier, the verifier has to be present during learning.
A compile reward optimizes a proxy
We next introduced the verifier directly, using reinforcement learning with a simple reward: whether the generated Rust compiles. The model improved at producing code that compiles and did not improve at the underlying task. Compilation is necessary but far from sufficient, since a great deal of compilable Rust is still incorrect. We had optimized a proxy and obtained a proxy improvement. A reward should encode the outcome you want, not a quantity that merely correlates with it.
A graded test reward is the first real signal
We then replaced the compile reward with a graded, behavior-tied reward. A translation that fails to compile scores near zero; one that compiles and passes every test receives the full score; one that compiles and passes some tests receives partial credit in proportion to the fraction passing. Compilation is the gate, and the passing-test fraction is the signal the model climbs from there.
This was the first change that moved the model meaningfully. Compile failures fell sharply, and the improvement came from translations that were logically correct rather than merely syntactically valid. The partial credit also gave the optimizer a usable gradient: a translation passing eight of ten tests is no longer scored identically to one that fails outright.
Repair is the largest single improvement
The largest single gain came not from training but from allowing the model to see compiler output and revise. We return the test output to the model and ask it to correct its own translation, iterating a small number of rounds.
The first repair round alone is worth roughly ten additional solved projects. Most first-attempt failures are shallow, a missing import or an incorrect signature, and the error message points directly at the fix. The loop plateaus after a few rounds, because the remaining failures are structural and require understanding why the original C behaves as it does, which the error output does not explain. With repair the model solves 18 of 79 projects, roughly triple the base model. The most efficient improvement we found was at inference time, not training time.
Results
The table below summarizes the progression on CRUST-bench's 79 projects. "Solved" denotes that every test in the project passes.
| Configuration | Solved | Rate |
|---|---|---|
| Base model | 6 / 79 | 7.6% |
| Supervised fine-tuning | 4 / 79 | 5.1% |
| RL, compile reward | 6 / 79 | 7.6% |
| RL, graded test reward | 8 / 79 | 10.1% |
| H2LooP Porter (test reward + repair) | 18 / 79 | 22.8% |
| Multi-turn RL | 6 / 79 | 7.6% |
A few points are worth stating directly. Supervised fine-tuning regressed below the base model. The compile reward landed exactly on the base model. The only changes that moved the model were the graded test reward and, most of all, the repair loop applied on top of it.
What improved, qualitatively
Beyond the headline counts, the test reward changed the character of the model's output. Compilation success rose by roughly 41 percent, so most of the benefit first appears as code that builds and only then converts into code that passes tests. The errors that disappeared were concentrated in cross-file consistency: references to functions and constants the model had used but never defined, and imports that resolved to nothing. After training, a substantially larger share of projects built cleanly, and the residual failures shifted toward genuinely hard cases rather than self-inflicted inconsistencies.
For external context, the CRUST-bench paper reports GPT-4o at 11/100 and a fine-tuned 7B model at 5/100 on a 100-project split. These are not directly comparable because the split differs, but they indicate the scale of the problem: the strongest models still solve under half the benchmark.
Multi-Turn Training: Folding Repair Into the Loop
Because repair was so effective at inference time, the natural question was whether the model could learn to repair during training rather than have it applied afterward. We built a multi-turn setup in which each training episode is a full interaction: the model writes Rust, runs it against a real toolchain, observes the actual compiler and test output, and revises, all within a single episode. The model is trained on precisely the loop on which it is evaluated.
Scale is worth noting, since it bears on how to read the result. Reinforcement learning of this kind learns by sampling, and across these experiments the model produced tens of thousands of real, compiled-and-tested translation attempts. The null result that follows is not a consequence of insufficient training signal.
Our first attempt stalled on a reward that was too coarse: nearly every attempt collapsed onto one of two scores, leaving no usable learning signal. We rebuilt the reward to grade outcomes more finely and stabilized the optimization. By every internal measure the second configuration was healthy. It nonetheless came out level with the base model.
That null result proved to be the most useful finding of the project. Once the reward and the optimization are sound and the model still does not improve, the reward was never the constraint. We therefore examined the failures directly, more than twenty thousand of them. The pattern was unambiguous. The model writes fluent, confident Rust that refers to entities it never defines: a function called but never written, a constant used but never declared, an import that resolves to nothing. Genuine type and trait errors, the kind one might expect a model to struggle with in Rust, were a distant third. The failures are predominantly about keeping an entire multi-file project consistent with itself, not about resolving an individual difficult type.
Reinforcement learning sharpens what a model can already do; it does not grant a capability the model lacks. The base model writes idiomatic Rust line by line, but holding an entire project's declarations consistent is a capability it does not possess, and no current reward schedule creates it. This is consistent with broader findings on the benchmark, where straightforward generate-then-repair tends to outperform more elaborate agentic methods.
Conclusion
The reward signal dominates. Every meaningful change came from what we rewarded, not from how we trained. Identical setups under supervised data, a compile reward, and a test reward produced markedly different models.
Compilation is a floor, not a goal. Getting code to compile is a prerequisite. The work lies in producing translations that are correct, which only a behavior-tied reward delivers.
Inference-time structure is underrated. A repair loop reacting to real compiler output outperformed every training change we made, at a fraction of the cost.
Reinforcement learning has limits worth recognizing early. It sharpens existing ability and will not install a capability the model fundamentally lacks. Recognizing that distinction saved us from optimizing a reward that was never the bottleneck.
Our RL training loop, triples the base model score on CRUST-bench. We are set for our next phase of work in Code porting where we tackle more complex and nuanced legacy projects.
References CRUST-Bench: A Comprehensive Benchmark for C-to-safe-Rust Transpilation https://arxiv.org/abs/2504.15254