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 generators and NLL #55850

Closed
DutchGhost opened this issue Nov 10, 2018 · 0 comments · Fixed by #56460
Closed

ICE with generators and NLL #55850

DutchGhost opened this issue Nov 10, 2018 · 0 comments · Fixed by #56460
Assignees
Labels
A-coroutines Area: Coroutines A-NLL Area: Non-lexical lifetimes (NLL) I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ NLL-sound Working towards the "invalid code does not compile" goal

Comments

@DutchGhost
Copy link
Contributor

DutchGhost commented Nov 10, 2018

The following ICE's on nightly 2018:

#![feature(generators, generator_trait)]

use std::ops::Generator;
use std::ops::GeneratorState::Yielded;

pub struct GenIter<G>(G);

impl <G> Iterator for GenIter<G>
where
    G: Generator,
{
    type Item = G::Yield;
    
    fn next(&mut self) -> Option<Self::Item> {
        unsafe {
            match self.0.resume() {
                Yielded(y) => Some(y),
                _ => None
            }
        }
    }
}

fn bug<'a>() -> impl Iterator<Item = &'a str> {
    GenIter(move || {
        let mut s = String::new();
        yield &s[..]
    })
}

fn main() {
    bug();
}

This is an NLL issue, on 2015 nightly without NLL turned on, the compiler complains that s does not live long enough. with NLL turned on in 2015, I get the same ICE.

Backtrace:
error: internal compiler error: librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs:181: can't make a name for free region '_#2r
  --> src/main.rs:25:13
   |
25 |       GenIter(move || {
   |  _____________^
26 | |         let mut s = String::new();
27 | |         yield &s[..]
28 | |     })
   | |_____^

thread 'main' panicked at 'Box<Any>', librustc_errors/lib.rs:538:9
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::_print
             at libstd/sys_common/backtrace.rs:71
   2: std::panicking::default_hook::{{closure}}
             at libstd/sys_common/backtrace.rs:59
             at libstd/panicking.rs:211
   3: std::panicking::default_hook
             at libstd/panicking.rs:227
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
             at libstd/panicking.rs:480
   6: std::panicking::begin_panic
   7: rustc_errors::Handler::span_bug
   8: rustc::util::bug::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::util::bug::opt_span_bug_fmt
  13: rustc::util::bug::span_bug_fmt
  14: rustc_mir::borrow_check::nll::region_infer::error_reporting::region_name::<impl rustc_mir::borrow_check::nll::region_infer::RegionInferenceContext<'tcx>>::give_region_a_name
  15: rustc_mir::borrow_check::nll::region_infer::error_reporting::<impl rustc_mir::borrow_check::nll::region_infer::RegionInferenceContext<'tcx>>::free_region_constraint_info
  16: rustc_mir::borrow_check::nll::explain_borrow::<impl rustc_mir::borrow_check::MirBorrowckCtxt<'cx, 'gcx, 'tcx>>::explain_why_borrow_contains_point
  17: rustc_mir::borrow_check::error_reporting::<impl rustc_mir::borrow_check::MirBorrowckCtxt<'cx, 'gcx, 'tcx>>::report_borrowed_value_does_not_live_long_enough
  18: rustc_mir::borrow_check::path_utils::each_borrow_involving_path
  19: rustc_mir::borrow_check::MirBorrowckCtxt::access_place
  20: <rustc_mir::borrow_check::MirBorrowckCtxt<'cx, 'gcx, 'tcx> as rustc_mir::dataflow::DataflowResultsConsumer<'cx, 'tcx>>::visit_terminator_entry
  21: rustc_mir::borrow_check::do_mir_borrowck
  22: rustc::ty::context::tls::with_related_context
  23: rustc::infer::InferCtxtBuilder::enter
  24: rustc_mir::borrow_check::mir_borrowck
  25: rustc::ty::query::__query_compute::mir_borrowck
  26: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::mir_borrowck<'tcx>>::compute
  27: rustc::dep_graph::graph::DepGraph::with_task_impl
  28: rustc::ty::context::tls::with_related_context
  29: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  30: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
  31: rustc::ty::query::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::mir_borrowck
  32: rustc_mir::borrow_check::nll::type_check::TypeChecker::check_stmt
  33: rustc_mir::borrow_check::nll::type_check::TypeChecker::typeck_mir
  34: rustc_mir::borrow_check::nll::type_check::type_check
  35: rustc_mir::borrow_check::do_mir_borrowck
  36: rustc::ty::context::tls::with_related_context
  37: rustc::infer::InferCtxtBuilder::enter
  38: rustc_mir::borrow_check::mir_borrowck
  39: rustc::ty::query::__query_compute::mir_borrowck
  40: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::mir_borrowck<'tcx>>::compute
  41: rustc::dep_graph::graph::DepGraph::with_task_impl
  42: rustc::ty::context::tls::with_related_context
  43: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  44: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
  45: rustc::ty::query::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::mir_borrowck
  46: rustc::ty::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::par_body_owners
  47: rustc::util::common::time
  48: rustc::ty::context::tls::enter_context
  49: <std::thread::local::LocalKey<T>>::with
  50: rustc::ty::context::TyCtxt::create_and_enter
  51: rustc_driver::driver::compile_input
  52: rustc_driver::run_compiler_with_pool
  53: <scoped_tls::ScopedKey<T>>::set
  54: rustc_driver::run_compiler
  55: syntax::with_globals
  56: __rust_maybe_catch_panic
             at libpanic_unwind/lib.rs:102
  57: rustc_driver::run
  58: rustc_driver::main
  59: std::rt::lang_start::{{closure}}
  60: std::panicking::try::do_call
             at libstd/rt.rs:59
             at libstd/panicking.rs:310
  61: __rust_maybe_catch_panic
             at libpanic_unwind/lib.rs:102
  62: std::rt::lang_start_internal
             at libstd/panicking.rs:289
             at libstd/panic.rs:398
             at libstd/rt.rs:58
  63: main
  64: __libc_start_main
  65: <unknown>
