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

Const generics: internal compiler error: collection encountered polymorphic constant #62187

Closed
is8ac opened this issue Jun 27, 2019 · 7 comments
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-const_generics `#![feature(const_generics)]` 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

@is8ac
Copy link

is8ac commented Jun 27, 2019

Source:

#![feature(const_generics)]

pub trait BitLen: Sized {
    const BIT_LEN: usize;
}

impl<const L: usize> BitLen for [u8; L] {
    const BIT_LEN: usize = 8 * L;
}

fn main() {
    let foo = <[u8; 2]>::BIT_LEN;
}

Panic:

error: internal compiler error: src/librustc_mir/monomorphize/collector.rs:1289: collection encountered polymorphic constant
 --> src/bin/bitlen_demo.rs:4:5
  |
4 |     const BIT_LEN: usize;
  |     ^^^^^^^^^^^^^^^^^^^^^

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:585:9
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.29/src/backtrace/libunwind.rs:88
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.29/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:198
   5: std::panicking::default_hook
             at src/libstd/panicking.rs:212
   6: rustc::util::common::panic_hook
   7: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:479
   8: std::panicking::begin_panic
   9: rustc_errors::Handler::span_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::span_bug_fmt
  16: rustc_mir::monomorphize::collector::collect_const
  17: <rustc_mir::monomorphize::collector::MirNeighborCollector as rustc::mir::visit::Visitor>::visit_rvalue
  18: rustc_mir::monomorphize::collector::collect_items_rec
  19: rustc_mir::monomorphize::collector::collect_crate_mono_items::{{closure}}
  20: rustc::util::common::time
  21: rustc_mir::monomorphize::collector::collect_crate_mono_items
  22: rustc::util::common::time
  23: rustc_mir::monomorphize::partitioning::collect_and_partition_mono_items
  24: rustc::ty::query::__query_compute::collect_and_partition_mono_items
  25: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::collect_and_partition_mono_items>::compute
  26: rustc::dep_graph::graph::DepGraph::with_task_impl
  27: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  28: rustc_codegen_ssa::base::codegen_crate
  29: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_utils::codegen_backend::CodegenBackend>::codegen_crate
  30: rustc::util::common::time
  31: rustc_interface::passes::start_codegen
  32: rustc::ty::context::tls::enter_global
  33: rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}
  34: rustc_interface::passes::create_global_ctxt::{{closure}}
  35: rustc_interface::passes::BoxedGlobalCtxt::enter
  36: rustc_interface::queries::Query<T>::compute
  37: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::ongoing_codegen
  38: rustc_interface::interface::run_compiler_in_existing_thread_pool
  39: std::thread::local::LocalKey<T>::with
  40: scoped_tls::ScopedKey<T>::set
  41: syntax::with_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
query stack during panic:
#0 [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 (d3e2cec29 2019-06-26) running on x86_64-unknown-linux-gnu

note: compiler flags: -C debuginfo=2 -C incremental --crate-type bin

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

error: Could not compile `const_generics_demo`.

Caused by:
  process didn't exit successfully: `rustc --edition=2018 --crate-name bitlen_demo src/bin/bitlen_demo.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=aa6088263213b6e1 -C extra-filename=-aa6088263213b6e1 --out-dir /home/isaac/go/src/github.com/is8ac/const_generics_demo/target/debug/deps -C incremental=/home/isaac/go/src/github.com/is8ac/const_generics_demo/target/debug/incremental -L dependency=/home/isaac/go/src/github.com/is8ac/const_generics_demo/target/debug/deps` (exit code: 101)

Meta

[isaac@d6-arch const_generics_demo]$ rustc --version --verbose
rustc 1.37.0-nightly (d3e2cec29 2019-06-26)
binary: rustc
commit-hash: d3e2cec29225a46298ec4ebf082f34ebd7cfeecf
commit-date: 2019-06-26
host: x86_64-unknown-linux-gnu
release: 1.37.0-nightly
LLVM version: 8.0
@jonas-schievink jonas-schievink added A-const-generics Area: const generics (parameters and arguments) 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 Jun 27, 2019
@shamatar
Copy link
Contributor

Same is valid for traits (abstract incomplete example)

pub trait FullMultiplication {
    type Multiplicand;
    type MulResult;
}

impl<const N: usize> FullMultiplication for BigintRepresentation<{N}> 
{
    type Multiplicand = BigintRepresentation<{N}>;
    type MulResult = BigintRepresentation<{N*2}>;
}

@vadixidav
Copy link
Contributor

Also encountered this issue here.

@Centril Centril added requires-nightly This issue requires a nightly compiler in some way. F-const_generics `#![feature(const_generics)]` labels Aug 6, 2019
@alex
Copy link
Member

alex commented Aug 11, 2019

Does anyone have a sense of what would be involved in fixing this?

@JohnTitor
Copy link
Member

JohnTitor commented Oct 4, 2019

Cannot see the ICE with the above example on latest nightly (playground)

@tesuji
Copy link
Contributor

tesuji commented Oct 4, 2019

Should we add a regression test for this (and #62536)?

@Mark-Simulacrum
Copy link
Member

I think we'll worry more about tests as we head towards more effective const generics; right now I think it's not really in a state where tests would be super helpful. cc @varkor though

@varkor
Copy link
Member

varkor commented Oct 7, 2019

Although we know a lot isn't working with const generics, I'd really like to expand the test suite, so it's more comprehensive as we move towards stabilisation. Let's try to add regression tests where possible. I'll add one for this issue and #62536.

tmandry added a commit to tmandry/rust that referenced this issue Oct 11, 2019
…=nikomatsakis

Add some regression tests

- Add a test for rust-lang#62187.
- Clean up the directory structure in `src/test/ui/const-generics`
- Closes rust-lang#64792.
- Closes rust-lang#57399.
- Closes rust-lang#57271.
tmandry added a commit to tmandry/rust that referenced this issue Oct 11, 2019
…=nikomatsakis

Add some regression tests

- Add a test for rust-lang#62187.
- Clean up the directory structure in `src/test/ui/const-generics`
- Closes rust-lang#64792.
- Closes rust-lang#57399.
- Closes rust-lang#57271.
Centril added a commit to Centril/rust that referenced this issue Oct 11, 2019
…=nikomatsakis

Add some regression tests

- Add a test for rust-lang#62187.
- Clean up the directory structure in `src/test/ui/const-generics`
- Closes rust-lang#64792.
- Closes rust-lang#57399.
- Closes rust-lang#57271.
tmandry added a commit to tmandry/rust that referenced this issue Oct 11, 2019
…=nikomatsakis

Add some regression tests

- Add a test for rust-lang#62187.
- Clean up the directory structure in `src/test/ui/const-generics`
- Closes rust-lang#64792.
- Closes rust-lang#57399.
- Closes rust-lang#57271.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-const_generics `#![feature(const_generics)]` 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

No branches or pull requests

10 participants