Progress toward a GCC-based Rust compiler
Progress toward a GCC-based Rust compiler
Posted Dec 17, 2023 1:10 UTC (Sun) by roc (subscriber, #30627)In reply to: Progress toward a GCC-based Rust compiler by Phantom_Hoover
Parent article: Progress toward a GCC-based Rust compiler
I think it will also be useful for bootstrapping.
Posted Dec 17, 2023 2:28 UTC (Sun)
by atnot (subscriber, #124910)
[Link] (11 responses)
Posted Dec 18, 2023 1:20 UTC (Mon)
by mathstuf (subscriber, #69389)
[Link] (10 responses)
Posted Dec 18, 2023 2:13 UTC (Mon)
by Cyberax (✭ supporter ✭, #52523)
[Link]
Posted Dec 18, 2023 2:13 UTC (Mon)
by tialaramex (subscriber, #21167)
[Link] (8 responses)
Posted Dec 19, 2023 14:05 UTC (Tue)
by rrolls (subscriber, #151126)
[Link] (7 responses)
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?
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.
Do correct me if I'm wrong, though!
Posted Dec 19, 2023 14:49 UTC (Tue)
by timon (subscriber, #152974)
[Link]
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.
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].
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.
Posted Dec 19, 2023 15:17 UTC (Tue)
by farnz (subscriber, #17727)
[Link] (1 responses)
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.
Posted Dec 19, 2023 16:36 UTC (Tue)
by mathstuf (subscriber, #69389)
[Link]
Posted Dec 19, 2023 16:37 UTC (Tue)
by steveklabnik (guest, #114343)
[Link] (2 responses)
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.
Posted Dec 20, 2023 8:20 UTC (Wed)
by rrolls (subscriber, #151126)
[Link] (1 responses)
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.
Posted Dec 20, 2023 13:13 UTC (Wed)
by farnz (subscriber, #17727)
[Link]
The part of safety that the borrow checker is responsible for is purely a property of the source code; it confirms that (for example) that the shared XOR mutable invariant is maintained by safe Rust.
Anything which can't be machine-checked at the source level as maintaining the safety invariants is supposed to marked with unsafe, 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 unsafe, and it's on the humans writing a safe wrapper to ensure that the wrapper maintains invariants at all times.
Rust does insist that all instantiations are either safe, or marked appropriately with unsafe; additionally, the caller of an instantiation of a generic that's marked with unsafe must mark their calling block with unsafe 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).
Posted Dec 21, 2023 18:55 UTC (Thu)
by dvdeug (guest, #10998)
[Link]
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.
Progress toward a GCC-based Rust compiler
Progress toward a GCC-based Rust compiler
Progress toward a GCC-based Rust compiler
Progress toward a GCC-based Rust compiler
Progress toward a GCC-based Rust compiler
Bootstrapping and borrow-checking
Progress toward a GCC-based Rust compiler
Progress toward a GCC-based Rust compiler
Progress toward a GCC-based Rust compiler
Progress toward a GCC-based Rust compiler
Progress toward a GCC-based Rust compiler
Progress toward a GCC-based Rust compiler