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 const variables should not be hashed: Var(_#0c) inside async context on nightly #104787

Closed
matheus-consoli opened this issue Nov 23, 2022 · 0 comments · Fixed by #104788
Closed
Assignees
Labels
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.

Comments

@matheus-consoli
Copy link

Code

I think the problem here is derived from rustc not knowing the array length. I'm using futures-concurrency crate to .await an array of streams, merge() returns a Merge<S, const N: usize> struct, but the N is not known at this point because we don't limit the array::from_fn.

use core::array;

use futures_concurrency::prelude::*;
use futures_lite::{future::block_on, stream, StreamExt};

fn main() {
    block_on(async {
        // works, the array length is known
        // let s = from_fn::<_, 5, _>(stream::once)
        let s = array::from_fn(stream::once)
            .merge()
            .fold(0, |acc, n| acc + n)
            .await;

        assert_eq!(10, s);
    });
}

this is much like

array::from_fn(identity).collect();

except that the latter doesn't panic, and gives a helpful error message.

Also, this seems to only occur within an async context.

Meta

rustc --version --verbose:

>> rustc --version --verbose
rustc 1.67.0-nightly (ff8c8dfbe 2022-11-22)
binary: rustc
commit-hash: ff8c8dfbe66701531e3e5e335c28c544d0fbc945
commit-date: 2022-11-22
host: x86_64-unknown-linux-gnu
release: 1.67.0-nightly
LLVM version: 15.0.4

Error output

>> RUST_BACKTRACE=1 cargo r
   Compiling f v0.1.0 (/home/consoli/projects/rust/contrib/f)
error[E0282]: type annotations needed
  --> src/main.rs:11:14
   |
11 |             .merge()
   |              ^^^^^
   |
help: try using a fully qualified path to specify the expected types
   |
10 |         let s = <[futures_lite::stream::Once<usize>; _] as futures_concurrency::stream::Merge>::merge(from_fn(stream::once))
   |                 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                     ~

thread '<unnamed>' panicked at 'const variables should not be hashed: Var(_#0c)', /rustc/ff8c8dfbe66701531e3e5e335c28c544d0fbc945/compiler/rustc_middle/src/ty/consts/kind.rs:122:35

Backtrace

thread '<unnamed>' panicked at 'const variables should not be hashed: Var(_#0c)', /rustc/ff8c8dfbe66701531e3e5e335c28c544d0fbc945/compiler/rustc_middle/src/ty/consts/kind.rs:122:35
stack backtrace:
   0: rust_begin_unwind
             at /rustc/ff8c8dfbe66701531e3e5e335c28c544d0fbc945/library/std/src/panicking.rs:575:5
   1: core::panicking::panic_fmt
             at /rustc/ff8c8dfbe66701531e3e5e335c28c544d0fbc945/library/core/src/panicking.rs:65:14
   2: <rustc_middle::ty::consts::kind::InferConst as rustc_data_structures::stable_hasher::HashStable<rustc_query_system::ich::hcx::StableHashingContext>>::hash_stable
   3: <rustc_data_structures::intern::Interned<rustc_data_structures::intern::WithStableHash<rustc_middle::ty::TyS>> as rustc_data_structures::stable_hasher::HashStable<rustc_query_system::ich::hcx::StableHashingContext>>::hash_stable
   4: <[rustc_middle::ty::context::GeneratorInteriorTypeCause] as rustc_data_structures::stable_hasher::HashStable<rustc_query_system::ich::hcx::StableHashingContext>>::hash_stable
   5: rustc_query_system::dep_graph::graph::hash_result::<&rustc_middle::ty::context::TypeckResults>
   6: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, rustc_span::def_id::LocalDefId, &rustc_middle::ty::context::TypeckResults>
   7: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::LocalDefId, &rustc_middle::ty::context::TypeckResults>>
   8: rustc_data_structures::sync::par_for_each_in::<&[rustc_span::def_id::LocalDefId], <rustc_middle::hir::map::Map>::par_body_owners<rustc_hir_typeck::typeck_item_bodies::{closure#0}>::{closure#0}>
   9: rustc_hir_typeck::typeck_item_bodies
  10: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, (), ()>
  11: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<(), ()>>
  12: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::typeck_item_bodies, rustc_query_impl::plumbing::QueryCtxt>
  13: <rustc_session::session::Session>::time::<(), rustc_hir_analysis::check_crate::{closure#7}>
  14: rustc_hir_analysis::check_crate
  15: rustc_interface::passes::analysis
  16: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, (), core::result::Result<(), rustc_errors::ErrorGuaranteed>>
  17: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<(), core::result::Result<(), rustc_errors::ErrorGuaranteed>>>
  18: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::analysis, rustc_query_impl::plumbing::QueryCtxt>
  19: <rustc_interface::passes::QueryContext>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}::{closure#3}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>
  20: <rustc_interface::interface::Compiler>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_errors::ErrorGuaranteed>>
  21: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#0}::{closure#1}>
  22: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Sorry if this isn't a true ICE, the compiler panics, but the usual message "this is an ICE" is not shown

@matheus-consoli matheus-consoli 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 Nov 23, 2022
@compiler-errors compiler-errors self-assigned this Nov 23, 2022
@bors bors closed this as completed in e6c83d9 Nov 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants