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

Internal compiler error related to constant evaluation timeout #112748

Closed
claytonwramsey opened this issue Jun 17, 2023 · 2 comments · Fixed by #112925
Closed

Internal compiler error related to constant evaluation timeout #112748

claytonwramsey opened this issue Jun 17, 2023 · 2 comments · Fixed by #112925
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

@claytonwramsey
Copy link

Minimum example:

const SAVED_ROOK_MAGICS: [u64; 64] = [0; 64];

const ROOK_BITS: [u8; 64] = [1; 64];

const ROOK_MASKS: [u64; 64] = {
    let mut masks = [0; 64];
    let mut i = 0u8;
    while i < 64 {
        masks[i as usize] = get_rook_mask(i);
        i += 1;
    }
    masks
};

#[allow(unused)]
static ROOK_ATTACKS_TABLE: [u64; 999_999] =
    construct_magic_table(&ROOK_BITS, &SAVED_ROOK_MAGICS, &ROOK_MASKS);

const fn construct_magic_table<const N: usize>(
    bits: &[u8; 64],
    magics: &[u64; 64],
    masks: &[u64; 64],
) -> [u64; N] {
    let mut table = [0; N];

    let mut i = 0;
    let mut table_offset = 0;

    while i < 64 {
        let mask = masks[i];
        let magic = magics[i];
        let n_attacks_to_generate = 1 << mask.count_ones();

        let mut j = 0;
        while j < n_attacks_to_generate {
            let occupancy = index_to_occupancy(j, mask);
            let attack = 0;
            let key = compute_magic_key(occupancy, magic, 64 - bits[i]);
            table[key + table_offset] = attack;
            j += 1;
        }

        table_offset += 1 << bits[i];
        i += 1;
    }

    table
}

const fn compute_magic_key(occupancy: u64, magic: u64, shift: u8) -> usize {
    (occupancy.wrapping_mul(magic) >> shift) as usize
}

const fn get_rook_mask(sq: u8) -> u64 {
    (0x7E << (sq & !0x7) ^ 0x0001_0101_0101_0100 << (sq & 0x7)) & !(1 << sq as u64)
}

const fn index_to_occupancy(index: usize, mask: u64) -> u64 {
    let mut result = 0u64;
    let num_points = mask.count_ones();
    let mut editable_mask = mask;
    let mut i = 0;
    while i < num_points {
        let shift_size = editable_mask.trailing_zeros();
        let occupier = 1 << shift_size;
        editable_mask &= !occupier;
        if (index & (1 << i)) != 0 {
            result |= occupier;
        }
        i += 1;
    }

    result
}

I have a full project where I was able to consistently cause this error. It seems to be related to the timeout on constant evaluation. For my project which consistently has the error, check here.

For some reason, annotating ROOK_ATTACKS_TABLE with #[allow(long_running_const_eval)] prevents this error.

Meta

rustc --version --verbose:

rustc 1.72.0-nightly (b2b34bd83 2023-06-06)
binary: rustc
commit-hash: b2b34bd83192c3d16c88655158f7d8d612513e88
commit-date: 2023-06-06
host: x86_64-unknown-linux-gnu
release: 1.72.0-nightly
LLVM version: 16.0.5

Error output

error: internal compiler error: no errors encountered even though `delay_span_bug` issued

error: internal compiler error: The deny lint should have already errored
    --> /home/clayton/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/num/mod.rs:1174:5
     |
1174 | /     uint_impl! {
1175 | |         Self = u64,
1176 | |         ActualT = u64,
1177 | |         SignedT = i64,
...    |
1191 | |         bound_condition = "",
1192 | |     }
     | |_____^
     |
Backtrace

~/C/fiddler (compiler-bug|✚1) $ RUST_BACKTRACE=1 cargo build
   Compiling fiddler v0.1.0 (/home/clayton/Chess/fiddler)
error: internal compiler error: no errors encountered even though `delay_span_bug` issued

error: internal compiler error: The deny lint should have already errored
    --> /home/clayton/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/num/mod.rs:1174:5
     |
1174 | /     uint_impl! {
1175 | |         Self = u64,
1176 | |         ActualT = u64,
1177 | |         SignedT = i64,
...    |
1191 | |         bound_condition = "",
1192 | |     }
     | |_____^
     |
     = note: delayed at compiler/rustc_const_eval/src/const_eval/machine.rs:634:26
                0: <rustc_errors::HandlerInner>::emit_diagnostic
                1: <rustc_errors::Handler>::delay_span_bug::<rustc_span::span_encoding::Span, &str>
                2: <rustc_const_eval::interpret::eval_context::InterpCx<rustc_const_eval::const_eval::machine::CompileTimeInterpreter>>::statement
                3: rustc_const_eval::const_eval::eval_queries::eval_to_allocation_raw_provider
                4: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::eval_to_allocation_raw::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 16]>>
                5: <rustc_query_impl::query_impl::eval_to_allocation_raw::dynamic_query::{closure#2} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, rustc_middle::ty::ParamEnvAnd<rustc_middle::mir::interpret::GlobalId>)>>::call_once
                6: <rustc_query_system::query::plumbing::execute_job_incr<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::DefaultCache<rustc_middle::ty::ParamEnvAnd<rustc_middle::mir::interpret::GlobalId>, rustc_middle::query::erase::Erased<[u8; 32]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt>::{closure#2}::{closure#2} as core::ops::function::FnOnce<((rustc_query_impl::plumbing::QueryCtxt, rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::DefaultCache<rustc_middle::ty::ParamEnvAnd<rustc_middle::mir::interpret::GlobalId>, rustc_middle::query::erase::Erased<[u8; 32]>>, false, false, false>), rustc_middle::ty::ParamEnvAnd<rustc_middle::mir::interpret::GlobalId>)>>::call_once
                7: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::DefaultCache<rustc_middle::ty::ParamEnvAnd<rustc_middle::mir::interpret::GlobalId>, rustc_middle::query::erase::Erased<[u8; 16]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, true>
                8: rustc_query_impl::query_impl::eval_to_allocation_raw::get_query_incr::__rust_end_short_backtrace
                9: rustc_const_eval::const_eval::eval_queries::eval_to_allocation_raw_provider
               10: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::eval_to_allocation_raw::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 16]>>
               11: <rustc_query_impl::query_impl::eval_to_allocation_raw::dynamic_query::{closure#2} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, rustc_middle::ty::ParamEnvAnd<rustc_middle::mir::interpret::GlobalId>)>>::call_once
               12: <rustc_query_system::query::plumbing::execute_job_incr<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::DefaultCache<rustc_middle::ty::ParamEnvAnd<rustc_middle::mir::interpret::GlobalId>, rustc_middle::query::erase::Erased<[u8; 32]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt>::{closure#2}::{closure#2} as core::ops::function::FnOnce<((rustc_query_impl::plumbing::QueryCtxt, rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::DefaultCache<rustc_middle::ty::ParamEnvAnd<rustc_middle::mir::interpret::GlobalId>, rustc_middle::query::erase::Erased<[u8; 32]>>, false, false, false>), rustc_middle::ty::ParamEnvAnd<rustc_middle::mir::interpret::GlobalId>)>>::call_once
               13: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::DefaultCache<rustc_middle::ty::ParamEnvAnd<rustc_middle::mir::interpret::GlobalId>, rustc_middle::query::erase::Erased<[u8; 16]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, true>
               14: rustc_query_impl::query_impl::eval_to_allocation_raw::get_query_incr::__rust_end_short_backtrace
               15: <rustc_middle::query::plumbing::TyCtxtEnsure>::eval_static_initializer
               16: <rustc_lint::BuiltinCombinedModuleLateLintPass as rustc_lint::passes::LateLintPass>::check_item
               17: rustc_hir::intravisit::walk_mod::<rustc_lint::late::LateContextAndPass<rustc_lint::BuiltinCombinedModuleLateLintPass>>
               18: rustc_lint::late::late_lint_mod::<rustc_lint::BuiltinCombinedModuleLateLintPass>
               19: rustc_lint::lint_mod
               20: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::lint_mod::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 0]>>
               21: <rustc_query_impl::query_impl::lint_mod::dynamic_query::{closure#2} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, rustc_span::def_id::LocalDefId)>>::call_once
               22: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::Erased<[u8; 0]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, true>
               23: rustc_query_impl::query_impl::lint_mod::get_query_incr::__rust_end_short_backtrace
               24: rustc_data_structures::sync::par_for_each_in::<&[rustc_hir::hir_id::OwnerId], <rustc_middle::hir::map::Map>::par_for_each_module<rustc_lint::late::check_crate<rustc_lint::BuiltinCombinedLateLintPass, rustc_interface::passes::analysis::{closure#5}::{closure#1}::{closure#2}::{closure#0}::{closure#0}>::{closure#1}::{closure#0}::{closure#0}>::{closure#0}>
               25: <rustc_session::session::Session>::time::<(), rustc_lint::late::check_crate<rustc_lint::BuiltinCombinedLateLintPass, rustc_interface::passes::analysis::{closure#5}::{closure#1}::{closure#2}::{closure#0}::{closure#0}>::{closure#1}::{closure#0}>
               26: <rustc_session::session::Session>::time::<(), rustc_interface::passes::analysis::{closure#5}::{closure#1}::{closure#2}::{closure#0}>
               27: <core::panic::unwind_safe::AssertUnwindSafe<rustc_interface::passes::analysis::{closure#5}::{closure#1}> as core::ops::function::FnOnce<()>>::call_once
               28: <rustc_session::session::Session>::time::<(), rustc_interface::passes::analysis::{closure#5}>
               29: rustc_interface::passes::analysis
               30: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 1]>>
               31: <rustc_query_impl::query_impl::analysis::dynamic_query::{closure#2} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, ())>>::call_once
               32: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::SingleCache<rustc_middle::query::erase::Erased<[u8; 1]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, true>
               33: rustc_query_impl::query_impl::analysis::get_query_incr::__rust_end_short_backtrace
               34: <rustc_middle::ty::context::GlobalCtxt>::enter::<rustc_driver_impl::run_compiler::{closure#1}::{closure#2}::{closure#4}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
               35: <rustc_interface::interface::Compiler>::enter::<rustc_driver_impl::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_span::ErrorGuaranteed>>
               36: std::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
               37: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
               38: call_once<(), dyn core::ops::function::FnOnce<(), Output=()>, alloc::alloc::Global>
                          at /rustc/b2b34bd83192c3d16c88655158f7d8d612513e88/library/alloc/src/boxed.rs:1985:9
               39: call_once<(), alloc::boxed::Box<dyn core::ops::function::FnOnce<(), Output=()>, alloc::alloc::Global>, alloc::alloc::Global>
                          at /rustc/b2b34bd83192c3d16c88655158f7d8d612513e88/library/alloc/src/boxed.rs:1985:9
               40: thread_start
                          at /rustc/b2b34bd83192c3d16c88655158f7d8d612513e88/library/std/src/sys/unix/thread.rs:108:17
               41: start_thread
                          at ./nptl/pthread_create.c:444:8
               42: __GI___clone3
                          at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
             
     = note: this error: internal compiler error originates in the macro `uint_impl` (in Nightly builds, run with -Z macro-backtrace for more info)

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.72.0-nightly (b2b34bd83 2023-06-06) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type lib -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED] -C target_cpu=native

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

query stack during panic:
end of query stack
error: could not compile `fiddler` (lib)

@claytonwramsey claytonwramsey 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 Jun 17, 2023
@Noratrieb
Copy link
Member

cc @oli-obk

@oli-obk oli-obk self-assigned this Jun 18, 2023
@claytonwramsey
Copy link
Author

I just checked - I was able to cause this error to occur in 1.72 nightly but not in 1.70 stable.

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Jun 22, 2023
Stop hiding const eval limit in external macros

fixes rust-lang#112748

We don't emit a hard error if there was a previous deny lint triggering with the same message. If that lint ends up not being emitted, we ICE and don't emit an error either.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jun 23, 2023
Stop hiding const eval limit in external macros

fixes rust-lang#112748

We don't emit a hard error if there was a previous deny lint triggering with the same message. If that lint ends up not being emitted, we ICE and don't emit an error either.
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Jun 23, 2023
Stop hiding const eval limit in external macros

fixes rust-lang#112748

We don't emit a hard error if there was a previous deny lint triggering with the same message. If that lint ends up not being emitted, we ICE and don't emit an error either.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jun 23, 2023
Stop hiding const eval limit in external macros

fixes rust-lang#112748

We don't emit a hard error if there was a previous deny lint triggering with the same message. If that lint ends up not being emitted, we ICE and don't emit an error either.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jun 23, 2023
Stop hiding const eval limit in external macros

fixes rust-lang#112748

We don't emit a hard error if there was a previous deny lint triggering with the same message. If that lint ends up not being emitted, we ICE and don't emit an error either.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jun 23, 2023
Stop hiding const eval limit in external macros

fixes rust-lang#112748

We don't emit a hard error if there was a previous deny lint triggering with the same message. If that lint ends up not being emitted, we ICE and don't emit an error either.
@bors bors closed this as completed in c913952 Jun 23, 2023
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.

4 participants
@oli-obk @claytonwramsey @Noratrieb and others