query stack during panic:
#0 [mir_borrowck] processing `bug::{{closure}}`
#1 [mir_borrowck] processing `bug`
end of query stack
error: aborting due to previous error


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.32.0-nightly (36a50c29f 2018-11-09) running on x86_64-unknown-linux-gnu

note: compiler flags: -C opt-level=3 -C codegen-units=1 --crate-type bin

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

error: Could not compile `playground`.

To learn more, run the command again with --verbose.
@DutchGhost DutchGhost changed the title ICE with generators ICE with generators and NLL Nov 10, 2018
@zackmdavis zackmdavis added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Nov 10, 2018
@davidtwco davidtwco added the A-NLL Area: Non-lexical lifetimes (NLL) label Nov 30, 2018
@davidtwco davidtwco self-assigned this Nov 30, 2018
@Zoxc Zoxc added the A-coroutines Area: Coroutines label Dec 4, 2018
@pnkfelix pnkfelix added the NLL-sound Working towards the "invalid code does not compile" goal label Dec 4, 2018
pietroalbini added a commit to pietroalbini/rust that referenced this issue Dec 5, 2018
Fix ICE with generators and NLL

Fix rust-lang#55850.

This PR stops an ICE in rust-lang#55850 by not panicking when a region cannot be named. However, this PR does not (yet) fix the underlying issue that the correct name for the test case provided for the issue (in this instance, `'a`) was not found.

This PR also lays a little bit of groundwork by categorizing yields separately from returns so that region naming can be specialized for this case.

r? @pnkfelix
bors added a commit that referenced this issue Dec 7, 2018
Fix ICE with generators and NLL

Fix #55850.

This PR stops an ICE in #55850 by not panicking when a region cannot be named. However, this PR does not (yet) fix the underlying issue that the correct name for the test case provided for the issue (in this instance, `'a`) was not found.

This PR also lays a little bit of groundwork by categorizing yields separately from returns so that region naming can be specialized for this case.

r? @pnkfelix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-coroutines Area: Coroutines A-NLL Area: Non-lexical lifetimes (NLL) I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ NLL-sound Working towards the "invalid code does not compile" goal
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants