Skip to content

ICE when yield is used as an argument to println! #69017

Closed
@Patryk27

Description

@Patryk27
Contributor

Hi,

#![feature(generator_trait)]
#![feature(generators)]

use std::ops::Generator;

fn gen() -> impl Generator<usize> {
    |_: usize| {
        println!("-> {}", yield);
    }
}

playground link

ICEs, on today's nightly, with:

error: internal compiler error: src/librustc_mir/transform/promote_consts.rs:467: _1 = suspend(move _21) -> [resume: bb2, drop: bb3] not promotable
 --> src/lib.rs:8:27
  |
8 |         println!("-> {}", yield);
  |                           ^^^^^
backtrace
thread 'rustc' panicked at 'Box<Any>', <::std::macros::panic macros>:2:4
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.tiyicn.workers.dev-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/libunwind.rs:88
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.tiyicn.workers.dev-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:77
   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:1052
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1428
   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:204
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:224
  10: rustc_driver::report_ice
  11: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:474
  12: std::panicking::begin_panic
  13: rustc_errors::HandlerInner::span_bug
  14: rustc_errors::Handler::span_bug
  15: rustc::util::bug::opt_span_bug_fmt::{{closure}}
  16: rustc::ty::context::tls::with_opt::{{closure}}
  17: rustc::ty::context::tls::with_opt
  18: rustc::util::bug::opt_span_bug_fmt
  19: rustc::util::bug::span_bug_fmt
  20: rustc_mir::transform::promote_consts::Validator::validate_local
  21: core::ops::function::impls::<impl core::ops::function::FnMut<A> for &mut F>::call_mut
  22: <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T,I>>::from_iter
  23: <rustc_mir::transform::promote_consts::PromoteTemps as rustc_mir::transform::MirPass>::run_pass
  24: rustc_mir::transform::run_passes
  25: rustc_mir::transform::mir_validated
  26: rustc::ty::query::__query_compute::mir_validated
  27: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  28: rustc_mir::borrow_check::mir_borrowck
  29: rustc::ty::query::__query_compute::mir_borrowck
  30: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  31: rustc_mir::borrow_check::type_check::TypeChecker::check_rvalue
  32: rustc_mir::borrow_check::type_check::TypeChecker::typeck_mir
  33: rustc_mir::borrow_check::type_check::type_check
  34: rustc_mir::borrow_check::nll::compute_regions
  35: rustc_mir::borrow_check::do_mir_borrowck
  36: rustc::ty::context::GlobalCtxt::enter_local
  37: rustc_mir::borrow_check::mir_borrowck
  38: rustc::ty::query::__query_compute::mir_borrowck
  39: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::mir_borrowck>::compute
  40: rustc::dep_graph::graph::DepGraph::with_task_impl
  41: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  42: rustc::ty::<impl rustc::ty::context::TyCtxt>::par_body_owners
  43: rustc_interface::passes::analysis
  44: rustc::ty::query::__query_compute::analysis
  45: rustc::dep_graph::graph::DepGraph::with_task_impl
  46: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  47: rustc::ty::context::tls::enter_global
  48: rustc_interface::interface::run_compiler_in_existing_thread_pool
  49: scoped_tls::ScopedKey<T>::set
  50: syntax::attr::with_globals

This issue has been assigned to @chrissimpkins via this comment.

Activity

added
C-bugCategory: This is a bug.
I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Feb 10, 2020
added
F-coroutines`#![feature(coroutines)]`
requires-nightlyThis issue requires a nightly compiler in some way.
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)
on Feb 10, 2020
jonas-schievink

jonas-schievink commented on Feb 10, 2020

@jonas-schievink
Contributor

Hmm, const promotion seems to mistakenly think it can promote yield expressions

Centril

Centril commented on Feb 10, 2020

@Centril
Contributor

cc @rust-lang/wg-const-eval

chrissimpkins

chrissimpkins commented on Feb 10, 2020

@chrissimpkins
Member

searched nightlies: from nightly-2020-02-01 to nightly-2020-02-08
regressed nightly: nightly-2020-02-08
searched commits: from 442ae7f to a29424a
regressed commit: f8fd462
source code: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=55e65a869e1f5fef64cc4462b1a5a087

Instructions

cargo bisect-rustc  --start 2020-02-07 --end 2020-02-08 --prompt

Error

COLLAPSIBLE ERROR STACKTRACE

   Compiling playground v0.0.1 (/playground)
error: internal compiler error: src/librustc_mir/transform/promote_consts.rs:467: _1 = suspend(move _21) -> [resume: bb2, drop: bb3] not promotable
 --> src/lib.rs:8:27
  |
8 |         println!("-> {}", yield);
  |                           ^^^^^

thread 'rustc' panicked at 'Box<Any>', <::std::macros::panic macros>:2:4
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.tiyicn.workers.dev-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/libunwind.rs:88
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.tiyicn.workers.dev-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:77
   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:1052
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1428
   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:204
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:224
  10: rustc_driver::report_ice
  11: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:474
  12: std::panicking::begin_panic
  13: rustc_errors::HandlerInner::span_bug
  14: rustc_errors::Handler::span_bug
  15: rustc::util::bug::opt_span_bug_fmt::{{closure}}
  16: rustc::ty::context::tls::with_opt::{{closure}}
  17: rustc::ty::context::tls::with_opt
  18: rustc::util::bug::opt_span_bug_fmt
  19: rustc::util::bug::span_bug_fmt
  20: rustc_mir::transform::promote_consts::Validator::validate_local
  21: core::ops::function::impls::<impl core::ops::function::FnMut<A> for &mut F>::call_mut
  22: <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T,I>>::from_iter
  23: <rustc_mir::transform::promote_consts::PromoteTemps as rustc_mir::transform::MirPass>::run_pass
  24: rustc_mir::transform::run_passes
  25: rustc_mir::transform::mir_validated
  26: rustc::ty::query::__query_compute::mir_validated
  27: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  28: rustc_mir::borrow_check::mir_borrowck
  29: rustc::ty::query::__query_compute::mir_borrowck
  30: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  31: rustc_mir::borrow_check::type_check::TypeChecker::check_rvalue
  32: rustc_mir::borrow_check::type_check::TypeChecker::typeck_mir
  33: rustc_mir::borrow_check::type_check::type_check
  34: rustc_mir::borrow_check::nll::compute_regions
  35: rustc_mir::borrow_check::do_mir_borrowck
  36: rustc::ty::context::GlobalCtxt::enter_local
  37: rustc_mir::borrow_check::mir_borrowck
  38: rustc::ty::query::__query_compute::mir_borrowck
  39: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::mir_borrowck>::compute
  40: rustc::dep_graph::graph::DepGraph::with_task_impl
  41: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  42: rustc::ty::<impl rustc::ty::context::TyCtxt>::par_body_owners
  43: rustc_interface::passes::analysis
  44: rustc::ty::query::__query_compute::analysis
  45: rustc::dep_graph::graph::DepGraph::with_task_impl
  46: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  47: rustc::ty::context::tls::enter_global
  48: rustc_interface::interface::run_compiler_in_existing_thread_pool
  49: scoped_tls::ScopedKey<T>::set
  50: syntax::attr::with_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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.43.0-nightly (71c7e149e 2020-02-09) running on x86_64-unknown-linux-gnu

note: compiler flags: -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:
#0 [mir_validated] processing `gen::{{closure}}#0`
#1 [mir_borrowck] processing `gen::{{closure}}#0`
#2 [mir_borrowck] processing `gen`
#3 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error

error: could not compile `playground`.

To learn more, run the command again with --verbose.

jonas-schievink

jonas-schievink commented on Feb 10, 2020

@jonas-schievink
Contributor

@chrissimpkins yeah this is caused by resume arguments

oli-obk

oli-obk commented on Feb 10, 2020

@oli-obk
Contributor

In the given rollup I'd guess it's caused by #68524 Essentially the issue is that we didn't know there were terminators other than Call that assigned to locals.

The fix should be as trivial as making https://github.com/rust-lang/rust/blob/master/src/librustc_mir/transform/promote_consts.rs#L465-L468 handle Yield by returning Err(Unpromotable)

added
E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
on Feb 10, 2020
added
E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
E-help-wantedCall for participation: Help is requested to fix this issue.
on Feb 10, 2020

10 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)A-coroutinesArea: CoroutinesC-bugCategory: This is a bug.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-help-wantedCall for participation: Help is requested to fix this issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.F-coroutines`#![feature(coroutines)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @oli-obk@Centril@jonas-schievink@Patryk27@chrissimpkins

      Issue actions

        ICE when `yield` is used as an argument to `println!` · Issue #69017 · rust-lang/rust