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

ICE: -Zvalidate-mir: broken mir in libcore #73109

Closed
matthiaskrgr opened this issue Jun 7, 2020 · 19 comments · Fixed by #73359
Closed

ICE: -Zvalidate-mir: broken mir in libcore #73109

matthiaskrgr opened this issue Jun 7, 2020 · 19 comments · Fixed by #73359
Assignees
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) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Jun 7, 2020

Code

fn main() {
	let x = "a".to_string();
  }

Meta

rustc --version --verbose:
repo @ 0262de5

<version>

Error output

build/x86_64-unknown-linux-gnu/stage2/bin/rustc bad.rs -Zvalidate-mir

error: internal compiler error: broken MIR in DefId(2:2110 ~ core[13dc]::ops[0]::function[0]::FnOnce[0]::call_once[0]) (input to phase Const) at bb0[0]:
encountered non-callable type Self in `Call` terminator
   --> /home/matthias/vcs/github/rust/src/libcore/ops/function.rs:232:5
    |
232 |     extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: internal compiler error: broken MIR in DefId(2:2110 ~ core[13dc]::ops[0]::function[0]::FnOnce[0]::call_once[0]) (after AddMovesForPackedDrops in phase Const) at bb0[0]:
encountered non-callable type Self in `Call` terminator
   --> /home/matthias/vcs/github/rust/src/libcore/ops/function.rs:232:5
    |
232 |     extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: internal compiler error: broken MIR in DefId(2:2110 ~ core[13dc]::ops[0]::function[0]::FnOnce[0]::call_once[0]) (after NoLandingPads in phase Const) at bb0[0]:
encountered non-callable type Self in `Call` terminator
   --> /home/matthias/vcs/github/rust/src/libcore/ops/function.rs:232:5
    |
232 |     extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: internal compiler error: broken MIR in DefId(2:2110 ~ core[13dc]::ops[0]::function[0]::FnOnce[0]::call_once[0]) (after RemoveNoopLandingPads in phase Const) at bb0[0]:
encountered non-callable type Self in `Call` terminator
   --> /home/matthias/vcs/github/rust/src/libcore/ops/function.rs:232:5
    |
232 |     extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: internal compiler error: broken MIR in DefId(2:2110 ~ core[13dc]::ops[0]::function[0]::FnOnce[0]::call_once[0]) (after SimplifyCfg-make_shim in phase Const) at bb0[0]:
encountered non-callable type Self in `Call` terminator
   --> /home/matthias/vcs/github/rust/src/libcore/ops/function.rs:232:5
    |
232 |     extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: internal compiler error: broken MIR in DefId(2:2110 ~ core[13dc]::ops[0]::function[0]::FnOnce[0]::call_once[0]) (after AddCallGuards in phase Const) at bb0[0]:
encountered non-callable type Self in `Call` terminator
   --> /home/matthias/vcs/github/rust/src/libcore/ops/function.rs:232:5
    |
232 |     extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src/librustc_errors/lib.rs:366:17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Backtrace

warning: unused variable: `x`
 --> ./src/test/ui/issues/issue-29053.rs:4:5
  |
4 | let x = "a".to_string();
  |     ^ help: if this is intentional, prefix it with an underscore: `_x`
  |
  = note: `#[warn(unused_variables)]` on by default

warning: 1 warning emitted

error: internal compiler error: broken MIR in DefId(2:2110 ~ core[13dc]::ops[0]::function[0]::FnOnce[0]::call_once[0]) (input to phase Const) at bb0[0]:
encountered non-callable type Self in `Call` terminator
   --> /home/matthias/vcs/github/rust/src/libcore/ops/function.rs:232:5
    |
232 |     extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: internal compiler error: broken MIR in DefId(2:2110 ~ core[13dc]::ops[0]::function[0]::FnOnce[0]::call_once[0]) (after AddMovesForPackedDrops in phase Const) at bb0[0]:
encountered non-callable type Self in `Call` terminator
   --> /home/matthias/vcs/github/rust/src/libcore/ops/function.rs:232:5
    |
232 |     extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: internal compiler error: broken MIR in DefId(2:2110 ~ core[13dc]::ops[0]::function[0]::FnOnce[0]::call_once[0]) (after NoLandingPads in phase Const) at bb0[0]:
encountered non-callable type Self in `Call` terminator
   --> /home/matthias/vcs/github/rust/src/libcore/ops/function.rs:232:5
    |
232 |     extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: internal compiler error: broken MIR in DefId(2:2110 ~ core[13dc]::ops[0]::function[0]::FnOnce[0]::call_once[0]) (after RemoveNoopLandingPads in phase Const) at bb0[0]:
encountered non-callable type Self in `Call` terminator
   --> /home/matthias/vcs/github/rust/src/libcore/ops/function.rs:232:5
    |
232 |     extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: internal compiler error: broken MIR in DefId(2:2110 ~ core[13dc]::ops[0]::function[0]::FnOnce[0]::call_once[0]) (after SimplifyCfg-make_shim in phase Const) at bb0[0]:
encountered non-callable type Self in `Call` terminator
   --> /home/matthias/vcs/github/rust/src/libcore/ops/function.rs:232:5
    |
232 |     extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: internal compiler error: broken MIR in DefId(2:2110 ~ core[13dc]::ops[0]::function[0]::FnOnce[0]::call_once[0]) (after AddCallGuards in phase Const) at bb0[0]:
encountered non-callable type Self in `Call` terminator
   --> /home/matthias/vcs/github/rust/src/libcore/ops/function.rs:232:5
    |
232 |     extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src/librustc_errors/lib.rs:366:17
stack backtrace:
   0:     0x7ff80b84a927 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h76512f7a256472fb
   1:     0x7ff80b8973ed - core::fmt::write::hc64edb3869fa1953
   2:     0x7ff80b838ed5 - std::io::Write::write_fmt::h22c2e31bf0666336
   3:     0x7ff80b826720 - std::panicking::default_hook::{{closure}}::h8f574173d5f96f34
   4:     0x7ff80b826434 - std::panicking::default_hook::h6d7c5c0ca6d5609a
   5:     0x7ff80d1e3063 - rustc_driver::report_ice::h431648ac89c0c7bf
   6:     0x7ff80b826e0c - std::panicking::rust_panic_with_hook::hf2dca5902ecb2b51
   7:     0x7ff81131e02e - std::panicking::begin_panic::hf5fc738ac6374f42
   8:     0x7ff81135661e - <rustc_errors::HandlerInner as core::ops::drop::Drop>::drop::h3bc01279a971299c
   9:     0x7ff80d23ea56 - core::ptr::drop_in_place::h2641e7528eee45ff
  10:     0x7ff80d2475a6 - <alloc::rc::Rc<T> as core::ops::drop::Drop>::drop::h324ce0426c1e8578
  11:     0x7ff80d26733d - core::ptr::drop_in_place::hec47fdddd89633e0
  12:     0x7ff80d2591b1 - rustc_span::with_source_map::ha1d5ff3f79f62133
  13:     0x7ff80d1e84b9 - rustc_interface::interface::run_compiler_in_existing_thread_pool::ha05b609632adf0fb
  14:     0x7ff80d1cda8e - scoped_tls::ScopedKey<T>::set::h3583f55ed4da470f
  15:     0x7ff80d1e99e6 - std::sys_common::backtrace::__rust_begin_short_backtrace::h8229f831f4f87563
  16:     0x7ff80d1c5dce - core::ops::function::FnOnce::call_once{{vtable.shim}}::hc78b13e1eb35a770
  17:     0x7ff80b82f058 - std::sys::unix::thread::Thread::new::thread_start::heec70046c66b2eb2
  18:     0x7ff80b555422 - start_thread
  19:     0x7ff80b673bf3 - __GI___clone
  20:                0x0 - <unknown>

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

This issue has been assigned to @doctorn via this comment.

@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 7, 2020
@matthiaskrgr matthiaskrgr changed the title ICE: broken mir: let x = "a".to_string(); -Zvalidate-mir ICE: -Zvalidate-mir: broken mir in libcore Jun 8, 2020
@matthiaskrgr
Copy link
Member Author

matthiaskrgr commented Jun 8, 2020

This was introduced between
118b505
(nightly

rustc 1.46.0-nightly (118b50524 2020-06-06)
binary: rustc
commit-hash: 118b50524b79e565f017e08bce9b90a16c63634f
commit-date: 2020-06-06
host: x86_64-unknown-linux-gnu
release: 1.46.0-nightly
LLVM version: 10.0

)

and 0262de5

@matthiaskrgr
Copy link
Member Author

Might be related to #72810
cc @RalfJung ?

@RalfJung
Copy link
Member

RalfJung commented Jun 8, 2020

Hm... @jonas-schievink suggested to also accept Self as callable. I was initially opposed because Miri will ICE when anything but a FnPtr/FnDef is called. But is this even MIR that Miri ever sees? What does the Self here normalize to, and is there a method we have to do that normalization?

@jonas-schievink jonas-schievink added the A-mir Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html label Jun 8, 2020
@doctorn
Copy link
Contributor

doctorn commented Jun 9, 2020

I'm having a look at this - if it gets too rough I'll be sure to release

@rustbot claim

@rustbot rustbot self-assigned this Jun 9, 2020
@jonas-schievink
Copy link
Contributor

FYI: I think the solution outlined in https://rust-lang.zulipchat.com/#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/-Zvalidate-mir.20errors.20on.20master/near/200033437 is better than just accepting Self. The latter is very easy, but the "proper" solution involves changing the shim code, and I don't really know much about how that works.

@doctorn
Copy link
Contributor

doctorn commented Jun 9, 2020

Checking Self: FnOnce seems to work

@doctorn
Copy link
Contributor

doctorn commented Jun 9, 2020

Papered over by #73175 but @RalfJung explains that this really isn't a proper solution. I'll have a serious look at the shim code this week and see if we can get a more robust solution.

@RalfJung
Copy link
Member

FWIW, here's the Miri code that would ICE for a Self callee:

let (fn_val, abi) = match func.layout.ty.kind {

I think Miri runs shims as well, so... not sure what happens here.

@RalfJung
Copy link
Member

But, the thing is, Self isn't actually a type. Self is more like a type alias. So what is the actual underlying type here? My theory is that it's a FnDef/FnPtr and that's why Miri does not complain.

@jonas-schievink
Copy link
Contributor

I've checked this locally and Self is in fact a TyParam there (is the type-alias-Self even pretty-printed as Self instead of the aliased type?). Maybe Miri is applying some substs that replace it with the real type?

@RalfJung
Copy link
Member

Miri has a subst that monomorphizes everything, yes.
So the problem is that this is generic MIR, and Self is later substituted with a FnDef/FnPtr for codegen/Miri?

@jonas-schievink
Copy link
Contributor

That's my current hypothesis, but I haven't verified it yet

@doctorn
Copy link
Contributor

doctorn commented Jun 10, 2020

That was how I was thinking about it when I wrote the trait bounds check - although I'm really just getting to grips with MIR so it was just an idea (albeit - I thought it was a different piece of MIR that was generic)

@doctorn
Copy link
Contributor

doctorn commented Jun 10, 2020

In that case though - isn't a trait bounds check enough given a flag for the MIR validator to disable it when we expect non-generic MIR?

@RalfJung
Copy link
Member

Maybe... I guess the question is, right now we don't see this happen outside the shims; should we make sure it stays that way?

@doctorn
Copy link
Contributor

doctorn commented Jun 10, 2020

I just started investigating - do #69036 and #69925 sound relevant?

@doctorn
Copy link
Contributor

doctorn commented Jun 10, 2020

Ok as far as I can tell #69925 is the problem.

MIR shims get substitutions in two places: one phase computes the signature and the other resolves types in the body for mono-morphisation. To avoid double-substitutions @eddyb added some papering that asserts that signatures for FnPtrShims should already be concrete when they're built; however, the code in build_call_shim ignores this fact completely and uses generic substs that can be concretised later.

I'm having a look to see if I can alter the shim code to make use of the concretised version as this would resolve our problems and remove the need for #73175.

@doctorn
Copy link
Contributor

doctorn commented Jun 10, 2020

Didn't work :(( I start getting lots of panics (example attached). I have no idea why this would be the case though... Here's my branch - https://github.com/doctorn/rust/tree/mir-shim-validation.

Backtrace
error: internal compiler error: src/librustc_middle/mir/tcx.rs:84: deref projection of non-dereferenceable ty PlaceTy { ty: usize, variant_index: None }

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:907:9
stack backtrace:
   0: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
   1: core::fmt::write
   2: std::io::Write::write_fmt
   3: std::sys_common::backtrace::print
   4: std::panicking::default_hook::{{closure}}
   5: std::panicking::default_hook
   6: rustc_driver::report_ice
   7: std::panicking::rust_panic_with_hook
   8: std::panicking::begin_panic
   9: rustc_errors::HandlerInner::bug
  10: rustc_errors::Handler::bug
  11: rustc_middle::util::bug::opt_span_bug_fmt::{{closure}}
  12: rustc_middle::ty::context::tls::with_opt::{{closure}}
  13: rustc_middle::ty::context::tls::with_opt
  14: rustc_middle::util::bug::opt_span_bug_fmt
  15: rustc_middle::util::bug::bug_fmt
  16: rustc_middle::mir::tcx::PlaceTy::projection_ty_core::{{closure}}
  17: rustc_middle::mir::tcx::PlaceTy::projection_ty_core
  18: rustc_middle::mir::tcx::PlaceTy::projection_ty
  19: <rustc_mir::monomorphize::collector::MirNeighborCollector as rustc_middle::mir::visit::Visitor>::visit_terminator_kind
  20: rustc_middle::mir::visit::Visitor::visit_body
  21: rustc_mir::monomorphize::collector::collect_neighbours
  22: rustc_data_structures::stack::ensure_sufficient_stack
  23: rustc_mir::monomorphize::collector::collect_items_rec
  24: rustc_mir::monomorphize::collector::collect_items_rec
  25: rustc_mir::monomorphize::collector::collect_items_rec
  26: rustc_mir::monomorphize::collector::collect_items_rec
  27: rustc_mir::monomorphize::collector::collect_items_rec
  28: rustc_mir::monomorphize::collector::collect_items_rec
  29: rustc_mir::monomorphize::collector::collect_items_rec
  30: rustc_mir::monomorphize::collector::collect_items_rec
  31: rustc_mir::monomorphize::collector::collect_items_rec
  32: rustc_mir::monomorphize::collector::collect_items_rec
  33: rustc_session::utils::<impl rustc_session::session::Session>::time
  34: rustc_mir::monomorphize::collector::collect_crate_mono_items
  35: rustc_mir::monomorphize::partitioning::collect_and_partition_mono_items
  36: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::collect_and_partition_mono_items>::compute
  37: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  38: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  39: rustc_data_structures::stack::ensure_sufficient_stack
  40: rustc_query_system::query::plumbing::get_query_impl
  41: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
  42: rustc_session::utils::<impl rustc_session::session::Session>::time
  43: rustc_middle::ty::context::tls::enter_global
  44: rustc_interface::queries::Query<T>::compute
  45: rustc_interface::queries::Queries::ongoing_codegen
  46: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  47: rustc_span::with_source_map
  48: rustc_ast::attr::with_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

@jonas-schievink
Copy link
Contributor

I've managed to fix the shim creation to avoid Self: #73359

Not sure that's the best approach, but it seems to work.

@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Jun 17, 2020
@bors bors closed this as completed in fe4b485 Jun 20, 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) ❄️ 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