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: unexpected concrete region in borrowck: ReEarlyBound(0, 'a) #83190

Closed
Tracked by #87749
matthiaskrgr opened this issue Mar 16, 2021 · 15 comments · Fixed by #85755, #88533 or #88565
Closed
Tracked by #87749

ICE: unexpected concrete region in borrowck: ReEarlyBound(0, 'a) #83190

matthiaskrgr opened this issue Mar 16, 2021 · 15 comments · Fixed by #85755, #88533 or #88565
Assignees
Labels
C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ ICEBreaker-Cleanup-Crew Helping to "clean up" bugs with minimal examples and bisections regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Milestone

Comments

@matthiaskrgr
Copy link
Member

Code

code is from ./src/test/ui/type-alias-impl-trait/associated-type-lifetime-ice.rs

// failure-status: 101
// rustc-env:RUST_BACKTRACE=0
// normalize-stderr-test "note: .*\n\n" -> ""
// normalize-stderr-test "thread 'rustc' panicked.*\n" -> ""

// compile-flags: --crate-type=rlib

// Regression test for https://github.com/rust-lang/rust/issues/78450

#![feature(min_type_alias_impl_trait)]
#![no_std]

pub trait AssociatedImpl {
    type ImplTrait;

    fn f() -> Self::ImplTrait;
}

struct S<T>(T);

trait Associated {
    type A;
}

// ICE
impl<'a, T: Associated<A = &'a ()>> AssociatedImpl for S<T> {
    type ImplTrait = impl core::fmt::Debug;

    fn f() -> Self::ImplTrait {
    //~^ ERROR unexpected concrete region in borrowck: ReEarlyBound(0, 'a)
        ()
    }
}

Meta

searched toolchains f98721f886ab52d32d622ad0a46216ad03f3e525 through 195ad4830e11a544391abe296b146450dea8411b
installing 195ad4830e11a544391abe296b146450dea8411b
cargo for x86_64-unknown-linux-gnu: 5.96 MB / 5.96 MB [=================================================================================] 100.00 % 1.50 MB/s testing...
uninstalling 195ad4830e11a544391abe296b146450dea8411b


********************************************************************************
Regression in 195ad4830e11a544391abe296b146450dea8411b
********************************************************************************

Seems to have been introduced by #82898 / 195ad48
cc @oli-obk ?

Error output

error: internal compiler error: unexpected concrete region in borrowck: ReEarlyBound(0, 'a)
  --> ./src/test/ui/type-alias-impl-trait/associated-type-lifetime-ice.rs:29:5
   |
29 | /     fn f() -> Self::ImplTrait {
30 | |     //~^ ERROR unexpected concrete region in borrowck: ReEarlyBound(0, 'a)
31 | |         ()
32 | |     }
   | |_____^
   |
   = note: delayed at compiler/rustc_mir/src/borrow_check/region_infer/opaque_types.rs:83:44

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', compiler/rustc_errors/src/lib.rs:1012:13
note: run with `RUST_BACKTRACE=1` environment variable to display a 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/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.52.0-nightly (195ad4830 2021-03-16) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type lib

query stack during panic:
end of query stack
Backtrace

error: internal compiler error: unexpected concrete region in borrowck: ReEarlyBound(0, 'a)
  --> ./src/test/ui/type-alias-impl-trait/associated-type-lifetime-ice.rs:29:5
   |
29 | /     fn f() -> Self::ImplTrait {
30 | |     //~^ ERROR unexpected concrete region in borrowck: ReEarlyBound(0, 'a)
31 | |         ()
32 | |     }
   | |_____^
   |
   = note: delayed at compiler/rustc_mir/src/borrow_check/region_infer/opaque_types.rs:83:44

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', compiler/rustc_errors/src/lib.rs:1012:13
stack backtrace:
   0:     0x7fc856475a10 - std::backtrace_rs::backtrace::libunwind::trace::hfe3b1cace85e87d8
                               at /rustc/195ad4830e11a544391abe296b146450dea8411b/library/std/src/../../backtrace/src/backtrace/libunwind.rs:90:5
   1:     0x7fc856475a10 - std::backtrace_rs::backtrace::trace_unsynchronized::h542330af06479043
                               at /rustc/195ad4830e11a544391abe296b146450dea8411b/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7fc856475a10 - std::sys_common::backtrace::_print_fmt::h6b88726367858985
                               at /rustc/195ad4830e11a544391abe296b146450dea8411b/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x7fc856475a10 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hcd76ce6b485adbea
                               at /rustc/195ad4830e11a544391abe296b146450dea8411b/library/std/src/sys_common/backtrace.rs:46:22
   4:     0x7fc8564e3f8f - core::fmt::write::h127419eb46f2ecc9
                               at /rustc/195ad4830e11a544391abe296b146450dea8411b/library/core/src/fmt/mod.rs:1092:17
   5:     0x7fc856469b22 - std::io::Write::write_fmt::h0facb64ef2e7f5d8
                               at /rustc/195ad4830e11a544391abe296b146450dea8411b/library/std/src/io/mod.rs:1567:15
   6:     0x7fc856479745 - std::sys_common::backtrace::_print::h7bf1633ea5421f7b
                               at /rustc/195ad4830e11a544391abe296b146450dea8411b/library/std/src/sys_common/backtrace.rs:49:5
   7:     0x7fc856479745 - std::sys_common::backtrace::print::h5cc4d09049928ba5
                               at /rustc/195ad4830e11a544391abe296b146450dea8411b/library/std/src/sys_common/backtrace.rs:36:9
   8:     0x7fc856479745 - std::panicking::default_hook::{{closure}}::h9e84dc005bfc9fc7
                               at /rustc/195ad4830e11a544391abe296b146450dea8411b/library/std/src/panicking.rs:208:50
   9:     0x7fc8564791f3 - std::panicking::default_hook::h123278a03b1f796b
                               at /rustc/195ad4830e11a544391abe296b146450dea8411b/library/std/src/panicking.rs:225:9
  10:     0x7fc856c4c9fb - rustc_driver::report_ice::h0dd0a80bb463fc7e
  11:     0x7fc856479eb0 - std::panicking::rust_panic_with_hook::h4040631aa6c7bc27
                               at /rustc/195ad4830e11a544391abe296b146450dea8411b/library/std/src/panicking.rs:595:17
  12:     0x7fc856479a27 - std::panicking::begin_panic_handler::{{closure}}::h02a17b22ac092d08
                               at /rustc/195ad4830e11a544391abe296b146450dea8411b/library/std/src/panicking.rs:497:13
  13:     0x7fc856475ecc - std::sys_common::backtrace::__rust_end_short_backtrace::h6063b024443b5852
                               at /rustc/195ad4830e11a544391abe296b146450dea8411b/library/std/src/sys_common/backtrace.rs:141:18
  14:     0x7fc856479989 - rust_begin_unwind
                               at /rustc/195ad4830e11a544391abe296b146450dea8411b/library/std/src/panicking.rs:493:5
  15:     0x7fc85643e14b - std::panicking::begin_panic_fmt::h10b51f96d6207ff1
                               at /rustc/195ad4830e11a544391abe296b146450dea8411b/library/std/src/panicking.rs:435:5
  16:     0x7fc85936c92e - rustc_errors::HandlerInner::flush_delayed::h7cdd6b7640e6949e
  17:     0x7fc85936b23b - <rustc_errors::HandlerInner as core::ops::drop::Drop>::drop::h1ea17cd328582115
  18:     0x7fc858998d56 - core::ptr::drop_in_place<rustc_session::parse::ParseSess>::hc4ec048ba9ccb468
  19:     0x7fc85899b320 - <alloc::rc::Rc<T> as core::ops::drop::Drop>::drop::h38e1b78997ab5d18
  20:     0x7fc858997f3d - core::ptr::drop_in_place<rustc_interface::interface::Compiler>::ha1358694e6ae6d6a
  21:     0x7fc8589977aa - rustc_span::with_source_map::h19c02e2b8cd97d79
  22:     0x7fc85899c856 - scoped_tls::ScopedKey<T>::set::ha910f4dd75d3f2b6
  23:     0x7fc85899e084 - std::sys_common::backtrace::__rust_begin_short_backtrace::h9028e0cefdffcecf
  24:     0x7fc8589b91e5 - core::ops::function::FnOnce::call_once{{vtable.shim}}::h88ad06dc90d5e88d
  25:     0x7fc856489728 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hd8ea7ada17dfa868
                               at /rustc/195ad4830e11a544391abe296b146450dea8411b/library/alloc/src/boxed.rs:1546:9
  26:     0x7fc856489728 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h91ce3a636c58b978
                               at /rustc/195ad4830e11a544391abe296b146450dea8411b/library/alloc/src/boxed.rs:1546:9
  27:     0x7fc856489728 - std::sys::unix::thread::Thread::new::thread_start::h2e193c2e23720fdf
                               at /rustc/195ad4830e11a544391abe296b146450dea8411b/library/std/src/sys/unix/thread.rs:71:17
  28:     0x7fc856392299 - start_thread
  29:     0x7fc8562a7053 - clone
  30:                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/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.52.0-nightly (195ad4830 2021-03-16) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type lib

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 Mar 16, 2021
@oli-obk
Copy link
Contributor

oli-obk commented Mar 16, 2021

Yes, this is a newly added test that I wanted to add as a test that will pass when that issue is fixed.

@oli-obk
Copy link
Contributor

oli-obk commented Mar 16, 2021

cc @matthewjasper

you added this delay_span_bug, but from the PR and the documentation on the function I can't tell what the correct way forward is. I presume this was built without type-alias-impl-trait in mind, as now lifetimes from the surrounding impl block can end up in the opaque type. The specific code emitting the delay span bug is

https://github.com/rust-lang/rust/blob/master/compiler/rustc_mir/src/borrow_check/region_infer/opaque_types.rs#L82-L87

I don't know enough about lifetime inference to judge how to proceed (removing the delay span bug makes the test pass, but... that doesn't sound like a good approach for something this subtle)

@spastorino
Copy link
Member

After a discussion with Niko about this and assigning to myself we saw that there's already a PR. Unassigning myself then :).

@palfrey
Copy link
Contributor

palfrey commented Aug 8, 2021

Just saw this in https://github.com/palfrey/bioyino/runs/3273000488?check_suite_focus=true with rustc 1.56.0-nightly (574d37568 2021-08-07)

@tmandry
Copy link
Member

tmandry commented Aug 12, 2021

Also seen in crater for bioyino, cc #87749

@rustbot label regression-from-stable-to-beta

@rustbot rustbot added regression-from-stable-to-beta Performance or correctness regression from stable to beta. I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Aug 12, 2021
@apiraino
Copy link
Contributor

apiraino commented Aug 13, 2021

Perhaps related also to #87455? In that issue a comment mentions a backport for #87483 could fix that one.

@tmandry tmandry mentioned this issue Aug 19, 2021
7 tasks
@apiraino
Copy link
Contributor

Assigning priority as discussed in the Zulip thread of the Prioritization Working Group.

@rustbot label -I-prioritize +P-high

@rustbot rustbot added P-high High priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Aug 19, 2021
@Mark-Simulacrum Mark-Simulacrum added this to the 1.55.0 milestone Aug 27, 2021
@spastorino
Copy link
Member

As noted on PR #88533 we need a reduction of the ICEing example from bioyino-metric.

@rustbot ping cleanup-crew

@rustbot rustbot added the ICEBreaker-Cleanup-Crew Helping to "clean up" bugs with minimal examples and bisections label Aug 31, 2021
@rustbot
Copy link
Collaborator

rustbot commented Aug 31, 2021

@hellow554
Copy link
Contributor

hellow554 commented Aug 31, 2021

This is my current MCVE:

use combine::parser::range::take_while1;
use combine::stream::RangeStream;
use combine::{choice, Parser, StreamOnce};

pub fn metric_stream_parser<'a, I, F>(
) -> impl Parser<I, Output = (), PartialState = impl Default + 'a>
where
    I: 'a + StreamOnce<Token = u8, Range = &'a [u8], Position = usize> + RangeStream,
{
    let val = take_while1(|_: u8| false);
    let sampling = take_while1(|_: u8| false);
    let metric = (val, choice((sampling,))).map(|_| todo!());

    choice(((metric).map(|_: F| ()),))
}

combine is 4.0

try to reduce it further later or tomorrow (:

@spastorino
Copy link
Member

@hellow554 great if you come up with a standalone repro, please open a PR and feel free to assign it to me.

@lqd
Copy link
Member

lqd commented Aug 31, 2021

combine is super tough to reduce, so here's what I have (playground):

use std::marker::PhantomData;
pub trait StreamError: Sized {}
pub trait ParseError: Sized + PartialEq {
    type StreamError: StreamError;
}
pub trait StreamOnce {
    type Token: Clone;
    type Range: Clone;
    type Error: ParseError;
}
pub trait Stream: StreamOnce {}
pub struct Map<P, F>(P, F);
impl<Input, A, B, P, F> Parser<Input> for Map<P, F>
where
    Input: Stream,
    P: Parser<Input, Output = A>,
    F: FnMut(A) -> B,
{
    type Output = B;
    type PartialState = P::PartialState;
}
struct TakeWhile1<Input, F>(F, PhantomData<fn(Input) -> Input>);
impl<Input, F> Parser<Input> for TakeWhile1<Input, F>
where
    Input: Stream,
    F: FnMut(Input::Token) -> bool,
{
    type Output = Input::Range;
    type PartialState = usize;
}
fn take_while1<Input, F>(_f: F) -> TakeWhile1<Input, F>
where
    Input: Stream,
    F: FnMut(Input::Token) -> bool,
{
    unimplemented!()
}
pub struct SequenceState<T, U>(PhantomData<(T, U)>);
impl<T, U: Default> Default for SequenceState<T, U> {
    fn default() -> Self {
        unimplemented!()
    }
}
#[derive(Default)]
pub struct PartialState1<A> {
    _marker: PhantomData<(A,)>,
}
impl<Input: Stream, A> Parser<Input> for (A,)
where
    Input: Stream,
    Input::Error: ParseError,
    A: Parser<Input>,
{
    type Output = (A::Output,);
    type PartialState = PartialState1<SequenceState<A::Output, A::PartialState>>;
}
pub trait Parser<Input: Stream> {
    type Output;
    type PartialState: Default;
    fn map<F, B>(self, _f: F) -> Map<Self, F>
    where
        Self: Sized,
        F: FnMut(Self::Output) -> B,
    {
        unimplemented!()
    }
}
pub fn metric_stream_parser<'a, I>() -> impl Parser<I, Output = (), PartialState = impl Default + 'a>
where
    I: 'a + StreamOnce<Token = u8, Range = &'a [u8]> + Stream,
{
    let val = take_while1(|_: u8| false);
    let metric = (val,).map(|_| todo!());
    metric
}

@bors bors closed this as completed in a395610 Sep 1, 2021
@hellow554
Copy link
Contributor

Sub 50 lines, almost there:

pub trait Any {}
impl<T> Any for T {}

pub trait StreamOnce {
    type Range;
}

pub trait Parser<Input>: Sized {
    type Output;
    type PartialState;
    fn map(self) -> Map<Self> {
        todo!()
    }
}

pub struct Map<P>(P);
impl<I, P: Parser<I, Output = ()>> Parser<I> for Map<P> {
    type Output = ();
    type PartialState = P::PartialState;
}

struct TakeWhile1<Input>(Input);
impl<I: StreamOnce> Parser<I> for TakeWhile1<I> {
    type Output = I::Range;
    type PartialState = ();
}
impl<I> TakeWhile1<I> {
    fn new() -> Self {
        todo!()
    }
}

impl<I, A: Parser<I>> Parser<I> for (A,) {
    type Output = ();
    type PartialState = Map<A::Output>;
}

pub fn metric_stream_parser<'a, I>() -> impl Parser<I, Output = (), PartialState = impl Any + 'a>
where
    I: StreamOnce<Range = &'a [()]>,
{
    (TakeWhile1::new(),).map()
}

fn main() {}

@oli-obk oli-obk reopened this Sep 1, 2021
@oli-obk oli-obk added E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. and removed P-high High priority labels Sep 1, 2021
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Sep 1, 2021
Add regression test for issue 83190

Reduced from `bioyino-metric` by `@hellow554` and myself.

Closes rust-lang#83190.

r? `@spastorino`
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Sep 1, 2021
Add regression test for issue 83190

Reduced from `bioyino-metric` by ``@hellow554`` and myself.

Closes rust-lang#83190.

r? ``@spastorino``
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Sep 2, 2021
Add regression test for issue 83190

Reduced from `bioyino-metric` by ```@hellow554``` and myself.

Closes rust-lang#83190.

r? ```@spastorino```
@bors bors closed this as completed in e248c4d Sep 2, 2021
@camelid
Copy link
Member

camelid commented Sep 2, 2021

Should this be reopened to track beta backport or has it already been backported?

bors added a commit to rust-lang-ci/rust that referenced this issue Sep 4, 2021
…ulacrum

[beta] backports

This PR backports:

* Concrete regions can show up in mir borrowck if the originated from there rust-lang#88533 (fixes rust-lang#83190)
* Fix loading large rlibs rust-lang#88506 (fixes rust-lang#88351)
* Display associated types of implementors rust-lang#88490 (fixes rust-lang#86631)
* Tracking issue for UNSUPPORTED_CALLING_CONVENTIONS rust-lang#88397

r? `@Mark-Simulacrum`
@Mark-Simulacrum
Copy link
Member

Closing - backported in #88641

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ ICEBreaker-Cleanup-Crew Helping to "clean up" bugs with minimal examples and bisections regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.