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 with borrow checker in nightly #62107

Closed
kdar opened this issue Jun 25, 2019 · 2 comments · Fixed by #62233
Closed

ICE with borrow checker in nightly #62107

kdar opened this issue Jun 25, 2019 · 2 comments · Fixed by #62233
Assignees
Labels
A-borrow-checker Area: The borrow checker I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@kdar
Copy link

kdar commented Jun 25, 2019

ICE with the borrow checker on nightly. Tried on stable/beta and it correctly errors with

tx.send(Event::Rpc(response(resp.id))).unwrap();
   |                                             ^^^^^^^ cannot move out of borrowed content

in nightly, I get

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.37.0-nightly (8aa42ed7c 2019-06-24) running on x86_64-unknown-linux-gnu

note: compiler flags: -C debuginfo=2 -C incremental -C linker=clang -C link-arg=-fuse-ld=lld --crate-type bin

note: some of the compiler flags provided by cargo are hidden

Code

use std::sync::mpsc;

pub enum Event {
    Rpc(JsonRpc),
}

pub enum Id {
    Str(String),
}

pub fn response<I: Into<Id>>(id: I) -> JsonRpc {
    JsonRpc::Response(Response {
        id: id.into(),
        method: "request".into(),
    })
}

struct Response {
    id: Id,
    method: String,
}

pub enum JsonRpc {
    Response(Response),
}

fn main() {
    let (tx, rx) = mpsc::channel();
    for evt in rx {
        match evt {
            Event::Rpc(JsonRpc::Response(ref resp)) if resp.method == "shutdown" => {}
            Event::Rpc(JsonRpc::Response(ref resp)) if resp.method == "request" => {
                tx.send(Event::Rpc(response(resp.id))).unwrap();
            }
            _ => (),
        };
    }
}

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=45bda3f34fa2a19e826f1e1be88711a7

Meta

rustc --version --verbose:

rustc 1.37.0-nightly (8aa42ed7c 2019-06-24)
binary: rustc
commit-hash: 8aa42ed7c2adb9f37faa6eb905f890f6199e1db9
commit-date: 2019-06-24
host: x86_64-unknown-linux-gnu
release: 1.37.0-nightly
LLVM version: 8.0

Backtrace:

thread 'rustc' panicked at 'assertion failed: self.bccx.region_scope_tree.scopes_intersect(old_loan.kill_scope,
                                             new_loan.kill_scope)', src/librustc_borrowck/borrowck/check_loans.rs:493:9
stack backtrace:
   0:     0x7f51a0b3b14b - backtrace::backtrace::libunwind::trace::h9099c158484abe51
                               at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.29/src/backtrace/libunwind.rs:88
   1:     0x7f51a0b3b14b - backtrace::backtrace::trace_unsynchronized::he4479cf789916be1
                               at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.29/src/backtrace/mod.rs:66
   2:     0x7f51a0b3b14b - std::sys_common::backtrace::_print::hfd97ddfcd581ce47
                               at src/libstd/sys_common/backtrace.rs:47
   3:     0x7f51a0b3b14b - std::sys_common::backtrace::print::h72fe9b1ac0779f0b
                               at src/libstd/sys_common/backtrace.rs:36
   4:     0x7f51a0b3b14b - std::panicking::default_hook::{{closure}}::hb2410098a9792a61
                               at src/libstd/panicking.rs:198
   5:     0x7f51a0b3ae27 - std::panicking::default_hook::he3b875f8eb532cbe
                               at src/libstd/panicking.rs:212
   6:     0x7f519e8248e1 - rustc::util::common::panic_hook::h4c77d6782bc64924
   7:     0x7f51a0b3b9a9 - std::panicking::rust_panic_with_hook::hb2c131403b9ff330
                               at src/libstd/panicking.rs:479
   8:     0x7f51a025ff45 - std::panicking::begin_panic::h48a8c740da159997
   9:     0x7f51a022f65d - rustc_borrowck::borrowck::check_loans::CheckLoanCtxt::report_error_if_loans_conflict::hbcb4607cfdf861b8
  10:     0x7f51a020f1be - rustc_borrowck::dataflow::DataFlowContext<O>::each_bit_on_entry::h1d18ec17e0a321d3
  11:     0x7f51a022ea40 - <rustc_borrowck::borrowck::check_loans::CheckLoanCtxt as rustc::middle::expr_use_visitor::Delegate>::borrow::h8dfd8b989effcd98
  12:     0x7f519e7f4c1a - rustc::middle::expr_use_visitor::ExprUseVisitor::borrow_expr::hed798c4f337e2b4a
  13:     0x7f519e7f6172 - rustc::middle::expr_use_visitor::ExprUseVisitor::walk_expr::h478289325f1f661d
  14:     0x7f519e7f4a5d - rustc::middle::expr_use_visitor::ExprUseVisitor::consume_expr::h7283293f253a7027
  15:     0x7f519e7f651d - rustc::middle::expr_use_visitor::ExprUseVisitor::walk_expr::h478289325f1f661d
  16:     0x7f519e7f4c2a - rustc::middle::expr_use_visitor::ExprUseVisitor::borrow_expr::hed798c4f337e2b4a
  17:     0x7f519e7f5e06 - rustc::middle::expr_use_visitor::ExprUseVisitor::walk_expr::h478289325f1f661d
  18:     0x7f519e7f4a5d - rustc::middle::expr_use_visitor::ExprUseVisitor::consume_expr::h7283293f253a7027
  19:     0x7f519e7f5579 - rustc::middle::expr_use_visitor::ExprUseVisitor::walk_expr::h478289325f1f661d
  20:     0x7f519e7f4a5d - rustc::middle::expr_use_visitor::ExprUseVisitor::consume_expr::h7283293f253a7027
  21:     0x7f519e7f5fd3 - rustc::middle::expr_use_visitor::ExprUseVisitor::walk_expr::h478289325f1f661d
  22:     0x7f519e7f4a5d - rustc::middle::expr_use_visitor::ExprUseVisitor::consume_expr::h7283293f253a7027
  23:     0x7f519e7f62f3 - rustc::middle::expr_use_visitor::ExprUseVisitor::walk_expr::h478289325f1f661d
  24:     0x7f519e7f4a5d - rustc::middle::expr_use_visitor::ExprUseVisitor::consume_expr::h7283293f253a7027
  25:     0x7f519e7f62f3 - rustc::middle::expr_use_visitor::ExprUseVisitor::walk_expr::h478289325f1f661d
  26:     0x7f519e7f4a5d - rustc::middle::expr_use_visitor::ExprUseVisitor::consume_expr::h7283293f253a7027
  27:     0x7f51a022f342 - rustc_borrowck::borrowck::check_loans::check_loans::h70d160e6225c3793
  28:     0x7f51a02364d2 - rustc_borrowck::borrowck::borrowck::hc11e557e6bcb2700
  29:     0x7f519fab0bd0 - rustc::ty::query::__query_compute::borrowck::hb326ee1e01ea2f5f
  30:     0x7f519fe2abed - rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::borrowck>::compute::h4dfd3020c39922c3
  31:     0x7f519fb62c9f - rustc::dep_graph::graph::DepGraph::with_task_impl::hf9138b4ba4a263ec
  32:     0x7f519feab41d - rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query::he7a81b2f25a24351
  33:     0x7f519fb7d72a - rustc_mir::borrow_check::do_mir_borrowck::h041182468ca0f2be
  34:     0x7f519feb685d - rustc::ty::context::GlobalCtxt::enter_local::hdb6c427c7c20906e
  35:     0x7f519fb7a60a - rustc_mir::borrow_check::mir_borrowck::h15870aaa4fd0f5e5
  36:     0x7f51a05b9c87 - rustc::ty::query::__query_compute::mir_borrowck::hab3ac695671a6c49
  37:     0x7f51a0579b05 - rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::mir_borrowck>::compute::h308bdadc41948ba3
  38:     0x7f51a05ac550 - rustc::dep_graph::graph::DepGraph::with_task_impl::hb82856897b911bf1
  39:     0x7f51a058469f - rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query::h4b21f0bb085eb07f
  40:     0x7f51a0579983 - rustc::ty::<impl rustc::ty::context::TyCtxt>::par_body_owners::hbc77efbf68d01392
  41:     0x7f51a054cdfe - rustc::util::common::time::h448867c0d110e11e
  42:     0x7f51a04fa742 - rustc_interface::passes::analysis::hffd7ed50e2787ccd
  43:     0x7f51a0e8fca6 - rustc::ty::query::__query_compute::analysis::h4f745f8b753a54a0
  44:     0x7f51a0ea165c - rustc::dep_graph::graph::DepGraph::with_task_impl::hae3d1d8b68983bb5
  45:     0x7f51a0e9c0ad - rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query::h849c974350419d2a
  46:     0x7f51a0e01256 - rustc::ty::context::tls::enter_global::h8e6320204fd477f6
  47:     0x7f51a0e229c7 - rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}::hd42b09eb1e70ba2e
  48:     0x7f51a05559fa - rustc_interface::passes::create_global_ctxt::{{closure}}::h57368add3655177a
  49:     0x7f51a0e23c28 - rustc_interface::interface::run_compiler_in_existing_thread_pool::h49a948c9a09e4fd5
  50:     0x7f51a0e3da22 - std::thread::local::LocalKey<T>::with::h56185318caee7c8e
  51:     0x7f51a0e2cca1 - scoped_tls::ScopedKey<T>::set::h0795a1620a3ca850
  52:     0x7f51a0e61e04 - syntax::with_globals::h226a9e65871d3e23
  53:     0x7f51a0e809dd - std::sys_common::backtrace::__rust_begin_short_backtrace::h65635ba31aa34691
  54:     0x7f51a0b4c40a - __rust_maybe_catch_panic
                               at src/libpanic_unwind/lib.rs:82
  55:     0x7f51a0e0a2e9 - core::ops::function::FnOnce::call_once{{vtable.shim}}::hd6ecffcd44130a12
  56:     0x7f51a0b1edff - <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once::h8d7c6883fcf13717
                               at /rustc/8aa42ed7c2adb9f37faa6eb905f890f6199e1db9/src/liballoc/boxed.rs:746
  57:     0x7f51a0b4b0f0 - <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once::h2cb8e7ed98d76ce7
                               at /rustc/8aa42ed7c2adb9f37faa6eb905f890f6199e1db9/src/liballoc/boxed.rs:746
  58:     0x7f51a0b4b0f0 - std::sys_common::thread::start_thread::h657d20c664378d90
                               at src/libstd/sys_common/thread.rs:13
  59:     0x7f51a0b4b0f0 - std::sys::unix::thread::Thread::new::thread_start::hf4dea44ba5680dfb
                               at src/libstd/sys/unix/thread.rs:79
  60:     0x7f51a0a6d57f - start_thread
  61:     0x7f51a098cf13 - __clone
  62:                0x0 - <unknown>
