Skip to content

ICE: cannot convert RePlaceholder to a region vid #76168

New issue

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

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

Already on GitHub? # to your account

Closed
ririsoft opened this issue Aug 31, 2020 · 8 comments · Fixed by #91321
Closed

ICE: cannot convert RePlaceholder to a region vid #76168

ririsoft opened this issue Aug 31, 2020 · 8 comments · Fixed by #91321
Labels
A-async-await Area: Async & Await A-borrow-checker Area: The borrow checker A-closures Area: Closures (`|…| { … }`) AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. 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) ❄️ P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@ririsoft
Copy link

ririsoft commented Aug 31, 2020

Hello,

I am getting an ICE while "playing" with unboxed_closure

Code

MCVE can be found here: #76168 (comment)

Original
#![feature(unboxed_closures)]
use futures::executor::block_on;
use std::future::Future;

async fn walk<F>(mut filter: F)
where
    for<'a> F: FnMut<(&'a u32,)> + 'a,
    for<'a> <F as FnOnce<(&'a u32,)>>::Output: Future<Output = bool> + 'a,
{
    let res = filter(&5u32).await;
    println!("res: {}", res);
}

fn main() {
    block_on(async { walk(|&i| async move { true }).await });
}

Meta

rustc --version --verbose: (from Playground)

rustc 1.48.0-nightly (d006f5734 2020-08-28) running on x86_64-unknown-linux-gnu

Error output

error: internal compiler error: src/librustc_mir/borrow_check/universal_regions.rs:768:36: cannot convert `RePlaceholder(Placeholder { universe: U5, name: BrNamed(DefId(0:8 ~ playground[a09e]::walk[0]::'a[1]), 'a) })` to a region vid

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:918:9
Backtrace

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:918:9
stack backtrace:
   0: std::panicking::begin_panic
   1: rustc_errors::HandlerInner::bug
   2: rustc_errors::Handler::bug
   3: rustc_middle::util::bug::opt_span_bug_fmt::{{closure}}
   4: rustc_middle::ty::context::tls::with_opt::{{closure}}
   5: rustc_middle::ty::context::tls::with_opt
   6: rustc_middle::util::bug::opt_span_bug_fmt
   7: rustc_middle::util::bug::bug_fmt
   8: rustc_mir::borrow_check::universal_regions::UniversalRegionIndices::to_region_vid::{{closure}}
   9: rustc_mir::borrow_check::universal_regions::UniversalRegionIndices::to_region_vid
  10: rustc_mir::borrow_check::region_infer::RegionInferenceContext::eval_verify_bound
  11: rustc_mir::borrow_check::region_infer::RegionInferenceContext::eval_verify_bound
  12: rustc_mir::borrow_check::region_infer::RegionInferenceContext::solve
  13: rustc_mir::borrow_check::nll::compute_regions
  14: rustc_mir::borrow_check::do_mir_borrowck
  15: rustc_infer::infer::InferCtxtBuilder::enter
  16: rustc_mir::borrow_check::mir_borrowck
  17: core::ops::function::FnOnce::call_once
  18: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::mir_borrowck>::compute
  19: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  20: rustc_data_structures::stack::ensure_sufficient_stack
  21: rustc_query_system::query::plumbing::get_query_impl
  22: rustc_typeck::collect::type_of::type_of
  23: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  24: rustc_data_structures::stack::ensure_sufficient_stack
  25: rustc_query_system::query::plumbing::get_query_impl
  26: rustc_middle::ty::util::OpaqueTypeExpander::expand_opaque_ty
  27: rustc_middle::ty::util::<impl rustc_middle::ty::context::TyCtxt>::try_expand_impl_trait_type
  28: rustc_typeck::check::check_item_type
  29: rustc_middle::hir::map::Map::visit_item_likes_in_module
  30: rustc_typeck::check::check_mod_item_types
  31: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::check_mod_item_types>::compute
  32: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  33: rustc_data_structures::stack::ensure_sufficient_stack
  34: rustc_query_system::query::plumbing::get_query_impl
  35: rustc_query_system::query::plumbing::ensure_query_impl
  36: rustc_session::utils::<impl rustc_session::session::Session>::time
  37: rustc_typeck::check_crate
  38: rustc_interface::passes::analysis
  39: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::analysis>::compute
  40: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  41: rustc_data_structures::stack::ensure_sufficient_stack
  42: rustc_query_system::query::plumbing::get_query_impl
  43: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  44: rustc_span::with_source_map
  45: rustc_interface::interface::create_compiler_and_run
  46: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

@ririsoft ririsoft 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 Aug 31, 2020
@ririsoft
Copy link
Author

A project maintainer might want to add the F-unboxed_closures label.

@SNCPlay42
Copy link
Contributor

Reduced, no nightly features:

trait Trait<Input> {
    type Output;
}

async fn walk<F>(filter: F)
where
    for<'a> F: Trait<&'a u32> + 'a,
    for<'a> <F as Trait<&'a u32>>::Output: 'a,
{
}

Output on stable:

error[E0310]: the parameter type `F` may not live long enough
  --> src/lib.rs:9:1
   |
