Skip to content

nightly ICE with unboxed async fn recursion #131409

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

Closed
spookyvision opened this issue Oct 8, 2024 · 2 comments · Fixed by #131420
Closed

nightly ICE with unboxed async fn recursion #131409

spookyvision opened this issue Oct 8, 2024 · 2 comments · Fixed by #131420
Labels
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.

Comments

@spookyvision
Copy link
Contributor

spookyvision commented Oct 8, 2024

Code

trait Blah {
    async fn iter<T>(&mut self, iterator: T)
    where
        T: IntoIterator<Item = ()>;
}

impl Blah for () {
    async fn iter<T>(&mut self, iterator: T)
    where
        T: IntoIterator<Item = ()>,
    {
        Blah::iter(self, iterator).await
    }
}

struct Wrap<T: Blah> {
    t: T,
}

impl<T: Blah> Wrap<T>
where
    T: Blah,
{
    async fn ice(&mut self) {
        let arr: [(); 0] = [];
        self.t.iter(arr.into_iter()).await;
    }
}

#[tokio::main]
async fn main() {
    let mut t = Wrap { t: () };

    t.ice();
}

Meta

rustc --version --verbose:

rustc 1.83.0-nightly (3ae715c8c 2024-10-07)
binary: rustc
commit-hash: 3ae715c8c63f9aeac47cbf7d8d9dadb3fa32c638
commit-date: 2024-10-07
host: aarch64-apple-darwin
release: 1.83.0-nightly
LLVM version: 19.1.1

Error output

warning: unused implementer of `Future` that must be used
  --> src/main.rs:37:5
   |
37 |     t.ice();
   |     ^^^^^^^
   |
   = note: futures do nothing unless you `.await` or poll them
   = note: `#[warn(unused_must_use)]` on by default

error[E0733]: recursion in an async fn requires boxing
  --> src/main.rs:10:5
   |
10 | /     async fn write<T>(&mut self, iterator: T)
11 | |     where
12 | |         T: IntoIterator<Item = ()>,
   | |___________________________________^
