Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

broken mir, trivial loop with -Zvalidate-mir #73860

Closed
matthiaskrgr opened this issue Jun 29, 2020 · 4 comments · Fixed by #74411
Closed

broken mir, trivial loop with -Zvalidate-mir #73860

matthiaskrgr opened this issue Jun 29, 2020 · 4 comments · Fixed by #74411
Labels
A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

Code

The code fails to pass -Zvalidate-mir

fn main() {
 for _ in &[0] {}
}

Meta

Repo is at c86039b

Error output

error: internal compiler error: broken MIR in Item(DefId(0:3 ~ main[317d]::main[0])) (input to phase Const) at bb13[0]:
encountered `Assign` statement with incompatible types:
left-hand side has type: !
right-hand side has type: ()
 --> main.rs:2:2
  |
2 |  for _ in &[0] {}
  |  ^^^^^^^^^^^^^^^^
  |
  = note: delayed at src/librustc_mir/transform/validate.rs:140:36

error: internal compiler error: broken MIR in Item(DefId(0:3 ~ main[317d]::main[0])) (after CheckPackedRef in phase Const) at bb13[0]:
encountered `Assign` statement with incompatible types:
left-hand side has type: !
right-hand side has type: ()
 --> main.rs:2:2
  |
2 |  for _ in &[0] {}
  |  ^^^^^^^^^^^^^^^^
  |
  = note: delayed at src/librustc_mir/transform/validate.rs:140:36

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src/librustc_errors/lib.rs:367:17
Backtrace

error: internal compiler error: broken MIR in Item(DefId(0:3 ~ main[317d]::main[0])) (input to phase Const) at bb13[0]:
encountered `Assign` statement with incompatible types:
left-hand side has type: !
right-hand side has type: ()
 --> main.rs:2:2
  |
2 |  for _ in &[0] {}
  |  ^^^^^^^^^^^^^^^^
  |
  = note: delayed at src/librustc_mir/transform/validate.rs:140:36

error: internal compiler error: broken MIR in Item(DefId(0:3 ~ main[317d]::main[0])) (after CheckPackedRef in phase Const) at bb13[0]:
encountered `Assign` statement with incompatible types:
left-hand side has type: !
right-hand side has type: ()
 --> main.rs:2:2
  |
2 |  for _ in &[0] {}
  |  ^^^^^^^^^^^^^^^^
  |
  = note: delayed at src/librustc_mir/transform/validate.rs:140:36

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src/librustc_errors/lib.rs:367:17
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /home/matthias/.cargo/registry/src/git.luolix.top-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/libunwind.rs:86
   1: backtrace::backtrace::trace_unsynchronized
             at /home/matthias/.cargo/registry/src/git.luolix.top-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:78
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:59
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1076
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1537
   6: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:62
   7: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:49
   8: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:198
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:217
  10: <alloc::boxed::Box<F> as core::ops::function::Fn<A>>::call
             at ./src/liballoc/boxed.rs:1092
  11: rustc_driver::report_ice
             at src/librustc_driver/lib.rs:1160
  12: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:524
  13: std::panicking::begin_panic
             at ./src/libstd/panicking.rs:450
  14: <rustc_errors::HandlerInner as core::ops::drop::Drop>::drop
             at src/librustc_errors/lib.rs:367
  15: core::ptr::drop_in_place
             at ./src/libcore/ptr/mod.rs:184
  16: core::ptr::drop_in_place
             at ./src/libcore/ptr/mod.rs:184
  17: core::ptr::drop_in_place
             at ./src/libcore/ptr/mod.rs:184
  18: core::ptr::drop_in_place
             at ./src/libcore/ptr/mod.rs:184
  19: core::ptr::drop_in_place
             at ./src/libcore/ptr/mod.rs:184
  20: core::ptr::drop_in_place
             at ./src/libcore/ptr/mod.rs:184
  21: core::ptr::drop_in_place
             at ./src/libcore/ptr/mod.rs:184
  22: core::ptr::drop_in_place
             at ./src/libcore/ptr/mod.rs:184
  23: <alloc::rc::Rc<T> as core::ops::drop::Drop>::drop
             at ./src/liballoc/rc.rs:1159
  24: core::ptr::drop_in_place
             at ./src/libcore/ptr/mod.rs:184
  25: core::ptr::drop_in_place
             at ./src/libcore/ptr/mod.rs:184
  26: core::mem::drop
             at ./src/libcore/mem/mod.rs:877
  27: rustc_interface::interface::run_compiler_in_existing_thread_pool::{{closure}}::{{closure}}
             at ./src/librustc_interface/interface.rs:199
  28: rustc_data_structures::profiling::TimingGuard::run
             at ./src/librustc_data_structures/profiling.rs:555
  29: rustc_interface::interface::run_compiler_in_existing_thread_pool::{{closure}}
             at ./src/librustc_interface/interface.rs:199
  30: rustc_span::with_source_map
             at ./src/librustc_span/lib.rs:727
  31: rustc_interface::interface::run_compiler_in_existing_thread_pool
             at ./src/librustc_interface/interface.rs:189
  32: rustc_interface::interface::run_compiler::{{closure}}
             at ./src/librustc_interface/interface.rs:211
  33: rustc_interface::util::spawn_thread_pool::{{closure}}::{{closure}}::{{closure}}
             at ./src/librustc_interface/util.rs:149
  34: scoped_tls::ScopedKey<T>::set
             at /home/matthias/.cargo/registry/src/git.luolix.top-1ecc6299db9ec823/scoped-tls-1.0.0/src/lib.rs:137
  35: rustc_interface::util::spawn_thread_pool::{{closure}}::{{closure}}
             at ./src/librustc_interface/util.rs:145
  36: scoped_tls::ScopedKey<T>::set
             at /home/matthias/.cargo/registry/src/git.luolix.top-1ecc6299db9ec823/scoped-tls-1.0.0/src/lib.rs:137
  37: rustc_ast::attr::with_globals::{{closure}}
             at ./src/librustc_ast/attr/mod.rs:44
  38: scoped_tls::ScopedKey<T>::set
             at /home/matthias/.cargo/registry/src/git.luolix.top-1ecc6299db9ec823/scoped-tls-1.0.0/src/lib.rs:137
  39: rustc_ast::attr::with_globals
             at ./src/librustc_ast/attr/mod.rs:44
  40: rustc_interface::util::spawn_thread_pool::{{closure}}
             at ./src/librustc_interface/util.rs:144
  41: rustc_interface::util::scoped_thread::{{closure}}
             at ./src/librustc_interface/util.rs:119
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.46.0-dev running on x86_64-unknown-linux-gnu

note: compiler flags: -Z validate-mir

query stack during panic:
end of query stack

@matthiaskrgr matthiaskrgr added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 29, 2020
@matthiaskrgr matthiaskrgr changed the title broken mir, trivial loop with -Zverify-mir broken mir, trivial loop with -Zvalidate-mir Jun 29, 2020
@jonas-schievink jonas-schievink added A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html requires-nightly This issue requires a nightly compiler in some way. labels Jun 29, 2020
@RalfJung
Copy link
Member

Oh that is interesting:

left-hand side has type: !
right-hand side has type: ()

@nikomatsakis @eddyb is that expected? The other way around would make sense (assigning a ! into anything, really), but with a ! on the left, that seems odd? Or maybe the message just gets the sides wrong.

@RalfJung
Copy link
Member

Yeah, that MIR looks really broken:

    let mut _14: !;                      // in scope 0 at test.rs:2:2: 2:18
[...]
        _14 = const ();                  // scope 2 at test.rs:2:2: 2:18

Cc @matthewjasper

@matthewjasper
Copy link
Contributor

This is probably due to this line:

this.cfg.push_assign_unit(block, source_info, destination, this.hir.tcx());

Break, Continueand Return shouldn't have this, since they have type !, not ().

@nagisa
Copy link
Member

nagisa commented Jul 4, 2020

is that expected? The other way around would make sense (assigning a ! into anything, really), but with a ! on the left, that seems odd? Or maybe the message just gets the sides wrong.

This is a super old issue going back all the way to the initial MIR implementation and I’m somewhat confident is documented somewhere, though I cannot find an issue for this.

IIRC these invalid assignments only happen in unreachable basic blocks, so however wrong it looks in isolation, it is dead code and I think it never was a priority to fix either generation or the MIR validation we had back then for exactly that reason.

Looks like -Zvalidate-mir is a new take on validation? Perhaps the easy fix would be to not validate unreachable blocks.

@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Jul 6, 2020
Manishearth added a commit to Manishearth/rust that referenced this issue Jul 17, 2020
…hewjasper

Don't assign `()` to `!` MIR locals

Implements the fix described in rust-lang#73860 (comment).

Fixes rust-lang#73860

r? @matthewjasper
@bors bors closed this as completed in 87d01d1 Jul 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants