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: mir_borrowck encountered mutable promoted #52671

Closed
cramertj opened this issue Jul 24, 2018 · 9 comments · Fixed by #52673 or #52834
Closed

ICE: mir_borrowck encountered mutable promoted #52671

cramertj opened this issue Jul 24, 2018 · 9 comments · Fixed by #52673 or #52834
Labels
A-NLL Area: Non Lexical Lifetimes (NLL) C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@cramertj
Copy link
Member

Error:

error: internal compiler error: librustc_mir/borrow_check/mod.rs:1868: encountered mutable promoted

thread 'main' panicked at 'Box<Any>', librustc_errors/lib.rs:580:9
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
   1: std::sys_common::backtrace::print
   2: std::panicking::default_hook::{{closure}}
   3: std::panicking::default_hook
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
   6: std::panicking::begin_panic
   7: rustc_errors::Handler::bug
   8: rustc::session::opt_span_bug_fmt::{{closure}}
   9: rustc::ty::context::tls::with_opt::{{closure}}
  10: rustc::ty::context::tls::with_context_opt
  11: rustc::ty::context::tls::with_opt
  12: rustc::session::opt_span_bug_fmt
  13: rustc::session::bug_fmt
  14: rustc_mir::borrow_check::MirBorrowckCtxt::is_mutable
  15: rustc_mir::borrow_check::MirBorrowckCtxt::access_place
  16: <rustc_mir::borrow_check::MirBorrowckCtxt<'cx, 'gcx, 'tcx> as rustc_mir::dataflow::DataflowResultsConsumer<'cx, 'tcx>>::visit_statement_entry
  17: rustc_mir::borrow_check::do_mir_borrowck
  18: rustc::ty::context::tls::with_related_context
  19: rustc::infer::InferCtxtBuilder::enter
  20: rustc_mir::borrow_check::mir_borrowck
  21: rustc::ty::query::__query_compute::mir_borrowck
  22: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::mir_borrowck<'tcx>>::compute
  23: rustc::dep_graph::graph::DepGraph::with_task_impl
  24: rustc::ty::context::tls::with_related_context
  25: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  26: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
  27: rustc::ty::query::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::mir_borrowck
  28: rustc::ty::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::par_body_owners
  29: rustc::util::common::time
  30: rustc::ty::context::tls::enter_context
  31: <std::thread::local::LocalKey<T>>::with
  32: rustc::ty::context::TyCtxt::create_and_enter
  33: rustc_driver::driver::compile_input
  34: rustc_driver::run_compiler_with_pool
  35: <scoped_tls::ScopedKey<T>>::set
  36: <scoped_tls::ScopedKey<T>>::set
  37: syntax::with_globals
  38: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
  39: __rust_maybe_catch_panic
  40: rustc_driver::run
  41: rustc_driver::main
  42: std::rt::lang_start::{{closure}}
  43: std::panicking::try::do_call
  44: __rust_maybe_catch_panic
  45: std::rt::lang_start_internal
  46: main
  47: __libc_start_main
  48: _start
query stack during panic:
#0 [mir_borrowck] processing `wire::util::buffer::tests::test_buffer_and_range_slice`
end of query stack
error: aborting due to previous error

For more information about this error, try `rustc --explain E0170`.

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.29.0-dev running on x86_64-unknown-linux-gnu

note: compiler flags: -C linker=/usr/local/google/home/cramertj/src/fuchsia/buildtools/linux-x64/clang/bin/clang -C link-arg=--target=x86_64-unknown-fuchsia -C link-arg=--sysroot=/usr/local/google/home/cramertj/src/fuchsia/out/release-x64/sdks/zircon_sysroot/arch/x64/sysroot -C opt-level=z -C lto=thin --crate-type bin


[5390/6330] ACTION //garnet/public/lib/fidl/rust/fidl:fidl_build(//build/toolchain/fuchsia:x64)
ninja: build stopped: subcommand failed.

This only happens after #52597 cc @oli-obk. The code that triggered this is here.

@oli-obk
Copy link
Contributor

oli-obk commented Jul 24, 2018

cc @nagisa seems like https://github.com/rust-lang/rust/pull/52597/files#diff-5b4d01d26caf43976125ba0f877e78c0R1856 we need to report an error instead of panicking as originally written

@oli-obk
Copy link
Contributor

oli-obk commented Jul 24, 2018

Oh it's probably because we do promote &mut []

@kennytm kennytm added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ A-borrow-checker Area: The borrow checker C-bug Category: This is a bug. A-NLL Area: Non Lexical Lifetimes (NLL) WG-compiler-nll and removed A-borrow-checker Area: The borrow checker labels Jul 24, 2018
@oli-obk
Copy link
Contributor

oli-obk commented Jul 24, 2018

created a fix in #52673, but I have no minimal repro and no time today

@cramertj
Copy link
Member Author

To clarify: you're making this an error? I don't see why we can't allow &mut [] to be promoted.

@oli-obk
Copy link
Contributor

oli-obk commented Jul 24, 2018

good point

@kennytm
Copy link
Member

kennytm commented Jul 24, 2018

This ICE is currently causing errors in the style-servo, regex and crates.io crates in https://perf.rust-lang.org/status.html.

@oli-obk
Copy link
Contributor

oli-obk commented Jul 25, 2018

I have tried building regex 0.1.80 and it does not reproduce the issue for me on master or nightly 😕

trying a stage2 build now

still can't repro on regex, but can repro on OPs file now.

#![feature(nll)]
fn main() {
    let y: &'static mut [u8; 0] = &mut [];
}

@oli-obk
Copy link
Contributor

oli-obk commented Jul 25, 2018

ok, fix exists now

bors added a commit that referenced this issue Jul 26, 2018
@Mark-Simulacrum
Copy link
Member

It looks like we've fixed the ICE here but there's still a change in behavior here, as well as a faulty diagnostic; this is while compiling cargo-registry from crates.io (at least the version in rustc-perf).

error[E0499]: cannot borrow `promoted` as mutable more than once at a time
  --> src/util/io_util.rs:45:47
   |
45 |         slice = &mut mem::replace(&mut slice, &mut [])[n..];
   |                                               ^^^^^^^ mutable borrow starts here in previous iteration of loop
   |
note: borrowed value must be valid for the anonymous lifetime #2 defined on the function body at 39:1...
  --> src/util/io_util.rs:39:1
   |
39 | / pub fn read_fill(r: &mut R, mut slice: &mut [u8]) -> io::Result<()> {
40 | |     while !slice.is_empty() {
41 | |         let n = r.read(slice)?;
42 | |         if n == 0 {
...  |
47 | |     Ok(())
48 | | }
   | |_^

error: aborting due to previous error

pietroalbini added a commit to pietroalbini/rust that referenced this issue Aug 1, 2018
…r=pnkfelix

[NLL] Allow conflicting borrows of promoted length zero arrays

This is currently overkill as there's no way to create two conflicting borrows of any promoted.
It is possible that the following code might not fail due to const eval in the future (@oli-obk?). In which case either the array marked needs to not be promoted, or to be checked for conflicts

```rust
static mut A: () = {
    let mut y = None;
    let z;
    let mut done_y = false;
    loop {
        let x = &mut [1];  // < this array
        if done_y {
            z = x;
            break;
        }
        y = Some(x);
        done_y = true;
    }
    some_const_fn(y, z); // some_const_fn expects that y to not alias z.
};
```

r? @pnkfelix  @nikomatsakis

closes rust-lang#52671
cc rust-lang#51823
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-NLL Area: Non Lexical Lifetimes (NLL) C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
4 participants