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

Unstable fingerprints for evaluate_obligation (EvaluatedToOkModuloRegions) #110416

Open
Lunderberg opened this issue Apr 16, 2023 · 3 comments
Open
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

@Lunderberg
Copy link

Code

This appears similar to those tracked in #84970, but doesn't appear to be any of the outstanding cases listed there. The bug can be triggered with the steps below.

  1. Set up repo with cargo new test_case, and src/lib.rs and tests/test.rs defined as below.
  2. Compile with cargo clean && cargo build --all-targets
  3. In src/lib.rs, on line 2, replace struct A; with struct A(B);
  4. Re-compile with cargo build --all-targets

Contents of src/lib.rs

/// ```
/// struct A;
/// ```
pub trait RefType<'ext> {
    type Node<Target>;
}

pub trait HasDefaultContainer {
    type Container;
}

pub trait RecursiveObj {
    type Ref;
}

pub struct RefImpl<Target = ()> {
    phantom: std::marker::PhantomData<Target>,
}

impl<'ext> RefType<'ext> for RefImpl {
    type Node<Target> = ();
}
pub struct Arena<Container, Target = ()> {
    phantom: std::marker::PhantomData<(Container, Target)>,
}

impl<Container> Arena<Container, ()> {
    pub fn push<'ext, Obj>(&self, _: Obj)
    where
        Obj: RecursiveObj<Ref = RefImpl>,
    {
        unimplemented!()
    }
}

impl<Target: HasDefaultContainer> Arena<Target::Container, Target> {
    pub fn build<Func>(_: Func) -> Self
    where
        Func: Fn(&Arena<Target::Container>) -> Target,
    {
        unimplemented!()
    }
}

Contents of tests/test.rs

mod peano {
    use test_lib::*;
    pub enum Number<Ref: RefType<'static> = RefImpl> {
        Zero,
        Successor(Ref::Node<Number>),
    }
    impl<Ref: RefType<'static>> RecursiveObj for Number<Ref> {
        type Ref = Ref;
    }

    pub struct Container(Number);
    impl HasDefaultContainer for Number {
        type Container = Container;
    }
}

use peano::{Container, Number};
use test_lib::*;
impl Number {
    fn _new() -> Arena<Container, Number> {
        Arena::build(|arena: &Arena<_, ()>| -> Number {
            arena.push(Number::<RefImpl>::Zero);
            Number::<RefImpl>::Zero
        })
    }
}

Meta

Error was first observed on stable.

rustc --version --verbose:

rustc 1.68.2 (9eb3afe9e 2023-03-27)
binary: rustc
commit-hash: 9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0
commit-date: 2023-03-27
host: x86_64-unknown-linux-gnu
release: 1.68.2
LLVM version: 15.0.6

Error also occurs on nightly rust,

rustc --version --verbose:

rustc 1.71.0-nightly (5cdb7886a 2023-04-15)
binary: rustc
commit-hash: 5cdb7886a5ece816864fab177f0c266ad4dd5358
commit-date: 2023-04-15
host: x86_64-unknown-linux-gnu
release: 1.71.0-nightly
LLVM version: 16.0.2

Error output

   Compiling test_lib v0.1.0 (/home/eric/rustc_bug_investigation/inprogress)
error: internal compiler error: encountered incremental compilation error with evaluate_obligation(c1568a12d3bea224-1c7d014328b731dc)
  |
  = help: This is a known issue with the compiler. Run `cargo clean -p test` or `cargo clean` to allow your project to compile
  = note: Please follow the instructions below to create a bug report with the provided information
  = note: See <https://github.com/rust-lang/rust/issues/84970> for more information

thread 'rustc' panicked at 'Found unstable fingerprints for evaluate_obligation(c1568a12d3bea224-1c7d014328b731dc): Ok(EvaluatedToOkModuloRegions)', compiler/rustc_query_system/src/query/plumbing.rs:679:9
BACKTRACE COPIED BELOW