9  | / {
10 | | }
   | |_^
   |
   = help: consider adding an explicit lifetime bound `F: 'static`...

error: aborting due to previous error

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

ICEs on beta and nightly.

@SNCPlay42
Copy link
Contributor

SNCPlay42 commented Aug 31, 2020

Adding a F: 'static bound as suggested gives this ICE on stable:

warning: unused variable: `filter`
 --> src/lib.rs:5:27
  |
5 | async fn walk<F: 'static>(filter: F)
  |                           ^^^^^^ help: if this is intentional, prefix it with an underscore: `_filter`
  |
  = note: `#[warn(unused_variables)]` on by default

warning: function is never used: `walk`
 --> src/lib.rs:5:10
  |
5 | async fn walk<F: 'static>(filter: F)
  |          ^^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: 2 warnings emitted

error: internal compiler error: broken MIR in DefId(0:6 ~ playground[caf5]::walk[0]) (NoSolution): could not prove Binder(OutlivesPredicate(<F as Trait<&'a u32>>::Output, ReLateBound(DebruijnIndex(0), BrNamed(DefId(0:9 ~ playground[caf5]::walk[0]::'a[1]), 'a))))
  --> src/lib.rs:9:1
   |
9  | / {
10 | | }
   | |_^
   |
   = note: delayed at src/librustc_mir/borrow_check/type_check/mod.rs:258:27
Backtrace
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 /cargo/registry/src/github.heygears.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/libunwind.rs:86
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.heygears.com-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: rustc_driver::report_ice
  11: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:530
  12: std::panicking::begin_panic
  13: <rustc_errors::HandlerInner as core::ops::drop::Drop>::drop
  14: core::ptr::drop_in_place
  15: <alloc::rc::Rc<T> as core::ops::drop::Drop>::drop
  16: core::ptr::drop_in_place
  17: rustc_span::with_source_map
  18: rustc_interface::interface::create_compiler_and_run
  19: scoped_tls::ScopedKey<T>::set
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 (04488afe3 2020-08-24) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2 --crate-type lib

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

query stack during panic:
end of query stack

Which looks like #71546. It still gives the original ICE on beta and stable, and it looks like #71546's code now produces the original ICE of this issue on beta and stable.

Does that make this a duplicate?

@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Sep 8, 2020
@estebank estebank added A-async-await Area: Async & Await A-closures Area: Closures (`|…| { … }`) F-unboxed_closures `#![feature(unboxed_closures)]` requires-nightly This issue requires a nightly compiler in some way. labels Nov 17, 2020
@estebank
Copy link
Contributor

Another repro case relying on tokio:

#![feature(unboxed_closures)]

async fn wrapper<F>(f: F) 
where for<'a> F: FnOnce<(&'a mut i32,)>,
    for<'a> <F as FnOnce<(&'a mut i32,)>>::Output: Future<Output=()> + 'a
{
    let mut i = 41;
    f(&mut i).await;
}

async fn add_one(i: &mut i32) {
    *i = *i + 1;
}

@SNCPlay42
Copy link
Contributor

@rustbot modify labels: -F-unboxed_closures -requires-nightly

per #76168 (comment)

@rustbot rustbot removed F-unboxed_closures `#![feature(unboxed_closures)]` requires-nightly This issue requires a nightly compiler in some way. labels Nov 17, 2020
@tmandry tmandry added the regression-from-stable-to-stable Performance or correctness regression from one stable version to another. label Nov 19, 2020
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Nov 19, 2020
@tmandry tmandry added the A-borrow-checker Area: The borrow checker label Nov 19, 2020
@tmandry
Copy link
Member

tmandry commented Nov 19, 2020

This is now reproducing on stable. This feels like more of a "guts of the borrow checker" kind of issue than async/await-specific, so I'm tagging with A-borrow-checker.

@tmandry tmandry added the AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. label Nov 19, 2020
@spastorino
Copy link
Member

Assigning P-high as discussed as part of the Prioritization Working Group procedure and removing I-prioritize.

@spastorino spastorino added P-high High priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Nov 25, 2020
@estebank
Copy link
Contributor

Another repro from #81273:

#![feature(unboxed_closures)]

use std::future::Future;

use futures::future::LocalBoxFuture;


pub trait GenericTask<C>: 'static {
    fn execute<'a>(&'a self, ctx: &'a C) -> LocalBoxFuture<'a, ()>;
}

impl<C: 'static, T: 'static> GenericTask<C> for T
where
    T: for<'a> Fn<(&'a C, )>,
    for<'a> <T as FnOnce<(&'a C, )>>::Output: Future<Output = ()> + 'a,
{
    fn execute<'a>(&'a self, ctx: &'a C) -> LocalBoxFuture<'a, ()> {
        let future = (self)(ctx);

        Box::pin(async move {
            future.await;
        })
    }
}

@JohnTitor JohnTitor changed the title ICE: cannot convert `RePlaceholder to a region vid ICE: cannot convert RePlaceholder to a region vid Jun 24, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-async-await Area: Async & Await A-borrow-checker Area: The borrow checker A-closures Area: Closures (`|…| { … }`) AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. 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) ❄️ P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

7 participants