|
|
Log in / Subscribe / Register

Code Review

Code Review

Posted Nov 14, 2025 19:22 UTC (Fri) by tialaramex (subscriber, #21167)
In reply to: Code Review by Vorpal
Parent article: Rust in Android: move fast and fix things (Google Security Blog)

Even inside the compiler, only a relatively small portion needs you to understand any deep theory of program transformation. A lot of the Rust compiler is either turning a correct Rust program text into abstract syntax, or diagnosing some mistake which rendered your input not a correct Rust program in the way most likely to result in you going:

"Oh! Yeah, that's wrong, I will fix it"

and rarely that you say instead:

"Stupid compiler. It's not wrong, either shut up and accept what I wrote or explain clearly the problem"

I had a Rust diagnostic that I felt was less helpful than it should be. I grep'd the error text, found a constant with that text as its definition (this is all memory so details may be wrong) and then found that constant used only once, at the site emitting the diagnostic text. I read surrounding code and intuited how to write a better diagnostic, and yeah, first time it compiled it actually worked - as I got more familiar with the surrounding code I actually added some useful extra stuff until I was happy that anyone seeing this diagnostic was getting the best I could give them. One thing I realized part way through is that we're not on the happy path - nobody is ever going to curse that my diagnosis code is inefficient, because their program is wrong, and I'm telling them why, if the program wasn't wrong my code never runs at all. From "How hard can it be?" to a (nightly) release with my fix took less than one week. Rustc's reviewer was very helpful in shepherding me through and identifying anywhere my change did need small improvements to hit their quality goals.


to post comments

Non-technical advantages of rustc

Posted Nov 15, 2025 10:37 UTC (Sat) by farnz (subscriber, #17727) [Link] (1 responses)

Your comment about improving a diagnostic brings up one thing that the rustc project gets right, and that helps Rust's adoption; diagnostics (both lints and failures) are continuously being improved, and the people behind the compiler are supportive of efforts to make the diagnostics better.

This sort of work isn't always seen as valuable - after all, an error like "problem in type unification: cannot meet constraints for arg, arg is parameterized type T, T is required to implement Debug + Send + Sync, but supplied value param has type MyParamType, which implements Display + Send + Sync + Unpin + RefUnwindSafe + UnwindSafe" contains all the information you could possibly need to diagnose the bug, but "param is of type MyParamType, which does not implement Debug, which is required in funct(param) by fn funct<T: Debug>(arg: T)" is so much more helpful to the user, even though it has strictly less information than the first form.

Non-technical advantages of rustc

Posted Nov 16, 2025 2:37 UTC (Sun) by tialaramex (subscriber, #21167) [Link]

AIUI One of the things which consciously drove that, and which is as often a source of conflict on LWN as the claims of improved correctness, is Rust's tag line: "A language empowering everyone to build reliable and efficient software"

Because we're not "empowering everyone" if we've made it easy for you to attend our conference but practically impossible to understand our compiler warnings.

Seeing this tag line from other angles also encourages other technical changes, for example Rust often goes out of its way to have the obvious thing you'd write be efficient rather than try to teach Rust programmers to write something else that is already efficient - for beginners this means it's more likely that the Rust program you wrote, though perhaps not very sophisticated, has excellent performance anyway, but even for experienced Rust programmers it means often you don't need to figure out a clever way to write what you meant efficiently, the obvious way to write it is optimised anyway.


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds