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 when playing with async/await. #62009

Closed
Accuratemiss opened this issue Jun 20, 2019 · 6 comments · Fixed by #62152
Closed

ICE when playing with async/await. #62009

Accuratemiss opened this issue Jun 20, 2019 · 6 comments · Fixed by #62152
Assignees
Labels
A-async-await Area: Async & Await AsyncAwait-Polish Async-await issues that are part of the "polish" area 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.

Comments

@Accuratemiss
Copy link

Accuratemiss commented Jun 20, 2019

Hi

I'm pretty new to rust and programming in general. I was trying (failing) to write some toy async code and I got this internal compiler error, the theme seems to be always report ICEs so here we go
This was from cargo:

Compiling async v0.1.0 (/home/james/dev/async)
error[E0728]: `await` is only allowed inside `async` functions and blocks
  --> src/main.rs:30:1
   |
26 |   fn main() -> () {
   |      ---- this is not `async`
...
30 | / async{
31 | |     let task1 = print_dur(1).await;
32 | |     let task2 = print_dur(3).await;
33 | |     // pool.run(task1);
34 | | }.await
   | |_______^ only allowed inside `async` functions and blocks

warning: unused import: `futures::executor::block_on`
 --> src/main.rs:7:5
  |
7 | use futures::executor::block_on;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: #[warn(unused_imports)] on by default

warning: unused import: `tokio::timer`
 --> src/main.rs:9:5
  |
9 | use tokio::timer;
  |     ^^^^^^^^^^^^

warning: unused import: `tokio::prelude::*`
  --> src/main.rs:10:5
   |
10 | use tokio::prelude::*;
   |     ^^^^^^^^^^^^^^^^^

thread 'rustc' panicked at 'src/librustc/hir/map/hir_id_validator.rs:25: 
ItemLocalIds not assigned densely in ::main[0]. Max ItemLocalId = 16, missing IDs = ["[local_id: 2, node:unknown node (hir_id=HirId { owner: DefIndex(27), local_id: 2 })]", "[local_id: 3, node:unknown node (hir_id=HirId { owner: DefIndex(27), local_id: 3 })]"]; seens IDs = ["(HirId { owner: DefIndex(27), local_id: 0 } fn main (hir_id=HirId { owner: DefIndex(27), local_id: 0 }))", "(HirId { owner: DefIndex(27), local_id: 14 } block { let mut pool = <ThreadPool>::new().unwrap(); (/*ERROR*/) } (hir_id=HirId { owner: DefIndex(27), local_id: 14 }))", "(HirId { owner: DefIndex(27), local_id: 11 } expr <ThreadPool>::new().unwrap() (hir_id=HirId { owner: DefIndex(27), local_id: 11 }))", "(HirId { owner: DefIndex(27), local_id: 8 } path segment new (hir_id=HirId { owner: DefIndex(27), local_id: 8 }))", "(HirId { owner: DefIndex(27), local_id: 5 } path segment unwrap (hir_id=HirId { owner: DefIndex(27), local_id: 5 }))", "(HirId { owner: DefIndex(27), local_id: 16 } type () (hir_id=HirId { owner: DefIndex(27), local_id: 16 }))", "(HirId { owner: DefIndex(27), local_id: 13 } expr (/*ERROR*/) (hir_id=HirId { owner: DefIndex(27), local_id: 13 }))", "(HirId { owner: DefIndex(27), local_id: 10 } expr <ThreadPool>::new() (hir_id=HirId { owner: DefIndex(27), local_id: 10 }))", "(HirId { owner: DefIndex(27), local_id: 7 } type ThreadPool (hir_id=HirId { owner: DefIndex(27), local_id: 7 }))", "(HirId { owner: DefIndex(27), local_id: 4 } local mut pool (hir_id=HirId { owner: DefIndex(27), local_id: 4 }))", "(HirId { owner: DefIndex(27), local_id: 1 } local mut pool (hir_id=HirId { owner: DefIndex(27), local_id: 1 }))", "(HirId { owner: DefIndex(27), local_id: 15 } expr { let mut pool = <ThreadPool>::new().unwrap(); (/*ERROR*/) } (hir_id=HirId { owner: DefIndex(27), local_id: 15 }))", "(HirId { owner: DefIndex(27), local_id: 12 } stmt let mut pool = <ThreadPool>::new().unwrap(); (hir_id=HirId { owner: DefIndex(27), local_id: 12 }))", "(HirId { owner: DefIndex(27), local_id: 9 } expr <ThreadPool>::new (hir_id=HirId { owner: DefIndex(27), local_id: 9 }))", "(HirId { owner: DefIndex(27), local_id: 6 } path segment ThreadPool (hir_id=HirId { owner: DefIndex(27), local_id: 6 }))"]', src/librustc/util/bug.rs:37:26
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.29/src/backtrace/libunwind.rs:88
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.29/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:47
   3: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:36
   4: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:198
   5: std::panicking::default_hook
             at src/libstd/panicking.rs:212
   6: rustc::util::common::panic_hook
   7: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:479
   8: std::panicking::begin_panic
   9: rustc::util::bug::opt_span_bug_fmt::{{closure}}
  10: rustc::ty::context::tls::with_opt::{{closure}}
  11: rustc::ty::context::tls::with_context_opt
  12: rustc::ty::context::tls::with_opt
  13: rustc::util::bug::opt_span_bug_fmt
  14: rustc::util::bug::bug_fmt
  15: rustc::hir::map::hir_id_validator::check_crate
  16: rustc::util::common::time
  17: rustc::hir::map::map_crate
  18: rustc_interface::passes::create_global_ctxt::{{closure}}
  19: rustc_data_structures::box_region::PinnedGenerator<I,A,R>::new
  20: rustc_interface::passes::create_global_ctxt
  21: rustc_interface::queries::Query<T>::compute
  22: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::global_ctxt
  23: rustc_interface::interface::run_compiler_in_existing_thread_pool
  24: std::thread::local::LocalKey<T>::with
  25: scoped_tls::ScopedKey<T>::set
  26: syntax::with_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
query stack during panic:
end of query stack
error: aborting due to previous error


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.37.0-nightly (2fe7b3383 2019-06-19) running on x86_64-unknown-linux-gnu

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

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

error: Could not compile `async`.

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

The code I was trying was this code:

#![feature(async_await)]
extern crate runtime;
use futures::future;
use futures::executor::block_on;
use futures_executor::ThreadPool;
use tokio::timer;
use tokio::prelude::*;

use std::{ thread, time };


async fn print_dur(dur:u64) {
    println!("starting");
    thread::sleep(time::Duration::from_secs(dur));
    println!("{:?} done", dur);
}

async fn run_twice() {
    let x = vec![print_dur(1), print_dur(5), print_dur(1)];
    future::join_all(x);
}

fn main() -> () {
let mut pool = ThreadPool::new().unwrap();


async{
    let task1 = print_dur(1).await;
    let task2 = print_dur(3).await;
    // pool.run(task1);
}.await

}

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

@Centril Centril added A-async-await Area: Async & Await AsyncAwait-Polish Async-await issues that are part of the "polish" area 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 Jun 21, 2019
@Aaron1011
Copy link
Member

Minimized:

#![feature(async_await)]

async fn print_dur() {}

fn main() -> () {
    async{
        let task1 = print_dur().await;
    }.await
}

@memoryruins
Copy link
Contributor

memoryruins commented Jun 22, 2019

ICEs with any let statement between async { /* ... */ }.await while inside a function that isn't async


ICE

#![feature(async_await)]

fn main() {
    async { let (); }.await
}
error[E0728]: `await` is only allowed inside `async` functions and blocks
 --> src/main.rs:4:5
  |
3 | fn main() {
  |    ---- this is not `async`
4 |     async { let (); }.await
  |     ^^^^^^^^^^^^^^^^^^^^^^^ only allowed inside `async` functions and blocks

thread 'rustc' panicked at 'src/librustc/hir/map/hir_id_validator.rs:26: 
ItemLocalIds not assigned densely in ::main[0]. Max ItemLocalId = 5, missing IDs = ["[local_id: 1, node:unknown node (hir_id=HirId { owner: DefIndex(12), local_id: 1 })]"]; seens IDs = ["(HirId { owner: DefIndex(12), local_id: 0 } fn main (hir_id=HirId { owner: DefIndex(12), local_id: 0 }))", "(HirId { owner: DefIndex(12), local_id: 5 } unknown node (hir_id=HirId { owner: DefIndex(12), local_id: 5 }))", "(HirId { owner: DefIndex(12), local_id: 2 } expr (/*ERROR*/) (hir_id=HirId { owner: DefIndex(12), local_id: 2 }))", "(HirId { owner: DefIndex(12), local_id: 4 } expr { (/*ERROR*/) } (hir_id=HirId { owner: DefIndex(12), local_id: 4 }))", "(HirId { owner: DefIndex(12), local_id: 3 } block { (/*ERROR*/) } (hir_id=HirId { owner: DefIndex(12), local_id: 3 }))"]', src/librustc/util/bug.rs:37:26

Error without let and without the ICE

#![feature(async_await)]

fn main() {
    async {}.await
}
error[E0728]: `await` is only allowed inside `async` functions and blocks
 --> src/main.rs:4:5
  |
3 | fn main() {
  |    ---- this is not `async`
4 |     async {}.await
  |     ^^^^^^^^^^^^^^ only allowed inside `async` functions and blocks

error: aborting due to previous error

let statement inside async function

#![feature(async_await)]

fn main() {
    foo();
}

async fn foo() {
    async { let (); }.await
}
warning: unused implementer of `std::future::Future` that must be used
 --> src/main.rs:4:5
  |
4 |     foo();
  |     ^^^^^^
  |
  = note: #[warn(unused_must_use)] on by default
  = note: futures do nothing unless you `.await` or poll them

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

@doctorn
Copy link
Contributor

doctorn commented Jun 23, 2019

@rustbot claim

@rustbot rustbot self-assigned this Jun 23, 2019
@doctorn
Copy link
Contributor

doctorn commented Jun 23, 2019

This is actually the same as #61685. I think I've got a fix for both.

@nikomatsakis
Copy link
Contributor

@doctorn do you have a PR for this open?

@cramertj
Copy link
Member

Closing as a duplicate of #61685, both of which are fixed by #62152

Centril added a commit to Centril/rust that referenced this issue Jun 27, 2019
Don't ICE on item in `.await` expression

The code for lowering a `.await` expression missed that item IDs may already have been assigned for items inside of an `async` block, or for closures. This change means we no longer exit early after finding a `.await` in a block that isn't `async` and instead just emit the error. This avoids an ICE generated due to item IDs not being densely generated. (The `YieldSource` of the generated `yield` expression is  used to avoid errors generated about having `yield` expressions outside of generator literals.)

r? @cramertj

Resolves rust-lang#62009 and resolves rust-lang#61685
Centril added a commit to Centril/rust that referenced this issue Jun 27, 2019
Don't ICE on item in `.await` expression

The code for lowering a `.await` expression missed that item IDs may already have been assigned for items inside of an `async` block, or for closures. This change means we no longer exit early after finding a `.await` in a block that isn't `async` and instead just emit the error. This avoids an ICE generated due to item IDs not being densely generated. (The `YieldSource` of the generated `yield` expression is  used to avoid errors generated about having `yield` expressions outside of generator literals.)

r? @cramertj

Resolves rust-lang#62009 and resolves rust-lang#61685
Centril added a commit to Centril/rust that referenced this issue Jun 27, 2019
Don't ICE on item in `.await` expression

The code for lowering a `.await` expression missed that item IDs may already have been assigned for items inside of an `async` block, or for closures. This change means we no longer exit early after finding a `.await` in a block that isn't `async` and instead just emit the error. This avoids an ICE generated due to item IDs not being densely generated. (The `YieldSource` of the generated `yield` expression is  used to avoid errors generated about having `yield` expressions outside of generator literals.)

r? @cramertj

Resolves rust-lang#62009 and resolves rust-lang#61685
Centril added a commit to Centril/rust that referenced this issue Jun 27, 2019
Don't ICE on item in `.await` expression

The code for lowering a `.await` expression missed that item IDs may already have been assigned for items inside of an `async` block, or for closures. This change means we no longer exit early after finding a `.await` in a block that isn't `async` and instead just emit the error. This avoids an ICE generated due to item IDs not being densely generated. (The `YieldSource` of the generated `yield` expression is  used to avoid errors generated about having `yield` expressions outside of generator literals.)

r? @cramertj

Resolves rust-lang#62009 and resolves rust-lang#61685
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-async-await Area: Async & Await AsyncAwait-Polish Async-await issues that are part of the "polish" area 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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants