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 when build with const_evaluatable_checked and incremental #84355

Closed
moelife-coder opened this issue Apr 20, 2021 · 9 comments
Closed

ICE when build with const_evaluatable_checked and incremental #84355

moelife-coder opened this issue Apr 20, 2021 · 9 comments
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-generic_const_exprs `#![feature(generic_const_exprs)]` 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

@moelife-coder
Copy link

moelife-coder commented Apr 20, 2021

Code

#![feature(const_generics)]
#![feature(const_evaluatable_checked)]
use std::mem::{size_of, transmute_copy};

fn main() {
    unsafe {
        let c: &str = convert_from_slice([0; 16]);
    }
}
unsafe fn convert_from_slice<T>(source: [u8; size_of::<T>()]) -> T where [u8; size_of::<T>()]: Sized {
    let target: T = transmute_copy(&source);
    target
}

Meta

rustc --version --verbose:

rustc 1.53.0-nightly (9d9c2c92b 2021-04-19)
binary: rustc
commit-hash: 9d9c2c92b834c430f102ea96f65119e37320776e
commit-date: 2021-04-19
host: x86_64-unknown-linux-gnu
release: 1.53.0-nightly
LLVM version: 12.0.0

Error output

error: internal compiler error: compiler/rustc_middle/src/ich/impls_ty.rs:94:17: StableHasher: unexpected region '_#1r

thread 'rustc' panicked at 'Box<Any>', /rustc/9d9c2c92b834c430f102ea96f65119e37320776e/library/std/src/panic.rs:59:5
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/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.53.0-nightly (9d9c2c92b 2021-04-19) running on x86_64-unknown-linux-gnu

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

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

query stack during panic:
#0 [typeck] type-checking `main`
#1 [typeck_item_bodies] type-checking all item bodies
end of query stack
Backtrace

thread 'rustc' panicked at 'Box<Any>', /rustc/9d9c2c92b834c430f102ea96f65119e37320776e/library/std/src/panic.rs:59:5
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_middle::ich::impls_ty::<impl rustc_data_structures::stable_hasher::HashStable<rustc_middle::ich::hcx::StableHashingContext> for rustc_middle::ty::sty::RegionKind>::hash_stable
   8: <rustc_middle::ty::TyS as rustc_data_structures::stable_hasher::HashStable<rustc_middle::ich::hcx::StableHashingContext>>::hash_stable
   9: std::thread::local::LocalKey<T>::with
  10: <T as rustc_query_system::dep_graph::dep_node::DepNodeParams<Ctxt>>::to_fingerprint
  11: rustc_query_system::dep_graph::dep_node::DepNode<K>::construct
  12: rustc_query_system::query::plumbing::get_query_impl
  13: rustc_query_system::query::plumbing::get_query
  14: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::try_unify_abstract_consts
  15: rustc_trait_selection::traits::fulfill::FulfillProcessor::progress_changed_obligations
  16: rustc_data_structures::obligation_forest::ObligationForest<O>::process_obligations
  17: <rustc_trait_selection::traits::fulfill::FulfillmentContext as rustc_infer::traits::engine::TraitEngine>::select_where_possible
  18: rustc_typeck::check::fn_ctxt::checks::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_argument_types
  19: rustc_typeck::check::callee::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::confirm_builtin_call
  20: rustc_typeck::check::callee::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_call
  21: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
  22: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
  23: rustc_typeck::check::fn_ctxt::checks::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_decl_initializer
  24: rustc_typeck::check::fn_ctxt::checks::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_decl_local
  25: rustc_typeck::check::fn_ctxt::checks::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_stmt
  26: rustc_typeck::check::fn_ctxt::checks::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_block_with_expected
  27: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
  28: rustc_typeck::check::fn_ctxt::checks::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_block_with_expected
  29: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
  30: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_return_expr
  31: rustc_typeck::check::check::check_fn
  32: rustc_infer::infer::InferCtxtBuilder::enter
  33: rustc_typeck::check::typeck
  34: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  35: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  36: rustc_data_structures::stack::ensure_sufficient_stack
  37: rustc_query_system::query::plumbing::force_query_with_job
  38: rustc_query_system::query::plumbing::get_query_impl
  39: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::typeck
  40: rustc_middle::ty::<impl rustc_middle::ty::context::TyCtxt>::par_body_owners
  41: rustc_typeck::check::typeck_item_bodies
  42: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  43: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  44: rustc_data_structures::stack::ensure_sufficient_stack
  45: rustc_query_system::query::plumbing::force_query_with_job
  46: rustc_query_system::query::plumbing::get_query_impl
  47: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::typeck_item_bodies
  48: rustc_session::utils::<impl rustc_session::session::Session>::time
  49: rustc_typeck::check_crate
  50: rustc_interface::passes::analysis
  51: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  52: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  53: rustc_data_structures::stack::ensure_sufficient_stack
  54: rustc_query_system::query::plumbing::force_query_with_job
  55: rustc_query_system::query::plumbing::get_query_impl
  56: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
  57: rustc_interface::passes::QueryContext::enter
  58: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  59: rustc_span::with_source_map
  60: rustc_interface::interface::create_compiler_and_run
  61: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

@moelife-coder moelife-coder 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 20, 2021
@moelife-coder
Copy link
Author

The code does work on rust playground (for now), which is running rustc 1.53.0-nightly (2021-04-18 5a4ab26459a1ccf17ef5). Not sure if it's a regression or something similar.

@jonas-schievink jonas-schievink added A-const-generics Area: const generics (parameters and arguments) F-generic_const_exprs `#![feature(generic_const_exprs)]` labels Apr 20, 2021
@hellow554
Copy link
Contributor

Can't reproduce the error with your rust version :/

Have you changed something beforehand?

If it still occurs to you, please

  1. do a backup of your target folder (into a .zip file for example)
  2. cargo clean or rm -rf target
  3. cargo check (or whatever you've done to build your code)

If it still panics, please report, else please upload the target folder and link it here

@moelife-coder
Copy link
Author

I can still reproduce the bug after cargo clean; rm -rf ~/.config/cargo/target. I also tried to update to latest rustc (rustc 1.53.0-nightly (b84932674 2021-04-21)), but it's still not working.

I do have a custom global cargo.toml, but it should be irrelevant as it only contains a proxy and a target folder configuration (for better connection and global cache).

Global cargo.toml:

[http]
proxy = "127.0.0.1:1081"         # HTTP proxy in libcurl format
[build]
target-dir = "cargo/target"

No changes are made for the crate-level configuration file.

target.tar.gz

@moelife-coder
Copy link
Author

I tried several times and I realized that I can actually build it successfully when appending --release argument for cargo. After some attempts, I pinned the problem down to -C incremental rustc option. No matter what path I specified as incremental folder, it will always break the compiler. I believe this issue can now be reproduced using shell code:

mkdir incremental_tmp; rustc main.rs -C incremental incremental_tmp; rm -r incremental_tmp

I tried the following command in docker rustlang/rust:nightly and the issue successfully reproduced.

@moelife-coder
Copy link
Author

Although rust playground can build the code under default modes (build or run), it will fail when using test mode.

@moelife-coder moelife-coder changed the title ICE with feature const_evaluatable_checked ICE when build with const_evaluatable_checked and incremental Apr 22, 2021
@hellow554
Copy link
Contributor

Okay, I got it now... cargo check will also fail... I think I missed the incremental option in rustc, trying to reduce and bisect

@moelife-coder
Copy link
Author

I realized that it's a duplicate for #77708 . I'll close this issue in favor of that one.

@Johannesd3
Copy link

Are you sure this is a duplicate? The query stack and backtrace are different to #77708.

But it looks very similar to #85031 which I opened today.

@moelife-coder
Copy link
Author

Are you sure this is a duplicate? The query stack and backtrace are different to #77708.

But it looks very similar to #85031 which I opened today.

Sorry for the late response, but I think you are correct. The query stack is similar to your issue than #77708 .

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-generic_const_exprs `#![feature(generic_const_exprs)]` 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

No branches or pull requests

4 participants