LWN: Comments on "Progress toward a GCC-based Rust compiler" https://lwn.net/Articles/954787/ This is a special feed containing comments posted to the individual LWN article titled "Progress toward a GCC-based Rust compiler". en-us Sun, 19 Oct 2025 11:44:46 +0000 Sun, 19 Oct 2025 11:44:46 +0000 https://www.rssboard.org/rss-specification lwn@lwn.net Progress toward a GCC-based Rust compiler https://lwn.net/Articles/955963/ https://lwn.net/Articles/955963/ dvdeug <div class="FormattedComment"> There was a GCC version that had a particular proprietary C compiler noted in its documentation because that compiler had a bug in its compiling of GCC that made certain optimizations NOPs. Thus a three stage bootstrap of GCC would produce a slightly broken first stage, and an unoptimized but correct second-stage, which would break bootstrap because it wouldn't match the optimized third stage.<br> <p> So it's conceivable that a bad bootstrap compiler could break the borrow checker in rustc. It'd be unlikely to carry over to next generations, though.<br> </div> Thu, 21 Dec 2023 18:55:28 +0000 Progress toward a GCC-based Rust compiler https://lwn.net/Articles/955741/ https://lwn.net/Articles/955741/ farnz <p>The part of safety that the borrow checker is responsible for is <em>purely</em> a property of the source code; it confirms that (for example) that the shared XOR mutable invariant is maintained by safe Rust. <p>Anything which can't be machine-checked at the source level as maintaining the safety invariants is supposed to marked with <tt>unsafe</tt>, which indicates that the human programmer is responsible for checking that things are safe. This means that anything outside Rust source (such as machine-specific primitives) should be marked as <tt>unsafe</tt>, and it's on the humans writing a safe wrapper to ensure that the wrapper maintains invariants at all times. <p>Rust does insist that all instantiations are either safe, or marked appropriately with <tt>unsafe</tt>; additionally, the caller of an instantiation of a generic that's marked with <tt>unsafe</tt> must mark their calling block with <tt>unsafe</tt> to indicate that they're OK with this. You cannot have an unsafe instantiation of a safe generic in safe code - you need the markers to tell Rust that you've thought about this and are going to uphold the language invariants, even if the compiler can't check your working (which is true of platform interfaces, for example, where the compiler can't check the platform behaviour). Wed, 20 Dec 2023 13:13:04 +0000 Progress toward a GCC-based Rust compiler https://lwn.net/Articles/955732/ https://lwn.net/Articles/955732/ rrolls <div class="FormattedComment"> Aha, so basically, the solution "borrow-check it with rustc, then compile it with whatever" effectively _is_ the solution "write the borrow-checker in a lower-level language". (Since IIRC, each rustc is built with an older rustc, but at some point you'd get back to a version of rustc that wasn't written in Rust.)<br> <p> One more complication, then. Is "safety" _purely_ a property of the source code, or does it depend on the environment it's being compiled in as well? For example, you use rustc to borrow-check your source code on a typical consumer-grade x86-64 linux platform, and now you compile the same code on some esoteric architecture and operating system. Presumably, the environment can affect, for example, how generics get instantiated, which might turn something that was deemed safe on the first platform into something that's not fine at all on the second? Or does Rust insist that code is only deemed safe if every possible instantiation is safe? I suppose you could request cross-compilation in your borrow-check step, which might address this, but it does add some complication.<br> </div> Wed, 20 Dec 2023 08:20:39 +0000 Progress toward a GCC-based Rust compiler https://lwn.net/Articles/955695/ https://lwn.net/Articles/955695/ steveklabnik <div class="FormattedComment"> Borrow checking does not affect codegen in any way. As long as the code runs successfully under a borrow checker, a compiler without one can compile it with zero issues. As rustc has been checked by rustc's borrow checker, mrustc will (modulo other bugs, of course) not miscompile it.<br> <p> At one point mrustc produced a byte-identical compiler to rustc, I am not sure if that's a one-time thing or if they always do that, though.<br> </div> Tue, 19 Dec 2023 16:37:52 +0000 Progress toward a GCC-based Rust compiler https://lwn.net/Articles/955694/ https://lwn.net/Articles/955694/ mathstuf <div class="FormattedComment"> Note that the borrow checker itself is not part of the language, but of the implementation. Rust's rule is "shared XOR mutable"; the borrow checker is an inexact implementation of an enforcement for this. It has been improved over time from the original lexical borrow checker to non-lexical lifetimes to polonius in the future. I presume that a runtime could also enforce it (at the cost of runtime overhead). In fact, I wonder if valgrind could be enhanced to verify this for any given program at runtime…that would give any implementation more trust in its enforcement of the rule.<br> </div> Tue, 19 Dec 2023 16:36:33 +0000 Progress toward a GCC-based Rust compiler https://lwn.net/Articles/955661/ https://lwn.net/Articles/955661/ farnz <p>The bootstrap compiler can only be safely used on sources that have been built successfully by a compiler on another platform that never went through a stage without a borrow checker; that way, if there is a bug caused by an invalid borrow (noting that borrow checking is purely a safety net - it does not affect codegen at all), the pre-existing compiler on another platform will have found it. Tue, 19 Dec 2023 15:17:19 +0000 Bootstrapping and borrow-checking https://lwn.net/Articles/955662/ https://lwn.net/Articles/955662/ timon <div class="FormattedComment"> I don’t think you’re wrong, but I want to add another idea:<br> <p> Being borrow-checked is more a property of the input (source code) rather than the output (binary), so I’d say you can reasonably treat it as orthogonal to your bootstrap chain.<br> <p> The problem of having a not-borrow-checked borrow-checker is similar to the “trusting trust” problem. For countering the trusting trust problem, you can do “diverse double-compiling” [1].<br> <p> I woud propose “borrowing borrow-checkers” as an even better countermeasure here. Just throw your bootstrap compiler Rust source at as many borrow-checkers as you can find, and optimally they should all agree whether your borrows are fine.<br> <p> [1]: <a href="https://dwheeler.com/trusting-trust/">https://dwheeler.com/trusting-trust/</a><br> </div> Tue, 19 Dec 2023 14:49:56 +0000 Progress toward a GCC-based Rust compiler https://lwn.net/Articles/955660/ https://lwn.net/Articles/955660/ rrolls <div class="FormattedComment"> I was considering the question "is it safe for a bootstrap Rust compiler to not include a borrow checker" before I even read the comments, so it's pleasing to see this discussed here.<br> <p> Surely the approach of "the final recursive build will discover [any invalid borrows] and fail" isn't 100% safe, because if an invalid borrow exists it's _possible_ (unlikely but possible) that it creates an edge case that allows exactly that invalid borrow through the borrow checker that was just compiled, right?<br> <p> I'd describe it as 99% safe, since in practice it'd be much more likely that an invalid borrow in the bootstrap compiler would cause some noticeable effect somewhere else and _not_ prevent its own discovery... but I think for 100% safety, you'd have no option but to write the borrow-checker in a lower-level, already-proven language.<br> <p> Do correct me if I'm wrong, though!<br> </div> Tue, 19 Dec 2023 14:05:06 +0000 Progress toward a GCC-based Rust compiler https://lwn.net/Articles/955656/ https://lwn.net/Articles/955656/ ssokolow <div class="FormattedComment"> Regardless, my understanding is that gccrs intends to borrow rustc's implementation of the borrow checker, written in Rust, because, as mrustc demonstrates, you don't need a borrow checker to bootstrap the compiler from a non-Rust language.<br> </div> Tue, 19 Dec 2023 12:58:20 +0000 Progress toward a GCC-based Rust compiler https://lwn.net/Articles/955612/ https://lwn.net/Articles/955612/ SAI_Peregrinus <div class="FormattedComment"> Polonius is both an alggorithm/model for borrow checking and a Datalog implementation of that algorithm. The implementation in rustc today is written in Rust, not Datalog. There are no longer plans to use the Datalog implementation in rustc, since there's a port to Rust.<br> </div> Mon, 18 Dec 2023 20:12:25 +0000 Progress toward a GCC-based Rust compiler https://lwn.net/Articles/955491/ https://lwn.net/Articles/955491/ tialaramex <div class="FormattedComment"> "I'm sure it's fine" is of course completely reasonable - for a bootstrap compiler. If it's not fine then our final recursive build will discover that and fail. This is no sort of way to do routine development, but that's not what a bootstrap compiler is for.<br> </div> Mon, 18 Dec 2023 02:13:36 +0000 Progress toward a GCC-based Rust compiler https://lwn.net/Articles/955492/ https://lwn.net/Articles/955492/ Cyberax <div class="FormattedComment"> mrustc can bootstrap 1.54<br> </div> Mon, 18 Dec 2023 02:13:30 +0000 Progress toward a GCC-based Rust compiler https://lwn.net/Articles/955487/ https://lwn.net/Articles/955487/ mathstuf <div class="FormattedComment"> `mrustc` is stuck on bootstrapping 1.39 last I heard (the primary author went off to complete their degree or something). Note that its "borrow checker" implementation is "I'm sure it's fine".<br> </div> Mon, 18 Dec 2023 01:20:40 +0000 Progress toward a GCC-based Rust compiler https://lwn.net/Articles/955479/ https://lwn.net/Articles/955479/ mcon147 <div class="FormattedComment"> It helps shake out the specification for the language itself<br> </div> Sun, 17 Dec 2023 19:34:58 +0000 Progress toward a GCC-based Rust compiler https://lwn.net/Articles/955455/ https://lwn.net/Articles/955455/ atnot <div class="FormattedComment"> It doesn't really change the bootstrapping story much, given that mrustc exists, which is a C++14 compiler that compiles valid rust to bad C11. So depending on whether you're okay pre-generating those sources, it is either around equally as easy or significantly easier to bootstrap than gccrs would be.<br> </div> Sun, 17 Dec 2023 02:28:04 +0000 Progress toward a GCC-based Rust compiler https://lwn.net/Articles/955452/ https://lwn.net/Articles/955452/ roc <div class="FormattedComment"> Reimplementing the front-end is likely to expose bugs where the rustc frontend does something unintended.<br> <p> I think it will also be useful for bootstrapping.<br> </div> Sun, 17 Dec 2023 01:10:53 +0000 Progress toward a GCC-based Rust compiler https://lwn.net/Articles/955450/ https://lwn.net/Articles/955450/ Phantom_Hoover <div class="FormattedComment"> I really do struggle to understand what the practical reason is for gccrs to exist. Integrating Rust with the GCC toolchain is a worthy goal with practical benefits mentioned in this article… and it’s already been achieved with the GCC codegen. I see no benefits to rewriting the frontend, and it will take a ton of constant work given how quickly Rust evolves. The only thing I can think of is easier bootstrapping, which is a pretty marginal concern.<br> <p> Actually I am a bit confused by this part of the article:<br> <p> <span class="QuotedText">&gt; There is a wide range of existing GCC plugins that can aid in debugging, static analysis, or hardening; these work on the GCC intermediate representation.</span><br> <p> Wouldn’t the GCC codegen for rustc be able to take advantage of this, given it’s emitting GCC IR?<br> </div> Sun, 17 Dec 2023 00:25:00 +0000 Progress toward a GCC-based Rust compiler https://lwn.net/Articles/955444/ https://lwn.net/Articles/955444/ josh <div class="FormattedComment"> As noted elsewhere in this thread, the question is whether you mean Polonius the standalone datalog-based implementation, or the algorithm that that implementation prototyped.<br> </div> Sat, 16 Dec 2023 20:14:33 +0000 Progress toward a GCC-based Rust compiler https://lwn.net/Articles/955435/ https://lwn.net/Articles/955435/ atnot <div class="FormattedComment"> You're linking to the same article quoted above, which (in the part quoted) explains the difference between polonius-the-implementation and polonius-the-mathematical-model, which was created while developing polonius-the-implementation. It announces that they no longer intend to use polonius-the-implementation in rustc.<br> <p> This is a recent development, because for the projects multi-year existence, the general consensus was that polonius-the-implementation was going to be used in rustc.<br> <p> What has been implemented in rustc is, thus, polonius-the-mathematical-model.<br> </div> Sat, 16 Dec 2023 14:21:30 +0000 Progress toward a GCC-based Rust compiler https://lwn.net/Articles/955434/ https://lwn.net/Articles/955434/ khim <p>What talks? Where? By whom? Who abandoned Polonius? Nightly Rust <a href="https://godbolt.org/z/oYfaeqxcj">still accepts -Zpolonius flag</a> today…</p> Sat, 16 Dec 2023 13:40:28 +0000 Progress toward a GCC-based Rust compiler https://lwn.net/Articles/955433/ https://lwn.net/Articles/955433/ khim <p>What “recent development” are you talking about? Polonius is already integrated into rustc and was on the way to becoming default in Rust 2024 <a href="https://blog.rust-lang.org/inside-rust/2023/10/06/polonius-update.html">only two months ago</a>.</p> <p>What happened in these two months???</p> Sat, 16 Dec 2023 13:37:53 +0000 Progress toward a GCC-based Rust compiler https://lwn.net/Articles/955432/ https://lwn.net/Articles/955432/ khim <p>I think you are mixing story of <a href="https://github.com/rust-lang/polonius">Polonius</a> and <a href="https://github.com/rust-lang/chalk">Chalk</a>.</p> <p>Attempts to bring Chalk into rustc were, indeed, abandoned. <a href="https://blog.rust-lang.org/inside-rust/2023/07/17/trait-system-refactor-initiative.html">And new replacement is supposed to be built, more tightly integrated with rustc</a>.</p> <p>Polonius, on the other hand, was integrated long ago. It's not enabled by default, but that is supposed to replace current borrow checker <a href="https://blog.rust-lang.org/inside-rust/2023/10/06/polonius-update.html">in Rust 2024</a>.</p> Sat, 16 Dec 2023 13:35:26 +0000 Progress toward a GCC-based Rust compiler https://lwn.net/Articles/955411/ https://lwn.net/Articles/955411/ josh <div class="FormattedComment"> That's true, but there's still discussion about librarifying chunks of rustc, even if it isn't the datalog-based borrow checker prototype.<br> </div> Fri, 15 Dec 2023 22:31:02 +0000 Progress toward a GCC-based Rust compiler https://lwn.net/Articles/955367/ https://lwn.net/Articles/955367/ atnot <div class="FormattedComment"> It should be noted that is a relatively recent development. Originally polonius was very much written with the idea that it would be used in rustc.<br> </div> Fri, 15 Dec 2023 16:23:44 +0000 Progress toward a GCC-based Rust compiler https://lwn.net/Articles/955354/ https://lwn.net/Articles/955354/ Bigos <div class="FormattedComment"> I don't think rustc will use Polonius directly:<br> <p> <span class="QuotedText">&gt; Polonius refers to a few things. It is a new formulation of the borrow checker. It is also a specific project that implemented that analysis, based on datalog. Our current plan does not make use of that datalog-based implementation, but uses what we learned implementing it to focus on reimplementing Polonius within rustc.</span><br> <p> <a href="https://blog.rust-lang.org/inside-rust/2023/10/06/polonius-update.html">https://blog.rust-lang.org/inside-rust/2023/10/06/poloniu...</a><br> <p> I understand that as they working on reimplementing Polonius within rustc (not a separate crate). It will use the original Polonius ideas but work in a different way.<br> </div> Fri, 15 Dec 2023 15:41:34 +0000