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 using min_type_alias_impl_trait with generators #87142

Closed
WorldSEnder opened this issue Jul 14, 2021 · 1 comment · Fixed by #97731
Closed

ICE using min_type_alias_impl_trait with generators #87142

WorldSEnder opened this issue Jul 14, 2021 · 1 comment · Fixed by #97731
Labels
A-coroutines Area: Coroutines C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. F-coroutines `#![feature(coroutines)]` F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` glacier ICE tracked in rust-lang/glacier. 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

@WorldSEnder
Copy link

WorldSEnder commented Jul 14, 2021

Code

#![feature(min_type_alias_impl_trait, generator_trait, generators)]
use std::ops::{Generator};

pub trait GeneratorProviderAlt: Sized {
    type Gen: Generator<(), Return=(), Yield=()>;

    fn start(ctx: Context<Self>) -> Self::Gen;
}

pub struct Context<G: 'static + GeneratorProviderAlt> {
    // back-link to our generator state
    // In reality some other pointer type, but Box triggers the bug
    // Also in reality, points to a wrapper struct that only indirectly holds
    //   the generator state.
    link: Box<G::Gen>,
}

impl GeneratorProviderAlt for () {
    type Gen = impl Generator<(), Return=(), Yield=()>;
    fn start(ctx: Context<Self>) -> Self::Gen {
        move || {
            match ctx { _ => () } // make sure to use the context
            yield ();
        }
    }
}

playground link

I haven't gotten it to error without nightly features, so I believe it has to do with the generated enum for the Generator.

Meta

rustc --version --verbose:

rustc 1.55.0-nightly (952fdf2a1 2021-07-05)
binary: rustc
commit-hash: 952fdf2a1119affa1b37bcacb0c49cf9f0168ac8
commit-date: 2021-07-05
host: x86_64-unknown-linux-gnu
release: 1.55.0-nightly
LLVM version: 12.0.1

Error output

error: internal compiler error: compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs:150:13: type metadata for unique ID '324a3be6bacbf95688e06d88c8981eb0' is already in the `TypeMap`!
Backtrace

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1034:9
stack backtrace:
   0: std::panicking::begin_panic
   1: std::panic::panic_any
   2: rustc_errors::HandlerInner::bug
   3: rustc_errors::Handler::bug
   4: rustc_middle::ty::context::tls::with_opt
   5: rustc_middle::util::bug::opt_span_bug_fmt
   6: rustc_middle::util::bug::bug_fmt
   7: rustc_codegen_llvm::debuginfo::metadata::create_and_register_recursive_type_forward_declaration
   8: rustc_codegen_llvm::debuginfo::metadata::prepare_enum_metadata
   9: rustc_codegen_llvm::debuginfo::metadata::type_metadata
  10: rustc_codegen_llvm::debuginfo::<impl rustc_codegen_ssa::traits::debuginfo::DebugInfoMethods for rustc_codegen_llvm::context::CodegenCx>::dbg_scope_fn::get_function_signature
  11: rustc_codegen_llvm::debuginfo::<impl rustc_codegen_ssa::traits::debuginfo::DebugInfoMethods for rustc_codegen_llvm::context::CodegenCx>::dbg_scope_fn
  12: rustc_codegen_ssa::mir::codegen_mir
  13: rustc_codegen_ssa::base::codegen_instance
  14: <rustc_middle::mir::mono::MonoItem as rustc_codegen_ssa::mono_item::MonoItemExt>::define
  15: rustc_codegen_llvm::base::compile_codegen_unit::module_codegen
  16: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
  17: rustc_codegen_llvm::base::compile_codegen_unit
  18: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
  19: rustc_interface::passes::QueryContext::enter
  20: rustc_interface::queries::Queries::ongoing_codegen
  21: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  22: rustc_span::with_source_map
  23: rustc_interface::interface::create_compiler_and_run
  24: scoped_tls::ScopedKey<T>::set


As an aside, if one gets rid of the Box, this fails (kind of expected, though the error message could be improved) with

error[E0391]: cycle detected when computing layout of `[generator@src/lib.rs:21:9: 24:10]`
   |
   = note: ...which requires computing layout of `Context<()>`...
   = note: ...which again requires computing layout of `[generator@src/lib.rs:21:9: 24:10]`, completing the cycle
note: cycle used when optimizing MIR for `<impl at src/lib.rs:18:1: 26:2>::start`
  --> src/lib.rs:20:5
@WorldSEnder WorldSEnder 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 Jul 14, 2021
@jonas-schievink jonas-schievink added A-coroutines Area: Coroutines F-min_type_alias_impl_trait F-coroutines `#![feature(coroutines)]` labels Jul 14, 2021
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Aug 12, 2021
@Alexendoo
Copy link
Member

No longer ICEs since #94261

@Alexendoo Alexendoo added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Mar 16, 2022
@oli-obk oli-obk added F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` and removed F-min_type_alias_impl_trait labels Mar 30, 2022
JohnTitor added a commit to JohnTitor/rust that referenced this issue Jun 4, 2022
bors added a commit to rust-lang-ci/rust that referenced this issue Jun 4, 2022
…askrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#97609 (Iterate over `maybe_unused_trait_imports` when checking dead trait imports)
 - rust-lang#97688 (test const_copy to make sure bytewise pointer copies are working)
 - rust-lang#97707 (Improve soundness of rustc_data_structures)
 - rust-lang#97731 (Add regresion test for rust-lang#87142)
 - rust-lang#97735 (Don't generate "Impls on Foreign Types" for std)
 - rust-lang#97737 (Fix pretty printing named bound regions under -Zverbose)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors closed this as completed in c857265 Jun 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-coroutines Area: Coroutines C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. F-coroutines `#![feature(coroutines)]` F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` glacier ICE tracked in rust-lang/glacier. 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.
Development

Successfully merging a pull request may close this issue.

5 participants