跪拜 Guibai
← All articles
Artificial Intelligence · Rust · Go

Rewrite Code with Evidence, Not Confidence: Inside rust-anything

By 吴佳浩Alben ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

When AI can generate code faster than anyone can review it, the binding constraint shifts to verification. rust-anything's record-and-diff method gives teams a concrete, automatable way to prove a migration is correct, turning 'we think it works' into 'here is the evidence'.

Summary

Rewriting a legacy system has always failed at the same point: no one can prove the new code behaves like the old code. rust-anything approaches that by treating the running original as the spec. It profiles a codebase to find hot paths, generates a bridge so a single Rust function can replace its original without stopping the system, and records real input/output pairs from that original. Those recordings become the test oracle. The tool then diffs every recorded case against the Rust output, benchmarks whether the migration actually buys speed, and gates the change through an executable 'done' check. If anything fails, a disable command rolls back to byte-identical original code.

The design deliberately separates generation from verification. AI or a developer writes the Rust; rust-anything only supplies the evidence that the rewrite is right. That division matters as AI makes code generation cheap: the scarce resource becomes the ability to validate change. The tool's author also maps the same pipeline to agent runtime problems, noting that recording prompts, replays, and evaluation gates are the same mechanics as code migration. That suggests a general 'Software Verification Runtime' pattern for anything that changes and needs to be trusted.

Takeaways
— rust-anything migrates individual functions, modules, or services rather than entire systems.
— The tool records real input/output pairs from the original system and uses them as the specification for correctness.
— A Prettier-to-Rust migration ran about 19 times faster; 15,861 of 17,224 recorded cases executed in Rust, and every output matched byte-for-byte.
— The command pipeline is profile, bridge, record, build, diff, bench, gate, report, and disable.
— The gate command turns 'done' into an executable decision point; disable provides a byte-identical rollback.
— Each small migration must prove its own performance benefit; moving a function to Rust isn't automatically faster.
Conclusions

Verification, not generation, is the real bottleneck in AI-era software engineering; the article's central claim is that validation replaces confidence.

By separating generation from verification, rust-anything lets each side improve independently, avoiding the trap of building an auto-converting tool that must take responsibility for correctness.

The record/replay/diff/gate/rollback pipeline is structurally identical to what an agent runtime needs, which suggests a generalized runtime for trust in any changing system.

Performance gains from Rust have to be demonstrated per case; the bench step is a reminder that a rewrite's value is empirical, not assumed.

Concepts & terms
Software Verification Runtime
A runtime that records, replays, diffs, gates, and rolls back changes to verify that a system's behavior hasn't degraded. The article proposes it as a general pattern beyond code migration.
Gate
An executable check that aggregates all evidence (behavioral equivalence, benchmarks) and makes 'done' a concrete, pass/fail decision rather than a subjective feeling.
Record and diff
A technique where the original system's real input/output pairs are recorded and then used as the oracle to compare against a rewritten version, pinpointing exact mismatches.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