rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
97.83k stars 12.66k forks source link

regression: ICE -- bad ConstKind after monomorphizing #94502

Closed Mark-Simulacrum closed 2 years ago

Mark-Simulacrum commented 2 years ago

Crater picked up this issue in a number of crates:

May be a duplicate of https://github.com/rust-lang/rust/issues/93002, but filing this as a dedicated bug with a rough list of affected crates in Crater.

ty::ConstKind::Error constructed but no error reported (we should check, may be a distinct bug; maybe https://github.com/rust-lang/rust/issues/94506):

[INFO] [stdout] error: internal compiler error: /rustc/0a4f984a87c7ba6c74ec3e78442fec955a419e32/compiler/rustc_codegen_ssa/src/mir/constant.rs:42:20: encountered bad ConstKind after monomorphizing: Error(DelaySpanBugEmitted(()))
[INFO] [stdout]   --> parse/src/day02.rs:21:73
[INFO] [stdout]    |
[INFO] [stdout] 21 |     let char_count = count_dict.get(&password_rule.character).unwrap_or(&0);
[INFO] [stdout]    |                                                                         ^^
[INFO] [stdout] 
oli-obk commented 2 years ago

cc @b-naber @lcnr does this ring a bell wrt recent const representation changes in MIR?

b-naber commented 2 years ago

cc @b-naber @lcnr does this ring a bell wrt recent const representation changes in MIR?

Does a crater run use nightly?

None of the changes we made are in nightly right now. Only one PR was merged, but that was later reverted.

matthiaskrgr commented 2 years ago

Reduced a bit from https://github.com/deaz/adventofcode-2018:

use std::collections::HashMap;

pub fn f(input: &str) {
    input
        .lines()
        .map(|s| -> (u32) { (1) })
        .fold(HashMap::new(), |mut map, (x)| {
            let prev = map.get(&(0, x)).unwrap_or(&0);
            map.insert((0, x), prev + 1);
            map
        });
}

pub fn main() {
    let _ = f("");
}

This crashes on beta but not on stable or nightly.

lcnr commented 2 years ago

minimalized

struct Repro;
impl Repro {
    fn get(&self) -> &i32 {
        &3
    }

    fn insert(&mut self, _: i32) {}
}

fn main() {
    let x = &0;
    let mut conflict = Repro;
    let prev = conflict.get();
    conflict.insert(*prev + *x);
}

the issue is that body.tainted_by_errors is also set when only emitting a lint

eddyb commented 2 years ago

Sounds like this comment might be relevant: https://github.com/rust-lang/rust/pull/93368#issuecomment-1048487073 - i.e. that PR ended up doing a drive-by fix because conflating errors and warnings became a type mismatch at the DiagnosticBuilder level.

So you can probably confirm that nightly was broken between #93691 landing (nightly-2022-02-13?) and #93368 landing (nightly-2022-02-26?), and I guess beta branched between the two?

EDIT: heh, @lcnr already opened the fix/backport PR as I was writing this.

pietroalbini commented 2 years ago

Should be fixed by https://github.com/rust-lang/rust/pull/94552.