13 |       {
14 |           Blah::write(self, iterator).await
   |           --------------------------------- recursive call here
   |
   = note: a recursive `async fn` call must introduce indirection such as `Box::pin` to avoid an infinitely sized future

error: internal compiler error: compiler/rustc_codegen_llvm/src/context.rs:1186:21: `fn_abi_of_instance(Wrap::<()>::ice, [])` failed: Layout(Cycle(ErrorGuaranteed(())))
  --> src/main.rs:26:5
   |
26 |     async fn ice(&mut self) {
   |     ^^^^^^^^^^^^^^^^^^^^^^^

thread 'rustc' panicked at compiler/rustc_codegen_llvm/src/context.rs:1186:21:
Box<dyn Any>
stack backtrace:

(pasted below, as per the template's instructions)

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: please make sure that you have updated to the latest nightly

note: please attach the file at `/private/tmp/aec.24_07_03_17_29_39.wO/ice/rustc-ice-2024-10-08T16_47_37-3270.txt` to your bug report

note: compiler flags: --crate-type bin -C opt-level=3 -C embed-bitcode=no -C debuginfo=2 -C split-debuginfo=unpacked

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

query stack during panic:
end of query stack
For more information about this error, try `rustc --explain E0733`.
warning: `ice` (bin "ice") generated 1 warning
error: could not compile `ice` (bin "ice") due to 1 previous error; 1 warning emitted
Backtrace

   0:        0x10e54bd44 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::ha1175e5d631924b6
   1:        0x10b8cd7dc - core::fmt::write::hb0b7e313ed56bf22
   2:        0x10e53fdf4 - std::io::Write::write_fmt::hd7b821ad1b2e3439
   3:        0x10e54bc04 - std::sys::backtrace::BacktraceLock::print::h3a7a2e7d356908ce
   4:        0x10e54e0d0 - std::panicking::default_hook::{{closure}}::h10557e6d4768ff4b
   5:        0x10e54df1c - std::panicking::default_hook::h4543f5bf1aacb61d
   6:        0x10c4d1fb4 - <alloc[33d0a6a508eb5932]::boxed::Box<rustc_driver_impl[c0574d6a9003aa16]::install_ice_hook::{closure#0}> as core[ef7e3446cee7ff23]::ops::function::Fn<(&dyn for<'a, 'b> core[ef7e3446cee7ff23]::ops::function::Fn<(&'a std[5d2d2d2a3de07169]::panic::PanicHookInfo<'b>,), Output = ()> + core[ef7e3446cee7ff23]::marker::Send + core[ef7e3446cee7ff23]::marker::Sync, &std[5d2d2d2a3de07169]::panic::PanicHookInfo)>>::call
   7:        0x10e54e95c - std::panicking::rust_panic_with_hook::hf0bd200963f84a79
   8:        0x10c558990 - std[5d2d2d2a3de07169]::panicking::begin_panic::<rustc_errors[6c9f61422b2b67fe]::ExplicitBug>::{closure#0}
   9:        0x10c5587e8 - std[5d2d2d2a3de07169]::sys::backtrace::__rust_end_short_backtrace::<std[5d2d2d2a3de07169]::panicking::begin_panic<rustc_errors[6c9f61422b2b67fe]::ExplicitBug>::{closure#0}, !>
  10:        0x110c4e5d8 - std[5d2d2d2a3de07169]::panicking::begin_panic::<rustc_errors[6c9f61422b2b67fe]::ExplicitBug>
  11:        0x10c549fcc - <rustc_errors[6c9f61422b2b67fe]::diagnostic::BugAbort as rustc_errors[6c9f61422b2b67fe]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:        0x10c167fe0 - <rustc_errors[6c9f61422b2b67fe]::DiagCtxtHandle>::span_bug::<rustc_span[a9b61c9ba68f3314]::span_encoding::Span, alloc[33d0a6a508eb5932]::string::String>
  13:        0x10c16c52c - rustc_middle[7d4f75877793c8e4]::util::bug::opt_span_bug_fmt::<rustc_span[a9b61c9ba68f3314]::span_encoding::Span>::{closure#0}
  14:        0x10c16c560 - rustc_middle[7d4f75877793c8e4]::ty::context::tls::with_opt::<rustc_middle[7d4f75877793c8e4]::util::bug::opt_span_bug_fmt<rustc_span[a9b61c9ba68f3314]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  15:        0x10c16ba00 - rustc_middle[7d4f75877793c8e4]::ty::context::tls::with_context_opt::<rustc_middle[7d4f75877793c8e4]::ty::context::tls::with_opt<rustc_middle[7d4f75877793c8e4]::util::bug::opt_span_bug_fmt<rustc_span[a9b61c9ba68f3314]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  16:        0x110c24198 - rustc_middle[7d4f75877793c8e4]::util::bug::span_bug_fmt::<rustc_span[a9b61c9ba68f3314]::span_encoding::Span>
  17:        0x10c0c88d4 - <rustc_codegen_llvm[36c236d002db6048]::context::CodegenCx as rustc_middle[7d4f75877793c8e4]::ty::layout::FnAbiOfHelpers>::handle_fn_abi_err
  18:        0x10c0bdd60 - <rustc_codegen_llvm[36c236d002db6048]::context::CodegenCx as rustc_middle[7d4f75877793c8e4]::ty::layout::FnAbiOf>::fn_abi_of_instance::{closure#0}
  19:        0x10c0ca760 - <rustc_codegen_llvm[36c236d002db6048]::context::CodegenCx as rustc_codegen_ssa[be5c3ef9ac00adbb]::traits::declare::PreDefineCodegenMethods>::predefine_fn
  20:        0x10c0b9110 - rustc_codegen_llvm[36c236d002db6048]::base::compile_codegen_unit::module_codegen
  21:        0x10c0b8804 - rustc_codegen_llvm[36c236d002db6048]::base::compile_codegen_unit
  22:        0x10c137078 - rustc_codegen_ssa[be5c3ef9ac00adbb]::base::codegen_crate::<rustc_codegen_llvm[36c236d002db6048]::LlvmCodegenBackend>
  23:        0x10c1cacf4 - <rustc_codegen_llvm[36c236d002db6048]::LlvmCodegenBackend as rustc_codegen_ssa[be5c3ef9ac00adbb]::traits::backend::CodegenBackend>::codegen_crate
  24:        0x10cd23e60 - <rustc_session[828553cc4c1b3304]::session::Session>::time::<alloc[33d0a6a508eb5932]::boxed::Box<dyn core[ef7e3446cee7ff23]::any::Any>, rustc_interface[fed0365793385749]::passes::start_codegen::{closure#0}>
  25:        0x10cdaa890 - rustc_interface[fed0365793385749]::passes::start_codegen
  26:        0x10cd4f0d0 - <rustc_interface[fed0365793385749]::queries::Linker>::codegen_and_build_linker
  27:        0x10c480764 - <rustc_middle[7d4f75877793c8e4]::ty::context::GlobalCtxt>::enter::<rustc_driver_impl[c0574d6a9003aa16]::run_compiler::{closure#0}::{closure#1}::{closure#6}, core[ef7e3446cee7ff23]::result::Result<core[ef7e3446cee7ff23]::option::Option<rustc_interface[fed0365793385749]::queries::Linker>, rustc_span[a9b61c9ba68f3314]::ErrorGuaranteed>>
  28:        0x10c45239c - <rustc_interface[fed0365793385749]::interface::Compiler>::enter::<rustc_driver_impl[c0574d6a9003aa16]::run_compiler::{closure#0}::{closure#1}, core[ef7e3446cee7ff23]::result::Result<core[ef7e3446cee7ff23]::option::Option<rustc_interface[fed0365793385749]::queries::Linker>, rustc_span[a9b61c9ba68f3314]::ErrorGuaranteed>>
  29:        0x10c49a5dc - rustc_span[a9b61c9ba68f3314]::create_session_globals_then::<core[ef7e3446cee7ff23]::result::Result<(), rustc_span[a9b61c9ba68f3314]::ErrorGuaranteed>, rustc_interface[fed0365793385749]::util::run_in_thread_with_globals<rustc_interface[fed0365793385749]::util::run_in_thread_pool_with_globals<rustc_interface[fed0365793385749]::interface::run_compiler<core[ef7e3446cee7ff23]::result::Result<(), rustc_span[a9b61c9ba68f3314]::ErrorGuaranteed>, rustc_driver_impl[c0574d6a9003aa16]::run_compiler::{closure#0}>::{closure#1}, core[ef7e3446cee7ff23]::result::Result<(), rustc_span[a9b61c9ba68f3314]::ErrorGuaranteed>>::{closure#0}, core[ef7e3446cee7ff23]::result::Result<(), rustc_span[a9b61c9ba68f3314]::ErrorGuaranteed>>::{closure#0}::{closure#0}::{closure#0}>
  30:        0x10c4820b8 - std[5d2d2d2a3de07169]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[fed0365793385749]::util::run_in_thread_with_globals<rustc_interface[fed0365793385749]::util::run_in_thread_pool_with_globals<rustc_interface[fed0365793385749]::interface::run_compiler<core[ef7e3446cee7ff23]::result::Result<(), rustc_span[a9b61c9ba68f3314]::ErrorGuaranteed>, rustc_driver_impl[c0574d6a9003aa16]::run_compiler::{closure#0}>::{closure#1}, core[ef7e3446cee7ff23]::result::Result<(), rustc_span[a9b61c9ba68f3314]::ErrorGuaranteed>>::{closure#0}, core[ef7e3446cee7ff23]::result::Result<(), rustc_span[a9b61c9ba68f3314]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[ef7e3446cee7ff23]::result::Result<(), rustc_span[a9b61c9ba68f3314]::ErrorGuaranteed>>
  31:        0x10c477eb8 - <<std[5d2d2d2a3de07169]::thread::Builder>::spawn_unchecked_<rustc_interface[fed0365793385749]::util::run_in_thread_with_globals<rustc_interface[fed0365793385749]::util::run_in_thread_pool_with_globals<rustc_interface[fed0365793385749]::interface::run_compiler<core[ef7e3446cee7ff23]::result::Result<(), rustc_span[a9b61c9ba68f3314]::ErrorGuaranteed>, rustc_driver_impl[c0574d6a9003aa16]::run_compiler::{closure#0}>::{closure#1}, core[ef7e3446cee7ff23]::result::Result<(), rustc_span[a9b61c9ba68f3314]::ErrorGuaranteed>>::{closure#0}, core[ef7e3446cee7ff23]::result::Result<(), rustc_span[a9b61c9ba68f3314]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[ef7e3446cee7ff23]::result::Result<(), rustc_span[a9b61c9ba68f3314]::ErrorGuaranteed>>::{closure#1} as core[ef7e3446cee7ff23]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  32:        0x10e558d2c - std::sys::pal::unix::thread::Thread::new::thread_start::h89c74db28defaaab
  33:        0x19fe5af94 - __pthread_joiner_wake

@spookyvision spookyvision 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 Oct 8, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 8, 2024
@spookyvision spookyvision changed the title ICE with unboxed async fn recursion nightly ICE with unboxed async fn recursion Oct 8, 2024
@matthiaskrgr
Copy link
Member

probably duplicate of #118603

@spookyvision
Copy link
Contributor Author

spookyvision commented Oct 8, 2024

probably duplicate of #118603

the backtrace doesn't look identical, and neither does the repro, but that's all I can really say
edit: nevermind, missed the fn_abi_of_instance line in my output

jieyouxu added a commit to jieyouxu/rust that referenced this issue Oct 9, 2024
…ycle, r=wesleywiser

Dont ICE when encountering post-mono layout cycle error

It's possible to encounter post-mono layout cycle errors in `fn_abi_of_instance`. Don't ICE in those cases.

This was originally discovered in an async fn, but that's not the only way to encounter such an error (which the other test I added should demonstrate).

Error messsages suck, but this fix is purely about suppressing the ICE.

Fixes rust-lang#131409
@bors bors closed this as completed in f144469 Oct 10, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Oct 10, 2024
Rollup merge of rust-lang#131420 - compiler-errors:post-mono-layout-cycle, r=wesleywiser

Dont ICE when encountering post-mono layout cycle error

It's possible to encounter post-mono layout cycle errors in `fn_abi_of_instance`. Don't ICE in those cases.

This was originally discovered in an async fn, but that's not the only way to encounter such an error (which the other test I added should demonstrate).

Error messsages suck, but this fix is purely about suppressing the ICE.

Fixes rust-lang#131409
@jieyouxu jieyouxu removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants