logoalt Hacker News

zem08/01/20252 repliesview on HN

I would be stunned if you could compile arbitrary c++ to rust or d, unless by "compile" you mean "painfully hand-translate and spend months fixing subtle errors". you are underestimating the sheer complexity of the language.


Replies

troad08/01/2025

Agreed, but it would be much worse than you suggest. Many meaty C++ projects have an underlying architecture that could not even be expressed in (safe) Rust. The idea of transpiling a major C++ project and getting it running in Rust with only some minimal idiom fiddling seems utterly fantastical.

JonChesterfield08/01/2025

Implementation would be by modifying clang. Traverse the clang ast emitting the new language instead of llvm IR.

You wouldn't get idiomatic code out but with some effort you'd get rust/d/c/other which clang compiles to the same IR as the original.

How much refactoring is warranted afterwards would depend on how much effort you put in to recreating templates / header files / modules etc on the fly.

I'm not sure I'd choose to do this myself if I was in Google's position but it would be tempting.

show 1 reply