Skip to content

Crash "Can't merge cycle heads variances_of_query(Id(a0b7)) with different iteration counts" on cyclic types #22045

@Wilfred

Description

@Wilfred

Given the following minimised Rust code (derived from this file):

enum Type<T> {
    Object(Box<Expression<T>>),
    Generic(Box<Type<T>>),
}

enum DeclareClassExtends<T> {
    Ident(Type<T>),
    Recursive(Box<DeclareClassExtends<T>>),
}

enum Statement<T> {
    Class(Class<T>),
    Declare(DeclareClassExtends<T>),
}

enum Expression<T> {
    Call(Type<T>),
    Class(Class<T>),
}

struct Class<T>(Box<Statement<T>>, Box<Expression<T>>);

fn make() -> Statement<()> {
    loop {}
}

rust-analyzer crashes, both in normal LSP usage and in analysis-stats:

$ rust-analyzer analysis-stats .
...
8/9 88% processing: crashdemo::make
thread 'main' (43573436) panicked at /Users/wilfred/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/salsa-0.25.2/src/cycle.rs:338:17:
assertion `left == right` failed: Can't merge cycle heads variances_of_query(Id(a0b7)) with different iteration counts (IterationCount(0), IterationCount(1))
  left: IterationCount(0)
 right: IterationCount(1)
stack backtrace:
   0: __rustc::rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::assert_failed_inner
   3: core::panicking::assert_failed
   4: salsa::cycle::CycleHeads::insert
   5: salsa::active_query::ActiveQuery::add_read
   6: std::thread::local::LocalKey<T>::with
   7: hir_ty::variance::variances_of
   8: hir_ty::variance::Context::add_constraints_from_ty
   9: <hir_ty::variance::variances_of_query::variances_of_query_Configuration_ as salsa::function::Configuration>::execute
  10: salsa::function::execute::<impl salsa::function::IngredientImpl<C>>::execute
  11: salsa::function::fetch::<impl salsa::function::IngredientImpl<C>>::fetch_cold
  12: std::thread::local::LocalKey<T>::with
  13: hir_ty::variance::variances_of
  14: <hir_ty::next_solver::interner::DbInterner as ra_ap_rustc_type_ir::interner::Interner>::variances_of
  15: <hir_ty::next_solver::infer::relate::generalize::Generalizer as ra_ap_rustc_type_ir::relate::TypeRelation<hir_ty::next_solver::interner::DbInterner>>::relate_ty_args
  16: ra_ap_rustc_type_ir::relate::structurally_relate_tys
  17: <hir_ty::next_solver::infer::relate::generalize::Generalizer as ra_ap_rustc_type_ir::relate::TypeRelation<hir_ty::next_solver::interner::DbInterner>>::tys
  18: hir_ty::next_solver::infer::context::<impl ra_ap_rustc_type_ir::infer_ctxt::InferCtxtLike for hir_ty::next_solver::infer::InferCtxt>::instantiate_ty_var_raw
  19: <ra_ap_rustc_type_ir::relate::solver_relating::SolverRelating<Infcx,I> as ra_ap_rustc_type_ir::relate::TypeRelation<I>>::tys
  20: <Infcx as ra_ap_rustc_type_ir::relate::solver_relating::RelateExt>::relate
  21: hir_ty::infer::coerce::Coerce<D>::unify_raw
  22: hir_ty::infer::coerce::Coerce<D>::unify_and
  23: hir_ty::infer::coerce::Coerce<D>::coerce
  24: hir_ty::infer::coerce::<impl hir_ty::infer::InferenceContext>::coerce
  25: hir_ty::infer::coerce::CoerceMany::coerce_inner
  26: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_return
  27: hir_ty::infer::infer_query_with_inspect
  28: salsa::function::execute::<impl salsa::function::IngredientImpl<C>>::execute
  29: salsa::function::fetch::<impl salsa::function::IngredientImpl<C>>::fetch_cold
  30: std::thread::local::LocalKey<T>::with
  31: hir_ty::infer::InferenceResult::for_body
  32: rust_analyzer::cli::analysis_stats::<impl rust_analyzer::cli::flags::AnalysisStats>::run_inference
  33: std::thread::local::LocalKey<T>::with
  34: rust_analyzer::cli::analysis_stats::<impl rust_analyzer::cli::flags::AnalysisStats>::run
  35: rust_analyzer::main

This looks like an issue with salsa cycles?

I've noticed this crash occurring quite a bit recently: not sure if the folks I support have been unlucky with their codebases, or if it's a more common occurrence.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-salsamight be a salsa issueBroken WindowBugs / technical debt to be addressed immediatelyC-bugCategory: bugI-panic

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions