Skip to content

ICE when using const evaluation #71202

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
burtonageo opened this issue Apr 16, 2020 · 3 comments · Fixed by #81566
Closed

ICE when using const evaluation #71202

burtonageo opened this issue Apr 16, 2020 · 3 comments · Fixed by #81566
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) A-const-generics Area: const generics (parameters and arguments) 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. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@burtonageo
Copy link
Contributor

burtonageo commented Apr 16, 2020

Code

Playground link

use std::marker::PhantomData;

struct DataHolder<T> {
    item: T,
}

impl<T: Copy> DataHolder<T> {
    const ITEM_IS_COPY: [(); 1 - {
        trait NotCopy {
            const VALUE: bool = false;
        }

        impl<__Type: ?Sized> NotCopy for __Type {}

        struct IsCopy<__Type: ?Sized>(PhantomData<__Type>);

        impl<__Type> IsCopy<__Type>
        where
            __Type: Sized + Copy,
        {
            const VALUE: bool = true;
        }

        <IsCopy<T>>::VALUE
    } as usize] = [];
} 

fn main() {}

Meta

rustc --version --verbose:

rustc 1.44.0-nightly (d2230290f 2020-04-15)
binary: rustc
commit-hash: d2230290f7220e740ec08f4d844bf5951e1b74b8
commit-date: 2020-04-15
host: x86_64-apple-darwin
release: 1.44.0-nightly
LLVM version: 9.0

Error output

   Compiling playground v0.0.1 (/playground)
error: internal compiler error: src/librustc_middle/ty/subst.rs:573: type parameter `T/#0` (T/0) out of range when substituting (root type=Some(DataHolder<T>::ITEM_IS_COPY::{{constant}}#0::IsCopy<T>)) substs=[]

thread 'rustc' panicked at 'Box<Any>', /rustc/edc02580e4e80476ac1ded2cc1008eaf8b8400e6/src/libstd/macros.rs:13:23
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

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.44.0-nightly (edc02580e 2020-04-14) running on x86_64-unknown-linux-gnu

note: compiler flags: -C codegen-units=1 -C debuginfo=2 --crate-type bin

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

error: aborting due to previous error

error: could not compile `playground`.

To learn more, run the command again with --verbose.
Backtrace

   Compiling playground v0.0.1 (/playground)
error: internal compiler error: src/librustc_middle/ty/subst.rs:573: type parameter `T/#0` (T/0) out of range when substituting (root type=Some(DataHolder<T>::ITEM_IS_COPY::{{constant}}#0::IsCopy<T>)) substs=[]

thread 'rustc' panicked at 'Box<Any>', /rustc/edc02580e4e80476ac1ded2cc1008eaf8b8400e6/src/libstd/macros.rs:13:23
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.heygears.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/libunwind.rs:86
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.heygears.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:78
   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:1069
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1504
   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:198
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:218
  10: rustc_driver::report_ice
  11: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:515
  12: std::panicking::begin_panic
  13: rustc_errors::HandlerInner::span_bug
  14: rustc_errors::Handler::span_bug
  15: rustc_middle::util::bug::opt_span_bug_fmt::{{closure}}
  16: rustc_middle::ty::context::tls::with_opt::{{closure}}
  17: rustc_middle::ty::context::tls::with_opt
  18: rustc_middle::util::bug::opt_span_bug_fmt
  19: rustc_middle::util::bug::span_bug_fmt
  20: <rustc_middle::ty::subst::SubstFolder as rustc_middle::ty::fold::TypeFolder>::fold_ty
  21: rustc_middle::ty::fold::TypeFoldable::fold_with
  22: rustc_middle::ty::structural_impls::<impl rustc_middle::ty::fold::TypeFoldable for &rustc_middle::ty::TyS>::super_fold_with
  23: <rustc_middle::ty::subst::SubstFolder as rustc_middle::ty::fold::TypeFolder>::fold_ty
  24: rustc_middle::ty::fold::TypeFoldable::fold_with
  25: <rustc_middle::ty::subst::SubstFolder as rustc_middle::ty::fold::TypeFolder>::fold_const
  26: rustc_middle::ty::normalize_erasing_regions::<impl rustc_middle::ty::context::TyCtxt>::subst_and_normalize_erasing_regions
  27: rustc_mir::interpret::operand::<impl rustc_mir::interpret::eval_context::InterpCx<M>>::eval_operand
  28: rustc_mir::interpret::step::<impl rustc_mir::interpret::eval_context::InterpCx<M>>::eval_rvalue_into_place
  29: rustc_mir::interpret::step::<impl rustc_mir::interpret::eval_context::InterpCx<M>>::run
  30: rustc_mir::const_eval::eval_queries::const_eval_raw_provider
  31: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::const_eval_raw>::compute
  32: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  33: rustc_query_system::query::plumbing::get_query
  34: rustc_mir::const_eval::eval_queries::const_eval_validated_provider
  35: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::const_eval_validated>::compute
  36: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  37: rustc_query_system::query::plumbing::get_query
  38: rustc_mir::const_eval::eval_queries::const_eval_validated_provider
  39: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::const_eval_validated>::compute
  40: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  41: rustc_query_system::query::plumbing::get_query
  42: rustc_middle::mir::interpret::queries::<impl rustc_middle::ty::context::TyCtxt>::const_eval_resolve
  43: rustc_middle::ty::sty::Const::eval::{{closure}}
  44: <rustc_trait_selection::traits::project::AssocTypeNormalizer as rustc_middle::ty::fold::TypeFolder>::fold_const
  45: rustc_middle::ty::structural_impls::<impl rustc_middle::ty::fold::TypeFoldable for &rustc_middle::ty::TyS>::super_fold_with
  46: <rustc_trait_selection::traits::project::AssocTypeNormalizer as rustc_middle::ty::fold::TypeFolder>::fold_ty
  47: rustc_trait_selection::traits::project::normalize
  48: <rustc_infer::infer::InferCtxt as rustc_trait_selection::infer::InferCtxtExt>::partially_normalize_associated_types_in
  49: rustc_middle::ty::context::GlobalCtxt::enter_local
  50: rustc_typeck::check::wfcheck::check_associated_item
  51: rustc_typeck::check::wfcheck::check_impl_item
  52: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::check_impl_item_well_formed>::compute
  53: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  54: rustc_query_system::query::plumbing::get_query
  55: rustc_query_system::query::plumbing::ensure_query
  56: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
  57: rustc_hir::hir::Crate::par_visit_all_item_likes
  58: rustc_session::session::Session::track_errors
  59: rustc_typeck::check_crate
  60: rustc_interface::passes::analysis
  61: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::analysis>::compute
  62: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  63: rustc_query_system::query::plumbing::get_query
  64: rustc_middle::ty::context::tls::enter_global
  65: rustc_interface::interface::run_compiler_in_existing_thread_pool
  66: scoped_tls::ScopedKey<T>::set
  67: rustc_ast::attr::with_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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.44.0-nightly (edc02580e 2020-04-14) running on x86_64-unknown-linux-gnu

note: compiler flags: -C codegen-units=1 -C debuginfo=2 --crate-type bin

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

query stack during panic:
#0 [const_eval_raw] const-evaluating `DataHolder::<T>::ITEM_IS_COPY::{{constant}}#0`
#1 [const_eval_validated] const-evaluating + checking `DataHolder::<T>::ITEM_IS_COPY::{{constant}}#0`
#2 [const_eval_validated] const-evaluating + checking `DataHolder::<T>::ITEM_IS_COPY::{{constant}}#0`
#3 [check_impl_item_well_formed] processing `DataHolder::<T>::ITEM_IS_COPY`
#4 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error

error: could not compile `playground`.

To learn more, run the command again with --verbose.

@burtonageo burtonageo 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 Apr 16, 2020
@jonas-schievink jonas-schievink added A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Apr 16, 2020
burtonageo added a commit to burtonageo/glacier that referenced this issue Apr 16, 2020
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Apr 16, 2020
@spastorino
Copy link
Member

Assigning P-medium as discussed as part of the Prioritization Working Group process and removing I-prioritize.

@Dylan-DPC-zz Dylan-DPC-zz added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Apr 21, 2020
@adtac
Copy link

adtac commented Apr 23, 2020

Not sure how useful this is to you, but we're working on a private project and we managed to reduce the reproducer to:

impl<T> DataHolder {
    const ITEM_IS_COPY: [(); {
        trait NotCopy {
            const VALUE: bool;
        }

        impl<__Type: ?Sized> NotCopy for __Type {}

        T::VALUE
    } as usize] = [];
}

This too fails with ICE. It shouldn't compile, but as long as it's raising ICEs, we believe the issue is caused by the same underlying bug.

/cc @chengniansun @e45lee

@JohnTitor
Copy link
Member

Triage:
This is no longer ICE even with the const_generics feature flag: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=41675635317ae1129f2a8701dfc09824

@JohnTitor JohnTitor added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Dec 30, 2020
bors added a commit to rust-lang-ci/rust that referenced this issue Jan 31, 2021
…as-schievink

Rollup of 11 pull requests

Successful merges:

 - rust-lang#80092 (2229: Fix issues with move closures and mutability)
 - rust-lang#80404 (Remove const_in_array_repeat)
 - rust-lang#81255 (Don't link with --export-dynamic on wasm32-wasi)
 - rust-lang#81480 (Add suggestion for nested fields)
 - rust-lang#81549 (Misc ip documentation fixes)
 - rust-lang#81566 (Add a test for rust-lang#71202)
 - rust-lang#81568 (Fix an old FIXME in redundant paren lint)
 - rust-lang#81571 (Fix typo in E0759)
 - rust-lang#81572 (Edit multiple error code Markdown files)
 - rust-lang#81589 (Fix small typo in string.rs)
 - rust-lang#81590 (Stabilize int_bits_const)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors closed this as completed in 5f1a7aa Feb 1, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) A-const-generics Area: const generics (parameters and arguments) 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. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority 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.

8 participants