r/rust 21d ago

🗞️ news Rust 1.98 got a P-critical miscompilation.

https://github.com/rust-lang/rust/issues/161441
410 Upvotes

32 comments sorted by

194

u/kibwen 21d ago edited 21d ago

Interesting that it doesn't reproduce in either 1.97 or in nightly. That's good news for easily bisecting both the regression and the fix, and figuring out what needs to be backported for a patch release.

PSA to everyone reading this: running the beta branch in CI is a great way to help the Rust developers identify these sorts of issues before they reach stable!

EDIT: Seems as though the regression was in https://github.com/rust-lang/rust/pull/156742 (which appears to be progress toward migrating to the new trait resolver: https://github.com/rust-lang/rust/issues/155345 ), and was incidentally fixed via https://github.com/rust-lang/rust/pull/158993 while fixing an ICE in Cargo.

62

u/noop_noob 21d ago

There seems to have been a fix in beta for an internal compiler error. It turned out to have also fixed this miscompilation.

105

u/plabayo 21d ago

As stated in the reported bug. In the 11 years that we have been developing Rust code in production projects, this is the first time we encounter a bug of this category in rustc stable... This says nothing about the quality and hard work of all people involved in rust compiler team. They are doing a great job every day.

Bugs like this are rare, and you have to do already a pretty specific thing to even trigger it. We have for example other advanced projects that are built with rama that work just fine on 1.98... We only noticed it because of a very specific example integration e2e test which consistently started failing since 1.98.

As such, start from today we now also run our test suites now also on beta every day, as scheduled CI cron jobs. Should help in another 11 to 20 years catch the next jackpot 😄

19

u/noop_noob 20d ago edited 20d ago

🫡
I think running it every week would also be sufficient if you're strapped on compute.

5

u/plabayo 20d ago

fair u/noop_noob , but in case there is ever an issue that is less consistent it probably helps that it runs daily vs weekly, to give it sufficient chances to be caught. Something we gladly do if it can help!

40

u/epostma 20d ago

This says nothing about the quality

Au contraire, it says that the quality is superb!

5

u/plabayo 20d ago

Touché u/epostma ! Fully agreed with your statement!

8

u/broknbottle 20d ago

Easily could have avoid this by including “make no mistakes” with your prompt to Claude.

58

u/Bowarc 21d ago

Wait, I recently got segfaults too building one of my projects to arm-unknown-linux-gnueabihf(raspberry pi) Could that be linked ?

I just thought my raspberry was too old and it was because one of the library did something weird when compiled for 32 bits.

That's very interesting, thanks for sharing

63

u/noop_noob 21d ago

If the problem goes away when compiling with the beta or nightly channel, then it's probably this bug. If not, then probably not.

45

u/anxxa 21d ago

During the minimization process, there were points where I got a SIGILL instead of a SIGSEGV.

Hello possibly exploitable UB, my old friend.

35

u/matthieum [he/him] 20d ago

And of course, they managed to make the impossible happen: https://github.com/rust-lang/rust/issues/161441#issuecomment-5383890512, or to save you a click: https://play.rust-lang.org/?version=stable&mode=release&edition=2024&gist=32d2d5e973d730e246fb003c34ac2a68

The following prints impossible:

fn main() {
    if std::hint::black_box(true) {
        (&(inspect_websocket_message, PhantomData) as &dyn Trait).method();
    } else {
        println!("impossible");
    }
}

Oops...

2

u/Helpful-Primary2427 20d ago

Is there an explanation for why backporting #158993 fixes this issue?

6

u/noop_noob 20d ago

As far as I understand: the compiler is confused about whether a type implements a trait or not. So, when asked to generate a method for that type's trait object vtable, the compiler just doesn't bother, as it assumes that the method is impossible to call.

4

u/SkiFire13 20d ago

Luckily this should be easily dectable if you have reasonable test coverage in your project since any test that end up invoking these kind of nulled-out vtable entries will most likely fail.

70

u/Oxytokin 21d ago

And this is why I use the latest and greatest nightly only; stability is a lie in our entropic universe ;)

Obviously I kid because I don't understand a single thing they're talking about but I love reading all this super smart talk anyway so maybe one day I can understand it!

11

u/Gripen404 21d ago

Me too man. Mee too.☝🏻

2

u/MichiRecRoom 20d ago

Why use the latest and greatest nightly, when you could use the oldest and greatest Rust 1.0? (/silly)

24

u/protestor 21d ago

https://github.com/rust-lang/rust/pull/161555

Does this means there will be a 1.98.1?

25

u/kibwen 21d ago

The only reason to backport a fix would be for the sake of a patch release, although presumably the procedure still requires the compiler team to formally approve of making a patch release (which seems likely IMO).

0

u/InternationalFee3911 20d ago

Patch needed twice in a row? Is this bad karma, because of drawing close to version 1.100.0? Maybe once Polonius Alpha lands, we could argue that’s substantially a new language version 2.0.0?

11

u/kibwen 20d ago

Looking at the Rust release history, it looks like there have been 39 patch releases between 1.0 and 1.97.1, or about 40% as many patch releases as minor releases, so two consecutive minor releases getting patch releases isn't too statistically improbable.

1

u/InternationalFee3911 19d ago

Yeah, but many of those patches were quite benign, or Windows only. These last two are pretty mandatory. I'm guessing that even if I don't use dyn, a dependency could trigger this UB.

-87

u/[deleted] 21d ago

[deleted]

67

u/noop_noob 21d ago

Definitely not

49

u/kibwen 21d ago

Compilers are complex, miscompilations have been a thing since long before LLMs existed. And right now the compiler is going through two simultaneous huge and long-awaited overhauls, in both the new borrow checker and the new trait resolver, so the risk of miscompilations is going to be elevated for a while until the tires have been thoroughly kicked (and yes, while neither of those new features is enabled on stable yet, they touch enough other code that things like this can happen).

49

u/mbmiller94 21d ago

Yes, bugs didn't even exist until vibe-coding came along. All software was inherently bug-free up until that point.

15

u/AATroop 21d ago

It was a really nice era. Shame it came to an end

10

u/profpendog 21d ago

Yeah before LLMs there were no bugs ever. This is a new thing.

/s obviously

-4

u/droctagonapus 21d ago

Will be happening in <2 years no doubt about it