Rustine: mimalloc C → Rust Translation#1212
Rustine: mimalloc C → Rust Translation#1212enum-class wants to merge 1 commit intomicrosoft:dev3from
Conversation
This PR presents an initial version of Rust translation of Microsoft's mimalloc (dev3 branch) using Rustine, an LLM-powered C-to-Rust whole-repository translation/validation/debugging pipeline. The translation of the entire repository (including application and test code) is 100% compilable.
@microsoft-github-policy-service agree [company="University of Illinois Urbana-Champaign"] |
@microsoft-github-policy-service agree company="University of Illinois Urbana-Champaign" |
|
The LLM output looks quite bad, presumedly since it tries to stay close to C without using idiomatic Rust. The use of references I've seen looks highly questionable also. Compare it to https://github.com/Zoxc/fjall for a more proper Rust port. |
| pub fn mi_expand(p: Option<&mut ()>, newsize: usize) -> Option<&mut ()> { | ||
| // The C function ignores its parameters and returns NULL (0) | ||
| // In Rust, we return None to represent NULL | ||
| None | ||
| } |
There was a problem hiding this comment.
It only took me until here to find a blatantly incorrect translation
Lines 270 to 282 in b196396
There was a problem hiding this comment.
@jcotton42 Thank you for the comment, but I believe this translation is actually correct. This version of mimalloc was intentionally translated with MI_PADDING enabled. In this mode, the original C code explicitly disables mi_expand and always returns NULL. The original C code also explicitly disables shrinking/expanding and always returns NULL The Rust translation correctly preserves this behavior (returning None). The translation is semantically correct for MI_PADDING mode. If you'd like to see the version with padding disabled (where the actual expand logic is active), or an updated translation from our improved pipeline, let me know.
@Zoxc Thank you for taking the time to review the PR This translation was generated about 4 months ago using an early version of the Rustine pipeline powered by DeepSeek-V3 a relatively cheap and lightweight model at the time. The goal of this PR was never to deliver a production-ready, fully idiomatic Rust port of mimalloc, but rather to serve as a research artifact demonstrating that LLMs (even modest ones) can successfully translate a complex, highly concurrent, and performance-critical C codebase like mimalloc into 100% compilable Rust that passes the key tests. In many places the generated code does manage to produce reasonably idiomatic Rust patterns, which was encouraging. Since then, we have made significant improvements to the Rustine pipeline and many of such issues are resolved. Practitioners can use such compilable translations (and likely preserving functionality due to similarity to C code) by LLMs as the first version, and improve the idiomaticity. Note that these translations can be ready very fast, in the order of minutes/few hours. Even if significant manual fixing is still required afterward, the overall process is dramatically faster than starting from scratch. |
This PR presents an initial version of Rust translation of Microsoft's mimalloc (dev3 branch) using Rustine, an LLM-powered C-to-Rust whole-repository translation/validation/debugging pipeline. It is worth noting that C2Rust fails to translate mimalloc because it struggles with complex atomic operations and strict thread-safety requirements. In contrast, Rustine succeeds by focusing on semantic intent rather than relying on shallow, syntax-level transpilation.
The translation of the entire repository (including application and test code) is 100% compilable. Test translation quality is manually checked, and execution of translated tests on translated code results in 100% test pass (test_api, test_api_fill, test_stress).
Please review the translations and let us know if you are interested in additional stats related to Rust code (safety features, raw pointer usage, including pointer arithmetics, clippy results, and code quality metrics). We would be happy to incorporate your feedback into the pipeline and improve the translation.