Skip to content

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

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
Patryk27 opened this issue Feb 10, 2020 · 10 comments
Closed

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

Patryk27 opened this issue Feb 10, 2020 · 10 comments
Assignees
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) A-coroutines Area: Coroutines C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-help-wanted Call for participation: Help is requested to fix this issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. F-coroutines `#![feature(coroutines)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Patryk27
Copy link
Contributor

Patryk27 commented Feb 10, 2020

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.heygears.com-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/libunwind.rs:88
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.heygears.com-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.

@Patryk27 Patryk27 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 Feb 10, 2020
@jonas-schievink jonas-schievink added A-coroutines Area: Coroutines F-coroutines `#![feature(coroutines)]` requires-nightly This issue requires a nightly compiler in some way. A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) labels Feb 10, 2020
@jonas-schievink
Copy link
Contributor

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

@Centril
Copy link
Contributor

Centril commented Feb 10, 2020

cc @rust-lang/wg-const-eval

@chrissimpkins
Copy link
Member

chrissimpkins commented Feb 10, 2020

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.heygears.com-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/libunwind.rs:88
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.heygears.com-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
Copy link
Contributor

@chrissimpkins yeah this is caused by resume arguments

@oli-obk
Copy link
Contributor

oli-obk commented Feb 10, 2020

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)

@jonas-schievink jonas-schievink added the E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. label Feb 10, 2020
@Centril Centril added E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. E-help-wanted Call for participation: Help is requested to fix this issue. labels Feb 10, 2020
@chrissimpkins
Copy link
Member

chrissimpkins commented Feb 10, 2020

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)

Maybe even simple enough for me :)

I took a stab at it. Looks like this does address it.

#69032

@chrissimpkins
Copy link
Member

@rustbot claim

@rustbot rustbot self-assigned this Feb 10, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Feb 12, 2020
…t-lang#69017, r=petrochenkov

ICE in nightly-2020-02-08: handle TerminatorKind::Yield in librustc_mir::transform::promote_consts::Validator method

IR: rust-lang#69017
regressed commit: rust-lang@f8fd462
Source: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=55e65a869e1f5fef64cc4462b1a5a087

Addresses ICE reported in rust-lang#69017 by handling `TerminatorKind::Yield` in https://github.com/rust-lang/rust/blob/4d1241f5158ffd66730e094d8f199ed654ed52ae/src/librustc_mir/transform/promote_consts.rs#L465-L468.

<details><summary>Nightly build</summary>
<p>

```
$ cargo +nightly build
Compiling yielder v0.1.0 (/Users/chris/Desktop/tests/rustlang-tests/yielder)
error: internal compiler error: src/librustc_mir/transform/promote_consts.rs:467: _1 = suspend(move _21) -> [resume: bb2, drop: bb3] not promotable
 --> src/main.rs:8:27
  |
8 |         println!("-> {}", yield);
  |                           ^^^^^

thread 'rustc' panicked at 'Box<Any>', <::std::macros::panic macros>:2:4
note: run with `RUST_BACKTRACE=1` environment variable to display a 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 (71c7e14 2020-02-09) running on x86_64-apple-darwin

note: compiler flags: -C debuginfo=2 -C incremental --crate-type bin

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

error: aborting due to previous error

error: could not compile `yielder`.

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

</p>
</details>

<details><summary>Stage 1 dev build</summary>
<p>

```
$ cargo +stage1 build
Compiling yielder v0.1.0 (/Users/chris/Desktop/tests/rustlang-tests/yielder)
warning: function is never used: `gen`
 --> src/main.rs:6:4
  |
6 | fn gen() -> impl Generator<usize> {
  |    ^^^
  |
  = note: `#[warn(dead_code)]` on by default

    Finished dev [unoptimized + debuginfo] target(s) in 0.53s
```

</p>
</details>

@jonas-schievink @oli-obk
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Feb 12, 2020
…t-lang#69017, r=petrochenkov

ICE in nightly-2020-02-08: handle TerminatorKind::Yield in librustc_mir::transform::promote_consts::Validator method

IR: rust-lang#69017
regressed commit: rust-lang@f8fd462
Source: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=55e65a869e1f5fef64cc4462b1a5a087

Addresses ICE reported in rust-lang#69017 by handling `TerminatorKind::Yield` in https://github.com/rust-lang/rust/blob/4d1241f5158ffd66730e094d8f199ed654ed52ae/src/librustc_mir/transform/promote_consts.rs#L465-L468.

<details><summary>Nightly build</summary>
<p>

```
$ cargo +nightly build
Compiling yielder v0.1.0 (/Users/chris/Desktop/tests/rustlang-tests/yielder)
error: internal compiler error: src/librustc_mir/transform/promote_consts.rs:467: _1 = suspend(move _21) -> [resume: bb2, drop: bb3] not promotable
 --> src/main.rs:8:27
  |
8 |         println!("-> {}", yield);
  |                           ^^^^^

thread 'rustc' panicked at 'Box<Any>', <::std::macros::panic macros>:2:4
note: run with `RUST_BACKTRACE=1` environment variable to display a 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 (71c7e14 2020-02-09) running on x86_64-apple-darwin

note: compiler flags: -C debuginfo=2 -C incremental --crate-type bin

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

error: aborting due to previous error

error: could not compile `yielder`.

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

</p>
</details>

<details><summary>Stage 1 dev build</summary>
<p>

```
$ cargo +stage1 build
Compiling yielder v0.1.0 (/Users/chris/Desktop/tests/rustlang-tests/yielder)
warning: function is never used: `gen`
 --> src/main.rs:6:4
  |
6 | fn gen() -> impl Generator<usize> {
  |    ^^^
  |
  = note: `#[warn(dead_code)]` on by default

    Finished dev [unoptimized + debuginfo] target(s) in 0.53s
```

</p>
</details>

@jonas-schievink @oli-obk
@chrissimpkins
Copy link
Member

merged to master in #69094

@jonas-schievink
Copy link
Contributor

Thanks for fixing this!

@chrissimpkins
Copy link
Member

Thanks to you and Oliver for helping me!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) A-coroutines Area: Coroutines C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-help-wanted Call for participation: Help is requested to fix this issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. F-coroutines `#![feature(coroutines)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants