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

Unsized locals and async ICE #68543

Closed
DutchGhost opened this issue Jan 25, 2020 · 6 comments · Fixed by #116081
Closed

Unsized locals and async ICE #68543

DutchGhost opened this issue Jan 25, 2020 · 6 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_fn_params `#![feature(unsized_fn_params)]` 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) ❄️ 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

@DutchGhost
Copy link
Contributor

DutchGhost commented Jan 25, 2020

The following ICE's:

#![feature(unsized_fn_params, unsized_locals)]

use std::future::Future;

async fn bug<T>(mut f: dyn Future<Output = T> + Unpin) -> T {
    (&mut f).await
}
Backtrace:
  Compiling playground v0.0.1 (/playground)
warning: function is never used: `bug`
 --> src/lib.rs:5:10
  |
5 | async fn bug<T>(mut f: dyn Future<Output = T> + Unpin) -> T {
  |          ^^^
  |
  = note: `#[warn(dead_code)]` on by default

thread 'rustc' panicked at 'assertion failed: !field.is_unsized()', src/librustc/ty/layout.rs:719:25
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/libunwind.rs:88
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.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:1426
   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:476
  12: std::panicking::begin_panic
  13: rustc::ty::layout::LayoutCx<rustc::ty::context::TyCtxt>::layout_raw_uncached
  14: rustc::ty::layout::layout_raw
  15: rustc::ty::query::__query_compute::layout_raw
  16: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::layout_raw>::compute
  17: rustc::dep_graph::graph::DepGraph::with_task_impl
  18: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  19: <rustc::ty::layout::LayoutCx<rustc::ty::context::TyCtxt> as rustc_target::abi::LayoutOf>::layout_of
  20: <core::iter::adapters::Map<I,F> as core::iter::traits::iterator::Iterator>::try_fold
  21: <core::iter::adapters::chain::Chain<A,B> as core::iter::traits::iterator::Iterator>::try_fold
  22: <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T,I>>::from_iter
  23: rustc::ty::layout::LayoutCx<rustc::ty::context::TyCtxt>::layout_raw_uncached
  24: rustc::ty::layout::layout_raw
  25: rustc::ty::query::__query_compute::layout_raw
  26: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::layout_raw>::compute
  27: rustc::dep_graph::graph::DepGraph::with_task_impl
  28: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  29: <rustc::ty::layout::LayoutCx<rustc::ty::context::TyCtxt> as rustc_target::abi::LayoutOf>::layout_of
  30: <core::iter::adapters::ResultShunt<I,E> as core::iter::traits::iterator::Iterator>::next
  31: <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T,I>>::from_iter
  32: <core::iter::adapters::ResultShunt<I,E> as core::iter::traits::iterator::Iterator>::next
  33: <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T,I>>::from_iter
  34: core::iter::adapters::process_results
  35: rustc::ty::layout::LayoutCx<rustc::ty::context::TyCtxt>::layout_raw_uncached
  36: rustc::ty::layout::layout_raw
  37: rustc::ty::query::__query_compute::layout_raw
  38: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::layout_raw>::compute
  39: rustc::dep_graph::graph::DepGraph::with_task_impl
  40: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  41: <rustc::ty::layout::LayoutCx<rustc::ty::query::TyCtxtAt> as rustc_target::abi::LayoutOf>::layout_of
  42: <rustc_mir::transform::const_prop::ConstProp as rustc_mir::transform::MirPass>::run_pass
  43: rustc_mir::transform::run_passes
  44: rustc_mir::transform::run_optimization_passes
  45: rustc_mir::transform::optimized_mir
  46: rustc::ty::query::__query_compute::optimized_mir
  47: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::optimized_mir>::compute
  48: rustc::dep_graph::graph::DepGraph::with_task_impl
  49: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  50: rustc_metadata::rmeta::encoder::EncodeContext::encode_optimized_mir
  51: <rustc_metadata::rmeta::encoder::EncodeContext as rustc_hir::intravisit::Visitor>::visit_item
  52: rustc_hir::hir::Crate::visit_all_item_likes
  53: rustc_metadata::rmeta::encoder::EncodeContext::encode_crate_root
  54: rustc::ty::context::tls::with_context::{{closure}}
  55: rustc_metadata::rmeta::encoder::encode_metadata
  56: rustc_metadata::rmeta::decoder::cstore_impl::<impl rustc::middle::cstore::CrateStore for rustc_metadata::creader::CStore>::encode_metadata
  57: rustc::ty::context::TyCtxt::encode_metadata
  58: rustc_interface::passes::QueryContext::enter
  59: rustc_interface::queries::Queries::ongoing_codegen
  60: rustc_interface::interface::run_compiler_in_existing_thread_pool
  61: scoped_tls::ScopedKey<T>::set
  62: syntax::with_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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.42.0-nightly (c2d141df5 2020-01-24) running on x86_64-unknown-linux-gnu

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

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

query stack during panic:
#0 [layout_raw] computing layout of `std::mem::MaybeUninit<dyn std::future::Future<Output = T> + std::marker::Unpin>`
#1 [layout_raw] computing layout of `[static generator@src/lib.rs:5:61: 7:2 __arg0:dyn std::future::Future<Output = T> + std::marker::Unpin for<'r, 's, 't0, 't1, 't2, 't3, 't4> {(dyn std::future::Future<Output = T> + std::marker::Unpin + 'r), (dyn std::future::Future<Output = T> + std::marker::Unpin + 's), (dyn std::future::Future<Output = T> + std::marker::Unpin + 't0), &'t1 mut (dyn std::future::Future<Output = T> + std::marker::Unpin + 't2), &'t3 mut (dyn std::future::Future<Output = T> + std::marker::Unpin + 't4), (), ()}]`
#2 [layout_raw] computing layout of `std::future::GenFuture<[static generator@src/lib.rs:5:61: 7:2 __arg0:dyn std::future::Future<Output = T> + std::marker::Unpin for<'r, 's, 't0, 't1, 't2, 't3, 't4> {(dyn std::future::Future<Output = T> + std::marker::Unpin + 'r), (dyn std::future::Future<Output = T> + std::marker::Unpin + 's), (dyn std::future::Future<Output = T> + std::marker::Unpin + 't0), &'t1 mut (dyn std::future::Future<Output = T> + std::marker::Unpin + 't2), &'t3 mut (dyn std::future::Future<Output = T> + std::marker::Unpin + 't4), (), ()}]>`
#3 [optimized_mir] processing `bug`
end of query stack
error: could not compile `playground`.

To learn more, run the command again with --verbose.
@jonas-schievink jonas-schievink added C-bug Category: This is a bug. F-unsized_locals `#![feature(unsized_locals)]` 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. A-async-await Area: Async & Await labels Jan 25, 2020
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Jan 26, 2020
@tmandry tmandry added the AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. label Jan 28, 2020
@tmandry
Copy link
Member

tmandry commented Jan 28, 2020

Visiting from async/await triage. Not making this a priority at the moment because it depends on an unstable feature.

@JohnTitor
Copy link
Member

Triage: the feature gate requires unsized_fn_params as well now.

@JohnTitor JohnTitor added the F-unsized_fn_params `#![feature(unsized_fn_params)]` label Oct 29, 2020
@DutchGhost
Copy link
Contributor Author

Triage: the feature gate requires unsized_fn_params as well now.

No, it does not:

#![feature(unsized_locals)]

struct T {
    a: [(); {
        let y = async {
            let f: (dyn for<'a> std::future::Future<Output = ()> + Unpin);
            
            f.await
        };
        
        core::mem::forget(y);
        1
    }]
}

Also even though it has a #![feature(...)], the ICE also happens when compiling with stable

@DutchGhost
Copy link
Contributor Author

The code in question now needs some extra (&mut f).await:

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

struct T {
    a: [(); {
        let y = async {
            let f: (dyn for<'a> std::future::Future<Output = ()> + Unpin);
            
            (&mut f).await
        };
        
        core::mem::forget(y);
        1
    }]
}

@DutchGhost
Copy link
Contributor Author

Same also occurs with generators and unsized locals acros yield points:

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

use std::ops::Generator;

fn blah() -> impl Generator {
    move || {
        let b: [u8] = *(Box::new([]) as Box<[u8]>);
        
        yield;
        
        for elem in b.iter() {}
    }
}

fn main() {
    blah();
}

@RalfJung
Copy link
Member

RalfJung commented Aug 6, 2023

Is this a duplicate of #61335?

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_fn_params `#![feature(unsized_fn_params)]` 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) ❄️ 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

Successfully merging a pull request may close this issue.

6 participants