error: internal compiler error: unexpected panic

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.68.2 (9eb3afe9e 2023-03-27) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED] -C link-arg=-B/usr/local/libexec/mold

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

query stack during panic:
#0 [evaluate_obligation] evaluating trait selection obligation `peano::Number: core::marker::Sized`
#1 [typeck] type-checking `<impl at tests/test.rs:19:1: 19:12>::_new`
#2 [typeck_item_bodies] type-checking all item bodies
#3 [analysis] running analysis passes on this crate
end of query stack
error: could not compile `test_lib` due to previous error
Backtrace

stack backtrace:
   0:     0x7f5be4bf359a - std::backtrace_rs::backtrace::libunwind::trace::ha271a8a7e1f3d4ef
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f5be4bf359a - std::backtrace_rs::backtrace::trace_unsynchronized::h85739da0352c791a
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f5be4bf359a - std::sys_common::backtrace::_print_fmt::hbc6ebcfb2910b329
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x7f5be4bf359a - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::he1c117e52d53614f
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f5be4c5539e - core::fmt::write::h25eb51b9526b8e0c
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/core/src/fmt/mod.rs:1213:17
   5:     0x7f5be4be3be5 - std::io::Write::write_fmt::ha9edec5fb1621933
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/io/mod.rs:1682:15
   6:     0x7f5be4bf3365 - std::sys_common::backtrace::_print::hf8657cd429fc3452
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/sys_common/backtrace.rs:47:5
   7:     0x7f5be4bf3365 - std::sys_common::backtrace::print::h41b9b18ed86f86bd
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/sys_common/backtrace.rs:34:9
   8:     0x7f5be4bf612f - std::panicking::default_hook::{{closure}}::h22a91871f4454152
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/panicking.rs:267:22
   9:     0x7f5be4bf5e6b - std::panicking::default_hook::h21ddc36de0cd4ae7
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/panicking.rs:286:9
  10:     0x7f5be7f46324 - rustc_driver[70f63b52fde826b7]::DEFAULT_HOOK::{closure#0}::{closure#0}
  11:     0x7f5be4bf696a - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h6f7e3c94ecc52e2f
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/alloc/src/boxed.rs:2002:9
  12:     0x7f5be4bf696a - std::panicking::rust_panic_with_hook::h5059419d6d59b3d0
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/panicking.rs:692:13
  13:     0x7f5be4bf66e9 - std::panicking::begin_panic_handler::{{closure}}::h0f383c291cd78343
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/panicking.rs:579:13
  14:     0x7f5be4bf3a4c - std::sys_common::backtrace::__rust_end_short_backtrace::h70ab22f2ad318cdd
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/sys_common/backtrace.rs:137:18
  15:     0x7f5be4bf63f2 - rust_begin_unwind
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/panicking.rs:575:5
  16:     0x7f5be4c51d43 - core::panicking::panic_fmt::hd1d46bcde3c61d72
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/core/src/panicking.rs:64:14
  17:     0x7f5be6e4e227 - rustc_query_system[59807289ca97d521]::query::plumbing::incremental_verify_ich_failed
  18:     0x7f5be69c1d3a - rustc_query_system[59807289ca97d521]::query::plumbing::get_query::<rustc_query_impl[81153385010d7886]::queries::evaluate_obligation, rustc_query_impl[81153385010d7886]::plumbing::QueryCtxt, rustc_middle[6dfce017f6b7786d]::dep_graph::dep_node::DepKind>
  19:     0x7f5be61616f4 - <rustc_trait_selection[d385e741675330b5]::traits::fulfill::FulfillProcessor as rustc_data_structures[560608da72c35763]::obligation_forest::ObligationProcessor>::process_obligation
  20:     0x7f5be615db22 - <rustc_data_structures[560608da72c35763]::obligation_forest::ObligationForest<rustc_trait_selection[d385e741675330b5]::traits::fulfill::PendingPredicateObligation>>::process_obligations::<rustc_trait_selection[d385e741675330b5]::traits::fulfill::FulfillProcessor>
  21:     0x7f5be615d5d8 - <rustc_trait_selection[d385e741675330b5]::traits::fulfill::FulfillmentContext as rustc_infer[83c7bda8c7ffae41]::traits::engine::TraitEngine>::select_where_possible
  22:     0x7f5be60d59ea - <rustc_hir_typeck[698e9809084ff9ec]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  23:     0x7f5be6108683 - <rustc_hir_typeck[698e9809084ff9ec]::fn_ctxt::FnCtxt>::check_block_with_expected
  24:     0x7f5be60d2d3c - <rustc_hir_typeck[698e9809084ff9ec]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  25:     0x7f5be606d8d1 - <rustc_hir_typeck[698e9809084ff9ec]::fn_ctxt::FnCtxt>::check_return_expr
  26:     0x7f5be6064802 - rustc_hir_typeck[698e9809084ff9ec]::check::check_fn
  27:     0x7f5be710b1c1 - <rustc_hir_typeck[698e9809084ff9ec]::fn_ctxt::FnCtxt>::check_expr_closure
  28:     0x7f5be60d6e0b - <rustc_hir_typeck[698e9809084ff9ec]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  29:     0x7f5be614890d - <rustc_hir_typeck[698e9809084ff9ec]::fn_ctxt::FnCtxt>::check_argument_types
  30:     0x7f5be725498b - <rustc_hir_typeck[698e9809084ff9ec]::fn_ctxt::FnCtxt>::check_call
  31:     0x7f5be60d28b2 - <rustc_hir_typeck[698e9809084ff9ec]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  32:     0x7f5be61088c1 - <rustc_hir_typeck[698e9809084ff9ec]::fn_ctxt::FnCtxt>::check_block_with_expected
  33:     0x7f5be60d2d3c - <rustc_hir_typeck[698e9809084ff9ec]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  34:     0x7f5be606d8d1 - <rustc_hir_typeck[698e9809084ff9ec]::fn_ctxt::FnCtxt>::check_return_expr
  35:     0x7f5be6064802 - rustc_hir_typeck[698e9809084ff9ec]::check::check_fn
  36:     0x7f5be604d0be - rustc_hir_typeck[698e9809084ff9ec]::typeck
  37:     0x7f5be603e797 - <rustc_query_system[59807289ca97d521]::dep_graph::graph::DepGraph<rustc_middle[6dfce017f6b7786d]::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle[6dfce017f6b7786d]::ty::context::TyCtxt, rustc_span[7c23fb27ec020b97]::def_id::LocalDefId, &rustc_middle[6dfce017f6b7786d]::ty::typeck_results::TypeckResults>
  38:     0x7f5be60362eb - rustc_query_system[59807289ca97d521]::query::plumbing::try_execute_query::<rustc_query_impl[81153385010d7886]::queries::typeck, rustc_query_impl[81153385010d7886]::plumbing::QueryCtxt>
  39:     0x7f5be7757f6d - rustc_query_system[59807289ca97d521]::query::plumbing::force_query::<rustc_query_impl[81153385010d7886]::queries::typeck, rustc_query_impl[81153385010d7886]::plumbing::QueryCtxt, rustc_middle[6dfce017f6b7786d]::dep_graph::dep_node::DepKind>
  40:     0x7f5be7757e70 - rustc_query_impl[81153385010d7886]::plumbing::force_from_dep_node::<rustc_query_impl[81153385010d7886]::queries::typeck>
  41:     0x7f5be5fc08b2 - <rustc_query_system[59807289ca97d521]::dep_graph::graph::DepGraph<rustc_middle[6dfce017f6b7786d]::dep_graph::dep_node::DepKind>>::try_mark_previous_green::<rustc_query_impl[81153385010d7886]::plumbing::QueryCtxt>
  42:     0x7f5be5fc0621 - <rustc_query_system[59807289ca97d521]::dep_graph::graph::DepGraph<rustc_middle[6dfce017f6b7786d]::dep_graph::dep_node::DepKind>>::try_mark_green::<rustc_query_impl[81153385010d7886]::plumbing::QueryCtxt>
  43:     0x7f5be74c79bf - rustc_query_system[59807289ca97d521]::query::plumbing::try_load_from_disk_and_cache_in_memory::<rustc_query_impl[81153385010d7886]::queries::typeck_item_bodies, rustc_query_impl[81153385010d7886]::plumbing::QueryCtxt>
  44:     0x7f5be74c6ae7 - rustc_query_system[59807289ca97d521]::query::plumbing::try_execute_query::<rustc_query_impl[81153385010d7886]::queries::typeck_item_bodies, rustc_query_impl[81153385010d7886]::plumbing::QueryCtxt>
  45:     0x7f5be78fed5b - <rustc_query_impl[81153385010d7886]::Queries as rustc_middle[6dfce017f6b7786d]::ty::query::QueryEngine>::typeck_item_bodies
  46:     0x7f5be63dbee2 - <rustc_session[cd7c78827427c6d6]::session::Session>::time::<(), rustc_hir_analysis[651175ae4d1746c1]::check_crate::{closure#7}>
  47:     0x7f5be63db352 - rustc_hir_analysis[651175ae4d1746c1]::check_crate
  48:     0x7f5be63dafab - rustc_interface[698bad460dbd68d3]::passes::analysis
  49:     0x7f5be7671f76 - <rustc_query_system[59807289ca97d521]::dep_graph::graph::DepGraph<rustc_middle[6dfce017f6b7786d]::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle[6dfce017f6b7786d]::ty::context::TyCtxt, (), core[1d432356d8e1e9f1]::result::Result<(), rustc_errors[53e74ce803854a4d]::ErrorGuaranteed>>
  50:     0x7f5be7671131 - rustc_query_system[59807289ca97d521]::query::plumbing::try_execute_query::<rustc_query_impl[81153385010d7886]::queries::analysis, rustc_query_impl[81153385010d7886]::plumbing::QueryCtxt>
  51:     0x7f5be78fb60a - <rustc_query_impl[81153385010d7886]::Queries as rustc_middle[6dfce017f6b7786d]::ty::query::QueryEngine>::analysis
  52:     0x7f5be7127010 - <rustc_interface[698bad460dbd68d3]::passes::QueryContext>::enter::<rustc_driver[70f63b52fde826b7]::run_compiler::{closure#1}::{closure#2}::{closure#2}, core[1d432356d8e1e9f1]::result::Result<(), rustc_errors[53e74ce803854a4d]::ErrorGuaranteed>>
  53:     0x7f5be7124a84 - rustc_span[7c23fb27ec020b97]::with_source_map::<core[1d432356d8e1e9f1]::result::Result<(), rustc_errors[53e74ce803854a4d]::ErrorGuaranteed>, rustc_interface[698bad460dbd68d3]::interface::run_compiler<core[1d432356d8e1e9f1]::result::Result<(), rustc_errors[53e74ce803854a4d]::ErrorGuaranteed>, rustc_driver[70f63b52fde826b7]::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
  54:     0x7f5be711d2d4 - <scoped_tls[1044df3f3db9be03]::ScopedKey<rustc_span[7c23fb27ec020b97]::SessionGlobals>>::set::<rustc_interface[698bad460dbd68d3]::interface::run_compiler<core[1d432356d8e1e9f1]::result::Result<(), rustc_errors[53e74ce803854a4d]::ErrorGuaranteed>, rustc_driver[70f63b52fde826b7]::run_compiler::{closure#1}>::{closure#0}, core[1d432356d8e1e9f1]::result::Result<(), rustc_errors[53e74ce803854a4d]::ErrorGuaranteed>>
  55:     0x7f5be711c9d2 - std[f8b79e573431a86c]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[698bad460dbd68d3]::util::run_in_thread_pool_with_globals<rustc_interface[698bad460dbd68d3]::interface::run_compiler<core[1d432356d8e1e9f1]::result::Result<(), rustc_errors[53e74ce803854a4d]::ErrorGuaranteed>, rustc_driver[70f63b52fde826b7]::run_compiler::{closure#1}>::{closure#0}, core[1d432356d8e1e9f1]::result::Result<(), rustc_errors[53e74ce803854a4d]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[1d432356d8e1e9f1]::result::Result<(), rustc_errors[53e74ce803854a4d]::ErrorGuaranteed>>
  56:     0x7f5be711c77a - <<std[f8b79e573431a86c]::thread::Builder>::spawn_unchecked_<rustc_interface[698bad460dbd68d3]::util::run_in_thread_pool_with_globals<rustc_interface[698bad460dbd68d3]::interface::run_compiler<core[1d432356d8e1e9f1]::result::Result<(), rustc_errors[53e74ce803854a4d]::ErrorGuaranteed>, rustc_driver[70f63b52fde826b7]::run_compiler::{closure#1}>::{closure#0}, core[1d432356d8e1e9f1]::result::Result<(), rustc_errors[53e74ce803854a4d]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[1d432356d8e1e9f1]::result::Result<(), rustc_errors[53e74ce803854a4d]::ErrorGuaranteed>>::{closure#1} as core[1d432356d8e1e9f1]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  57:     0x7f5be4c00823 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h3205ec2d7fc232c5
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/alloc/src/boxed.rs:1988:9
  58:     0x7f5be4c00823 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h3bb5daec8177f56b
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/alloc/src/boxed.rs:1988:9
  59:     0x7f5be4c00823 - std::sys::unix::thread::Thread::new::thread_start::had7b8061e306bb5c
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/sys/unix/thread.rs:108:17
  60:     0x7f5be4aa6609 - start_thread
                               at /build/glibc-SzIz7B/glibc-2.31/nptl/pthread_create.c:477:8
  61:     0x7f5be49c9133 - clone
                               at /build/glibc-SzIz7B/glibc-2.31/misc/../sysdeps/unix/sysv/linux/x86_64/clone.S:95
  62:                0x0 - <unknown>

@Lunderberg Lunderberg 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, 2023
@lqd
Copy link
Member

lqd commented Apr 17, 2023

An obligation incremental ICE via a ... doc-comment change, that's refreshing. Again related to overflowing requirements when evaluating a Sized requirement.

For people trying to reproduce: since the test imports items from the lib, the first listed step should actually be cargo new test_lib --lib.

This started ICEing in nightly-2022-11-12 so it's too recent to be related to most of the other repros in those tracking issues: bisection points to #100386 -- cc PR author @compiler-errors and reviewer @lcnr.

@compiler-errors
Copy link
Member

compiler-errors commented Apr 17, 2023

Again related to overflowing requirements when evaluating a Sized requirement.

Sized is coinductive now. The requirements aren't overflowing, just cyclic.

This has to do with some subtle interaction between the projection cache and coinductive cycles, causing a goal to either evaluate to EvaluatedToOkModuloRegions or EvaluatedToOk depending on where in the trait evaluation stack it shows up. I probably don't have the time or effort to fix this (or better excuse, it may be impossible given the current design of the old solver and its interleaving select/normalize calls).

For the record, this doesn't reproduce with RUSTFLAGS=-Ztrait-solver=next, so we might just have to wait for the new solver.

No idea why it only reproduces when you change that doc comment. It may have to do with some cache invalidation stuff that's above my head.

@lcnr
Copy link
Contributor

lcnr commented Apr 18, 2023

This has to do with some subtle interaction between the projection cache and coinductive cycles, causing a goal to either evaluate to EvaluatedToOkModuloRegions or EvaluatedToOk depending on where in the trait evaluation stack it shows up. I probably don't have the time or effort to fix this (or better excuse, it may be impossible given the current design of the old solver and its interleaving select/normalize calls).

I also believe this to not be worth the effort to fix in the old solver. The projection cache generally doesn't play well with dependency tracking in general, so I think we should accept this as yet another reason to focus on migrating to the new solver.

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

No branches or pull requests

4 participants