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

type metadata for unique ID is already in the TypeMap! #109464

Closed
balliegojr opened this issue Mar 21, 2023 · 2 comments · Fixed by #113108
Closed

type metadata for unique ID is already in the TypeMap! #109464

balliegojr opened this issue Mar 21, 2023 · 2 comments · Fixed by #113108
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. F-async_fn_in_trait Static async fn in traits 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

@balliegojr
Copy link

Code

Link for the playground

#![allow(incomplete_features)]
#![feature(async_fn_in_trait)]

#[derive(Clone, Copy)]
pub struct SharedState {}

pub trait State {
    async fn execute(self, shared_state: &SharedState);
}

pub trait StateComposer {
    fn and_then<T, F>(self, map_fn: F) -> AndThen<Self, F>
    where
        Self: State + Sized,
        T: State,
        F: FnOnce() -> T,
    {
        AndThen {
            previous: self,
            map_fn,
        }
    }
}

impl<T> StateComposer for T where T: State {}
pub struct AndThen<T, F> {
    previous: T,
    map_fn: F,
}

impl<T, U, F> State for AndThen<T, F>
where
    T: State,
    U: State,
    F: FnOnce() -> U,
{
    async fn execute(self, shared_state: &SharedState)
    where
        Self: Sized,
    {
        self.previous.execute(shared_state).await;
        (self.map_fn)().execute(shared_state).await
    }
}

pub struct SomeState {}

impl State for SomeState {
    async fn execute(self, shared_state: &SharedState) {}
}

pub fn main() {
    let shared_state = SharedState {};
    async {
        SomeState {}
            .and_then(|| SomeState {})
            .and_then(|| SomeState {})
            .execute(&shared_state)
            .await;
    };
}

Meta

rustc --version --verbose:

binary: rustc
commit-hash: 44f5180584404d18058cbbf224c55255db4fdcbb
commit-date: 2023-03-20
host: x86_64-unknown-linux-gnu
release: 1.70.0-nightly
LLVM version: 15.0.7

Error output

   Compiling state-machine v0.1.0 (/home/junior/sources/playground/state-machine)
warning: unused variable: `shared_state`
  --> src/lib.rs:49:28
   |
49 |     async fn execute(self, shared_state: &SharedState) {}
   |                            ^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_shared_state`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: unused implementer of `Future` that must be used
  --> src/lib.rs:54:5
   |
54 | /     async {
55 | |         SomeState {}
56 | |             .and_then(|| SomeState {})
57 | |             .and_then(|| SomeState {})
58 | |             .execute(&shared_state)
59 | |             .await;
60 | |     };
   | |_____^
   |
   = note: futures do nothing unless you `.await` or poll them
   = note: `#[warn(unused_must_use)]` on by default

error: internal compiler error: compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs:133:13: type metadata for unique ID 'VariantStructType([async fn body@src/lib.rs:40:5: 43:6], 0, HiddenZst)' is already in the `TypeMap`!

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/44f5180584404d18058cbbf224c55255db4fdcbb/compiler/rustc_errors/src/lib.rs:1644:9
stack backtrace:
   0:     0x7f2e3ab66bfa - std::backtrace_rs::backtrace::libunwind::trace::h02b863e4bfcd5ee4
                               at /rustc/44f5180584404d18058cbbf224c55255db4fdcbb/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f2e3ab66bfa - std::backtrace_rs::backtrace::trace_unsynchronized::h00a2c275504a104d
                               at /rustc/44f5180584404d18058cbbf224c55255db4fdcbb/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f2e3ab66bfa - std::sys_common::backtrace::_print_fmt::h026a22e05cf38896
                               at /rustc/44f5180584404d18058cbbf224c55255db4fdcbb/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x7f2e3ab66bfa - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h34a8f50cf2d025fa
                               at /rustc/44f5180584404d18058cbbf224c55255db4fdcbb/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f2e3abca21e - core::fmt::write::h5b51ab21f7d1e0b3
                               at /rustc/44f5180584404d18058cbbf224c55255db4fdcbb/library/core/src/fmt/mod.rs:1254:17
   5:     0x7f2e3ab59a85 - std::io::Write::write_fmt::hf4fa62cadc893d5c
                               at /rustc/44f5180584404d18058cbbf224c55255db4fdcbb/library/std/src/io/mod.rs:1698:15
   6:     0x7f2e3ab669c5 - std::sys_common::backtrace::_print::ha17a326a77d0900c
                               at /rustc/44f5180584404d18058cbbf224c55255db4fdcbb/library/std/src/sys_common/backtrace.rs:47:5
   7:     0x7f2e3ab669c5 - std::sys_common::backtrace::print::h4547d3fae20fb79a
                               at /rustc/44f5180584404d18058cbbf224c55255db4fdcbb/library/std/src/sys_common/backtrace.rs:34:9
   8:     0x7f2e3ab6973f - std::panicking::default_hook::{{closure}}::hc37cfbcbf13dea2f
                               at /rustc/44f5180584404d18058cbbf224c55255db4fdcbb/library/std/src/panicking.rs:271:22
   9:     0x7f2e3ab6947b - std::panicking::default_hook::h68329187d8716430
                               at /rustc/44f5180584404d18058cbbf224c55255db4fdcbb/library/std/src/panicking.rs:290:9
  10:     0x7f2e3ddb53f5 - <rustc_driver_impl[e865fcce65453e97]::DEFAULT_HOOK::{closure#0}::{closure#0} as core[e92a6e72e88848e6]::ops::function::FnOnce<(&core[e92a6e72e88848e6]::panic::panic_info::PanicInfo,)>>::call_once::{shim:vtable#0}
  11:     0x7f2e3ab69f7d - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::he6b1b104583416f4
                               at /rustc/44f5180584404d18058cbbf224c55255db4fdcbb/library/alloc/src/boxed.rs:2002:9
  12:     0x7f2e3ab69f7d - std::panicking::rust_panic_with_hook::h89588635866984f2
                               at /rustc/44f5180584404d18058cbbf224c55255db4fdcbb/library/std/src/panicking.rs:696:13
  13:     0x7f2e3e2eeb71 - std[f90515c7d1e58fcd]::panicking::begin_panic::<rustc_errors[1d3726326fe117a6]::ExplicitBug>::{closure#0}
  14:     0x7f2e3e2ec606 - std[f90515c7d1e58fcd]::sys_common::backtrace::__rust_end_short_backtrace::<std[f90515c7d1e58fcd]::panicking::begin_panic<rustc_errors[1d3726326fe117a6]::ExplicitBug>::{closure#0}, !>
  15:     0x7f2e3e302796 - std[f90515c7d1e58fcd]::panicking::begin_panic::<rustc_errors[1d3726326fe117a6]::ExplicitBug>
  16:     0x7f2e3e364b76 - std[f90515c7d1e58fcd]::panic::panic_any::<rustc_errors[1d3726326fe117a6]::ExplicitBug>
  17:     0x7f2e3e3624c6 - <rustc_errors[1d3726326fe117a6]::HandlerInner>::bug::<&alloc[8437dea91522f7f5]::string::String>
  18:     0x7f2e3e362190 - <rustc_errors[1d3726326fe117a6]::Handler>::bug::<&alloc[8437dea91522f7f5]::string::String>
  19:     0x7f2e3e35a4fb - rustc_middle[20900d4515e9a17b]::util::bug::opt_span_bug_fmt::<rustc_span[f138f19c2ce8dad]::span_encoding::Span>::{closure#0}
  20:     0x7f2e3e358f4a - rustc_middle[20900d4515e9a17b]::ty::context::tls::with_opt::<rustc_middle[20900d4515e9a17b]::util::bug::opt_span_bug_fmt<rustc_span[f138f19c2ce8dad]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  21:     0x7f2e3e358f16 - rustc_middle[20900d4515e9a17b]::ty::context::tls::with_context_opt::<rustc_middle[20900d4515e9a17b]::ty::context::tls::with_opt<rustc_middle[20900d4515e9a17b]::util::bug::opt_span_bug_fmt<rustc_span[f138f19c2ce8dad]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  22:     0x7f2e3e35a446 - rustc_middle[20900d4515e9a17b]::util::bug::opt_span_bug_fmt::<rustc_span[f138f19c2ce8dad]::span_encoding::Span>
  23:     0x7f2e3c45ae73 - rustc_middle[20900d4515e9a17b]::util::bug::bug_fmt
  24:     0x7f2e3c49ace2 - <rustc_codegen_llvm[9e46d5c92cfccab3]::debuginfo::metadata::type_map::TypeMap>::insert
  25:     0x7f2e3dc89ce6 - rustc_codegen_llvm[9e46d5c92cfccab3]::debuginfo::metadata::type_map::build_type_with_children::<rustc_codegen_llvm[9e46d5c92cfccab3]::debuginfo::metadata::enums::build_generator_variant_struct_type_di_node::{closure#0}, rustc_codegen_llvm[9e46d5c92cfccab3]::debuginfo::metadata::enums::build_generator_variant_struct_type_di_node::{closure#1}>
  26:     0x7f2e3dc30137 - rustc_codegen_llvm[9e46d5c92cfccab3]::debuginfo::metadata::enums::build_generator_variant_struct_type_di_node
  27:     0x7f2e3dc67b27 - <&mut rustc_codegen_llvm[9e46d5c92cfccab3]::debuginfo::metadata::enums::native::build_generator_di_node::{closure#0}::{closure#0} as core[e92a6e72e88848e6]::ops::function::FnOnce<(rustc_abi[e976117ca395acc5]::VariantIdx,)>>::call_once
  28:     0x7f2e3dc7b374 - <smallvec[549b52ff25e33a5d]::SmallVec<[rustc_codegen_llvm[9e46d5c92cfccab3]::debuginfo::metadata::enums::native::VariantMemberInfo; 16usize]> as core[e92a6e72e88848e6]::iter::traits::collect::Extend<<[rustc_codegen_llvm[9e46d5c92cfccab3]::debuginfo::metadata::enums::native::VariantMemberInfo; 16usize] as smallvec[549b52ff25e33a5d]::Array>::Item>>::extend::<core[e92a6e72e88848e6]::iter::adapters::map::Map<core[e92a6e72e88848e6]::iter::adapters::map::Map<core[e92a6e72e88848e6]::ops::range::Range<usize>, <rustc_index[32b293d781f6f491]::vec::IndexVec<rustc_abi[e976117ca395acc5]::VariantIdx, rustc_abi[e976117ca395acc5]::LayoutS>>::indices::{closure#0}>, rustc_codegen_llvm[9e46d5c92cfccab3]::debuginfo::metadata::enums::native::build_generator_di_node::{closure#0}::{closure#0}>>
  29:     0x7f2e3dc8a4e4 - rustc_codegen_llvm[9e46d5c92cfccab3]::debuginfo::metadata::type_map::build_type_with_children::<rustc_codegen_llvm[9e46d5c92cfccab3]::debuginfo::metadata::enums::native::build_generator_di_node::{closure#0}, for<'a, 'b, 'c> fn(&'a rustc_codegen_llvm[9e46d5c92cfccab3]::context::CodegenCx<'b, 'c>) -> smallvec[549b52ff25e33a5d]::SmallVec<[&'b rustc_codegen_llvm[9e46d5c92cfccab3]::llvm_::ffi::Metadata; 16usize]>>
  30:     0x7f2e3dc68bac - rustc_codegen_llvm[9e46d5c92cfccab3]::debuginfo::metadata::enums::native::build_generator_di_node
  31:     0x7f2e3dc2f97f - rustc_codegen_llvm[9e46d5c92cfccab3]::debuginfo::metadata::enums::build_generator_di_node
  32:     0x7f2e3c38b138 - rustc_codegen_llvm[9e46d5c92cfccab3]::debuginfo::metadata::type_di_node
  33:     0x7f2e3c627c9e - <rustc_codegen_llvm[9e46d5c92cfccab3]::context::CodegenCx as rustc_codegen_ssa[63d5a3cdf69e7e7e]::traits::debuginfo::DebugInfoMethods>::create_dbg_var
  34:     0x7f2e3c60c59a - rustc_codegen_ssa[63d5a3cdf69e7e7e]::mir::codegen_mir::<rustc_codegen_llvm[9e46d5c92cfccab3]::builder::Builder>
  35:     0x7f2e3d2e36f3 - rustc_codegen_llvm[9e46d5c92cfccab3]::base::compile_codegen_unit::module_codegen
  36:     0x7f2e3d2e1907 - <rustc_codegen_llvm[9e46d5c92cfccab3]::LlvmCodegenBackend as rustc_codegen_ssa[63d5a3cdf69e7e7e]::traits::backend::ExtraBackendMethods>::compile_codegen_unit
  37:     0x7f2e3d2dfcb4 - rustc_codegen_ssa[63d5a3cdf69e7e7e]::base::codegen_crate::<rustc_codegen_llvm[9e46d5c92cfccab3]::LlvmCodegenBackend>
  38:     0x7f2e3d2df5de - <rustc_codegen_llvm[9e46d5c92cfccab3]::LlvmCodegenBackend as rustc_codegen_ssa[63d5a3cdf69e7e7e]::traits::backend::CodegenBackend>::codegen_crate
  39:     0x7f2e3cfb9251 - <rustc_session[ae3e11cc9a6ced82]::session::Session>::time::<alloc[8437dea91522f7f5]::boxed::Box<dyn core[e92a6e72e88848e6]::any::Any>, rustc_interface[cef7fd7d041aab20]::passes::start_codegen::{closure#0}>
  40:     0x7f2e3cfb8d79 - rustc_interface[cef7fd7d041aab20]::passes::start_codegen
  41:     0x7f2e3cfb5aa8 - <rustc_middle[20900d4515e9a17b]::ty::context::GlobalCtxt>::enter::<<rustc_interface[cef7fd7d041aab20]::queries::Queries>::ongoing_codegen::{closure#0}::{closure#0}, core[e92a6e72e88848e6]::result::Result<alloc[8437dea91522f7f5]::boxed::Box<dyn core[e92a6e72e88848e6]::any::Any>, rustc_span[f138f19c2ce8dad]::ErrorGuaranteed>>
  42:     0x7f2e3cfb4004 - <rustc_interface[cef7fd7d041aab20]::queries::Queries>::ongoing_codegen
  43:     0x7f2e3cfb35d1 - <rustc_interface[cef7fd7d041aab20]::interface::Compiler>::enter::<rustc_driver_impl[e865fcce65453e97]::run_compiler::{closure#1}::{closure#2}, core[e92a6e72e88848e6]::result::Result<core[e92a6e72e88848e6]::option::Option<rustc_interface[cef7fd7d041aab20]::queries::Linker>, rustc_span[f138f19c2ce8dad]::ErrorGuaranteed>>
  44:     0x7f2e3cfb16a0 - rustc_span[f138f19c2ce8dad]::with_source_map::<core[e92a6e72e88848e6]::result::Result<(), rustc_span[f138f19c2ce8dad]::ErrorGuaranteed>, rustc_interface[cef7fd7d041aab20]::interface::run_compiler<core[e92a6e72e88848e6]::result::Result<(), rustc_span[f138f19c2ce8dad]::ErrorGuaranteed>, rustc_driver_impl[e865fcce65453e97]::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
  45:     0x7f2e3cfb0c49 - std[f90515c7d1e58fcd]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[cef7fd7d041aab20]::util::run_in_thread_pool_with_globals<rustc_interface[cef7fd7d041aab20]::interface::run_compiler<core[e92a6e72e88848e6]::result::Result<(), rustc_span[f138f19c2ce8dad]::ErrorGuaranteed>, rustc_driver_impl[e865fcce65453e97]::run_compiler::{closure#1}>::{closure#0}, core[e92a6e72e88848e6]::result::Result<(), rustc_span[f138f19c2ce8dad]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[e92a6e72e88848e6]::result::Result<(), rustc_span[f138f19c2ce8dad]::ErrorGuaranteed>>
  46:     0x7f2e3d6a2eda - <<std[f90515c7d1e58fcd]::thread::Builder>::spawn_unchecked_<rustc_interface[cef7fd7d041aab20]::util::run_in_thread_pool_with_globals<rustc_interface[cef7fd7d041aab20]::interface::run_compiler<core[e92a6e72e88848e6]::result::Result<(), rustc_span[f138f19c2ce8dad]::ErrorGuaranteed>, rustc_driver_impl[e865fcce65453e97]::run_compiler::{closure#1}>::{closure#0}, core[e92a6e72e88848e6]::result::Result<(), rustc_span[f138f19c2ce8dad]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[e92a6e72e88848e6]::result::Result<(), rustc_span[f138f19c2ce8dad]::ErrorGuaranteed>>::{closure#1} as core[e92a6e72e88848e6]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  47:     0x7f2e3ab73e53 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h75ab31ff38cd6fd4
                               at /rustc/44f5180584404d18058cbbf224c55255db4fdcbb/library/alloc/src/boxed.rs:1988:9
  48:     0x7f2e3ab73e53 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h2ba977e91260a719
                               at /rustc/44f5180584404d18058cbbf224c55255db4fdcbb/library/alloc/src/boxed.rs:1988:9
  49:     0x7f2e3ab73e53 - std::sys::unix::thread::Thread::new::thread_start::h132d174660c69668
                               at /rustc/44f5180584404d18058cbbf224c55255db4fdcbb/library/std/src/sys/unix/thread.rs:108:17
  50:     0x7f2e3a908bb5 - <unknown>
  51:     0x7f2e3a98ad90 - <unknown>
  52:                0x0 - <unknown>

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: rustc 1.70.0-nightly (44f518058 2023-03-20) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type lib -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]

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

query stack during panic:
end of query stack

Observation

The error does not happen with any of the 3 changes bellow

  • Remove the async keyword
  • Remove the SharedState parameter from the trait function
  • Add the type constraint to AndThen struct
pub struct AndThen<T, U, F>
where
    T: State,
    U: State,
    F: FnOnce() -> U,
{
    previous: T,
    map_fn: F,
}
@balliegojr balliegojr 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 Mar 21, 2023
@clubby789
Copy link
Contributor

clubby789 commented Mar 21, 2023

@rustbot label +A-llvm +A-debuginfo +F-async_fn_in_trait
Requires -Cdebuginfo=2 and --edition=2021 to reproduce

As far as I can tell this has caused an ICE since it was introduced in #101224


With debug assertions, this fails a bit earlier:

thread 'rustc' panicked at 'assertion failed: `(left == right)`
  left: `[async fn body@src/main.rs:40:5: 43:6]`,
 right: `[async fn body@src/main.rs:40:5: 43:6]`', compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs:58:9
stack backtrace:

@rustbot rustbot added A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. F-async_fn_in_trait Static async fn in traits labels Mar 22, 2023
@compiler-errors
Copy link
Member

This should be fixed by #107620, if that ever lands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. F-async_fn_in_trait Static async fn in traits 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
4 participants