query stack during panic:
#0 [borrowck] processing `main`
#1 [mir_borrowck] processing `main`
#2 [analysis] running analysis passes on this crate
end of query stack
@Centril Centril added 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. I-nominated A-borrow-checker Area: The borrow checker labels Jun 25, 2019
@Centril
Copy link
Contributor

Centril commented Jun 25, 2019

Reduced:

struct Id {}
struct E { id: Id }
struct A {}

fn response(id: Id) -> E { E { id } }

fn send<'a>(_: &'a A, _: E) {}

fn foo() {
    let evt = E { id: Id {} };
    match evt {
        ref resp if true => {}
        ref resp if true => {
            let tx = A {};
            send(&tx, response(resp.id));
        }
        _ => (),
    }
}

cc @pnkfelix

@oli-obk oli-obk added regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. P-medium Medium priority P-high High priority and removed I-nominated P-medium Medium priority labels Jun 27, 2019
@pnkfelix pnkfelix self-assigned this Jun 27, 2019
@lqd
Copy link
Member

lqd commented Jun 28, 2019

Bisected this one to nightly-2019-05-24 and 85334c5, that is, PR #60174. cc @matthewjasper

@matthewjasper matthewjasper self-assigned this Jun 29, 2019
bors added a commit that referenced this issue Jul 9, 2019
Exit arm scopes

Due to a bug in the HIR CFG construction, borrows for arm scopes were incorrectly leaking into other arms.
This PR also includes some drive-by improvements to `-Zunpretty=hir,identified` that would have been helpful while investigating this.

Closes #62107
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-borrow-checker Area: The borrow checker I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. 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