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 combining unsized locals and async #61335

Closed
syosi opened this issue May 30, 2019 · 7 comments · Fixed by #116081
Closed

ICE when combining unsized locals and async #61335

syosi opened this issue May 30, 2019 · 7 comments · Fixed by #116081
Labels
A-async-await Area: Async & Await AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. C-bug Category: This is a bug. F-unsized_locals `#![feature(unsized_locals)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority 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

@syosi
Copy link

syosi commented May 30, 2019

It seemed clear to me that having an unsized local across a yield point cannot work.
Indeed, you get an ICE with (playground):

#![feature(async_await)]
#![feature(unsized_locals)]
#![feature(gen_future)]

use std::future::poll_with_tls_context;
use std::pin::Pin;
use std::fmt::Display;

async fn foo2() {}

async fn foo(x: Box<dyn Display>) {
    let x = *x;
    foo2().await;
    println!("hello {}", &x);
}

fn main() {
    let mut a = foo(Box::new(5));
    let b = unsafe {
        Pin::new_unchecked(&mut a)
    };
    match poll_with_tls_context(b) {
        _ => ()
    };
}
@Centril Centril added A-async-await Area: Async & Await 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. I-nominated labels May 30, 2019
@Centril
Copy link
Contributor

Centril commented May 30, 2019

Backtrace:

   Compiling playground v0.0.1 (/playground)
error: internal compiler error: src/librustc/ty/layout.rs:328: univariant: field #3 of `[static generator@src/main.rs:11:35: 15:2 x:std::boxed::Box<dyn std::fmt::Display> for<'r, 's> {std::boxed::Box<(dyn std::fmt::Display + 'r)>, (dyn std::fmt::Display + 's), std::future::GenFuture<[static generator@src/main.rs:9:17: 9:19 {}]>, ()}]` comes after unsized field

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:637:9
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/gitpro.ttaallkk.top-1ecc6299db9ec823/backtrace-0.3.25/src/backtrace/libunwind.rs:97
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/gitpro.ttaallkk.top-1ecc6299db9ec823/backtrace-0.3.25/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:197
   5: std::panicking::default_hook
             at src/libstd/panicking.rs:211
   6: rustc::util::common::panic_hook
   7: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:478
   8: std::panicking::begin_panic
   9: rustc_errors::Handler::bug
  10: rustc::util::bug::opt_span_bug_fmt::{{closure}}
  11: rustc::ty::context::tls::with_opt::{{closure}}
  12: rustc::ty::context::tls::with_context_opt
  13: rustc::ty::context::tls::with_opt
  14: rustc::util::bug::opt_span_bug_fmt
  15: rustc::util::bug::bug_fmt
  16: rustc::ty::layout::LayoutCx<rustc::ty::context::TyCtxt>::layout_raw_uncached::{{closure}}
  17: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &mut F>::call_once
  18: <&mut I as core::iter::traits::iterator::Iterator>::next
  19: <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T,I>>::from_iter
  20: rustc::ty::layout::LayoutCx<rustc::ty::context::TyCtxt>::layout_raw_uncached
  21: rustc::ty::layout::layout_raw
  22: rustc::ty::query::__query_compute::layout_raw
  23: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::layout_raw>::compute
  24: rustc::dep_graph::graph::DepGraph::with_task_impl
  25: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  26: <rustc::ty::layout::LayoutCx<rustc::ty::context::TyCtxt> as rustc_target::abi::LayoutOf>::layout_of
  27: <rustc_mir::transform::const_prop::ConstPropagator as rustc::mir::visit::MutVisitor>::visit_statement
  28: <rustc_mir::transform::const_prop::ConstProp as rustc_mir::transform::MirPass>::run_pass
  29: rustc_mir::transform::run_passes::{{closure}}
  30: rustc_mir::transform::run_passes
  31: rustc_mir::transform::optimized_mir
  32: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::optimized_mir>::compute
  33: rustc::dep_graph::graph::DepGraph::with_task_impl
  34: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  35: rustc_mir::monomorphize::collector::collect_items_rec
  36: rustc_mir::monomorphize::collector::collect_items_rec
  37: rustc_mir::monomorphize::collector::collect_crate_mono_items::{{closure}}
  38: rustc::util::common::time
  39: rustc_mir::monomorphize::collector::collect_crate_mono_items
  40: rustc::util::common::time
  41: rustc_mir::monomorphize::partitioning::collect_and_partition_mono_items
  42: rustc::ty::query::__query_compute::collect_and_partition_mono_items
  43: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::collect_and_partition_mono_items>::compute
  44: rustc::dep_graph::graph::DepGraph::with_task_impl
  45: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  46: rustc_codegen_ssa::base::codegen_crate
  47: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_utils::codegen_backend::CodegenBackend>::codegen_crate
  48: rustc::util::common::time
  49: rustc_interface::passes::start_codegen
  50: rustc::ty::context::tls::enter_global
  51: rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}
  52: rustc_interface::passes::create_global_ctxt::{{closure}}
  53: rustc_interface::passes::BoxedGlobalCtxt::enter
  54: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::ongoing_codegen
  55: rustc_interface::interface::run_compiler_in_existing_thread_pool
  56: std::thread::local::LocalKey<T>::with
  57: scoped_tls::ScopedKey<T>::set
  58: syntax::with_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
query stack during panic:
#0 [layout_raw] computing layout of `[static generator@src/main.rs:11:35: 15:2 x:std::boxed::Box<dyn std::fmt::Display> for<'r, 's> {std::boxed::Box<(dyn std::fmt::Display + 'r)>, (dyn std::fmt::Display + 's), std::future::GenFuture<[static generator@src/main.rs:9:17: 9:19 {}]>, ()}]`
#1 [optimized_mir] processing `foo`
#2 [collect_and_partition_mono_items] collect_and_partition_mono_items
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.37.0-nightly (37d001e4d 2019-05-29) running on x86_64-unknown-linux-gnu

note: compiler flags: -C codegen-units=1 -C debuginfo=2 --crate-type bin

@Centril
Copy link
Contributor

Centril commented May 30, 2019

Reduced:

#![feature(async_await)]
#![feature(unsized_locals)]

async fn f() {}

async fn g(x: Box<dyn core::fmt::Display>) {
    let _x = *x;
    f().await;
}

fn main() {
    let _a = g(Box::new(5));
}

cc @tmandry @Zoxc @cramertj

@Centril
Copy link
Contributor

Centril commented May 30, 2019

Notably, swapping the order of the let _x = *x; to be after the f().await; does not cause an ICE or error.

@cramertj
Copy link
Member

cramertj commented May 30, 2019

@Centril sure, that's what I would expect. unsized locals can't be allowed across an await point. Still, it should be an error rather than an ICE ;)

@nikomatsakis nikomatsakis added the AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. label Jun 4, 2019
@nikomatsakis
Copy link
Contributor

Marking as "deferred" -- as unsized locals are not a stable feature, shouldn't be a blocker.

@pnkfelix
Copy link
Member

pnkfelix commented Jun 6, 2019

triage: P-medium, via same logic employed above to mark as deferred. Removing nomination label.

@pnkfelix pnkfelix added P-medium Medium priority and removed I-nominated labels Jun 6, 2019
@Centril Centril added F-async_await F-unsized_locals `#![feature(unsized_locals)]` labels Jul 28, 2019
@jonas-schievink jonas-schievink added the C-bug Category: This is a bug. label Aug 6, 2019
@Centril Centril added the requires-nightly This issue requires a nightly compiler in some way. label Oct 25, 2019
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label May 12, 2020
@Enselic
Copy link
Member

Enselic commented Sep 9, 2023

Triage: Still reproduces with nightly:

$ cat repro.rs
#![feature(unsized_locals)]

async fn f() {}

async fn g(x: Box<dyn core::fmt::Display>) {
    let _x = *x;
    f().await;
}

fn main() {
    let _a = g(Box::new(5));
}
$ rustc +nightly --edition 2018 repro.rs
error: internal compiler error: no errors encountered even though `delay_span_bug` issued

error: internal compiler error: unsized field in union
$ rustc +nightly -vV
rustc 1.74.0-nightly (1e746d774 2023-09-07)
binary: rustc
commit-hash: 1e746d7741d44551e9378daf13b8797322aa0b74
commit-date: 2023-09-07
host: x86_64-unknown-linux-gnu
release: 1.74.0-nightly
LLVM version: 17.0.0

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-Triaged Async-await issues that have been triaged during a working group meeting. C-bug Category: This is a bug. F-unsized_locals `#![feature(unsized_locals)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority 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
8 participants