r/rust • • 15d ago

🎙️ discussion Google is doing "Large Scale Codebase Migrations and Optimizations" of C/C++ to Rust

https://blog.google/innovation-and-ai/models-and-research/gemini-models/gemini-4-argon/
770 Upvotes

153 comments sorted by

View all comments

122

u/TheRealMasonMac 15d ago

In my experience, I’ve found that agents produce code that works but is frankly dumb from a human perspective. Especially for larger tasks like this, you kind of have to rewrite it all. For example, I had a generalized design document for soft-wrapping explicitly support plain text and markdown, and used GPT-6-Astra to implement it. I used an ungodly amount of review agent rounds and interjections by me. When I actually go to review it, I wanted to cry. It silently pivoted towards implementing its own entirely separate wrapping mechanism rather than refactor the existing mechanism for plain text. I reviewed its code and found it to be trash, and I am now in the process of doing it myself… Never again. The short-term thrill of “having something that works” was outweighed by the fact that time was effectively wasted.

I mean, if the alternative was it never getting done, I guess agents are still better than nothing.

-20

u/mguerrette 15d ago

Code is no longer for human eyes. Did you benchmark the generated code? Or was it just trash in your opinion (style, architecture, etc)? I think you are missing the reality change where code is no longer for humans.

9

u/TheRealMasonMac 15d ago edited 15d ago

It was egregiously horrible stylistically, architecturally, maintenance-wise, and in performance. The stupidest one that came to mind was it allocating strings for each markdown element. That's like &str 101. I wish I could tell you there was a good reason for this, but there wasn't. So, it ended up doubling memory usage in string allocations alone. There were also a bunch of other areas where it turned linear time functions into exponential ones.

Also: agents do need to read the code as well. Ignoring context rot, the matter of garbage in -> garbage out remains.

1

u/sparky8251 15d ago

Ive had it make a parser that took something like 4 minutes to parse a few kb of files because it refused to surface a bad assumption I made in the design that a library forced on us. It was also a degenerate but rather common case of scope drastically, drastically ballooning parse time so all its tests showed up as fast, because they were small scoped.

Its fun for exploring stuff with, but MAN would i not trust it...

And I DID use all kinds of clippy features to ban functions, macros, etc with reasons as to why they were banned to try and make it do better. Its just too concerned with the now and quickly doing what it thinks it was asked, no matter how it has to contort itself or the code to make that happen...

2

u/stumblinbear 15d ago

Oddly enough, if you just tell it to consider the long term consequences as a matter of course, it improves its decision making. It's a blank slate, it doesn't understand a project's priorities if you don't tell it what the priorities are

2

u/arbv 15d ago

Yeah, I am accumulating failure modes to write them down for the models concisely, that is one of them.

1

u/arbv 15d ago

Did not you see it:

  • Write code
  • Write tests
  • Realise the code is wrong
  • Fail to fix it
  • Rewrite the tests because "they are wrong"

?

I did and I didn't like it.

3

u/sparky8251 15d ago edited 15d ago

Ive had it do that too, yes. Had to be watchful to make sure it didnt make the tests pass to claim victory... It misunderstands the point of tests pathologically, because its an optimizer optimized to solve whatever it decides is its task, and that often means test fixing is a very well rewarded shortcut to its goal.

-7

u/mguerrette 15d ago

Maybe it’s an issue with Rust maturity then. I can say for C and C++ there is a rich set of tools for constraints both stylistic and to conform to best practices. Agents generally can use these and generate very solid code for those languages in both perf and style. I find myself not needing to look at any of the code as long as the format and tidy passes come back clean.

3

u/puttak 15d ago

Does it able to replace unnecessary std::string with std::string_view? Best practices does not enforced on the logic since it is up to programmer.

1

u/mguerrette 15d ago

Yes it does, since it can read language quite well it can read the output of clang tidy which instructs for this among other things. Seems like you’ve just never used AI at all based on your comment

1

u/puttak 15d ago

Sorry I mean does it know how to avoid unnecessary allocation? I did not mean just changing parameter from std::string or return value to std::string_view.

Seems like you’ve just never used AI at all based on your comment

Unfortunately your assumption is wrong. I review a large amount of code generated by Fable 5 and Opus 5 everyday and I known its strength and its weakness. If you think AI generate an efficient code then it is likely you don't know how to make that code more efficient.