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

Unknown issue "Request textDocument/inlayHint failed" #12768

Closed
CGMossa opened this issue Jul 15, 2022 · 9 comments
Closed

Unknown issue "Request textDocument/inlayHint failed" #12768

CGMossa opened this issue Jul 15, 2022 · 9 comments
Labels
A-ty type system / type inference / traits / method resolution C-support Category: support questions

Comments

@CGMossa
Copy link

CGMossa commented Jul 15, 2022

I'm getting this issue constantly and it is relentless.
I've tried to use release and prelease versions of R-A with no success.

UPDATED: See the updated code error message + code below.

rust-analyzer version: rust-analyzer version: 0.0.0 (5342f47 2022-07-09)
rustc version: rustc 1.62.0 (a8314ef7d 2022-06-27)

relevant settings: UPDATE: I tried to reset all of vscode's settings (including R-As).
This issue is only caused by this fail and it is a huge headache...

@flodiebold
Copy link
Member

Without the source code where this is happening, there's not much we can do. It might be #12193 if you're using GATs.

@CGMossa
Copy link
Author

CGMossa commented Jul 15, 2022

Sorry about that, the source is non-descriptive, and I cannot make it smaller as the issue is not apparent to me.
I'm not using GATs.

Here's both:

Panic context:
> 
version: 0.4.1126-standalone (794ecd58a 2022-07-13)
request: textDocument/inlayHint InlayHintParams {
    work_done_progress_params: WorkDoneProgressParams {
        work_done_token: None,
    },
    text_document: TextDocumentIdentifier {
        uri: Url {
            scheme: "file",
            cannot_be_a_base: false,
            username: "",
            password: None,
            host: None,
            port: None,
            path: "/c%3A/Users/tpb398/Documents/GitHub/blofeld_asf/src/weekly_model/breeding_replacement.rs",
            query: None,
            fragment: None,
        },
    },
    range: Range {
        start: Position {
            line: 0,
            character: 0,
        },
        end: Position {
            line: 150,
            character: 0,
        },
    },
}

thread 'Worker' panicked at 'index out of bounds: the len is 0 but the index is 0', C:\Users\runneradmin\.cargo\registry\src\github.com-1ecc6299db9ec823\chalk-ir-0.83.0\src\lib.rs:2737:10
stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library\std\src\panicking.rs:584
   1: core::panicking::panic_fmt
             at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library\core\src\panicking.rs:142
   2: core::panicking::panic_bounds_check
             at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library\core\src\panicking.rs:84
   3: <&chalk_ir::SubstFolder<I,A> as chalk_ir::fold::TypeFolder<I>>::fold_free_var_lifetime
   4: <chalk_ir::Lifetime<I> as chalk_ir::fold::TypeSuperFoldable<I>>::super_fold_with
   5: <chalk_ir::Ty<I> as chalk_ir::fold::TypeSuperFoldable<I>>::super_fold_with
   6: chalk_ir::fold::boring_impls::<impl chalk_ir::fold::TypeFoldable<I> for chalk_ir::GenericArg<I>>::fold_with
   7: core::iter::adapters::try_process
   8: chalk_ir::fold::boring_impls::<impl chalk_ir::fold::TypeFoldable<I> for chalk_ir::Substitution<I>>::fold_with
   9: <chalk_ir::Ty<I> as chalk_ir::fold::TypeSuperFoldable<I>>::super_fold_with
  10: <chalk_ir::Ty<I> as chalk_ir::fold::TypeSuperFoldable<I>>::super_fold_with
  11: chalk_ir::fold::boring_impls::<impl chalk_ir::fold::TypeFoldable<I> for chalk_ir::GenericArg<I>>::fold_with
  12: core::iter::adapters::try_process
  13: chalk_ir::fold::boring_impls::<impl chalk_ir::fold::TypeFoldable<I> for chalk_ir::Substitution<I>>::fold_with
  14: <chalk_ir::Ty<I> as chalk_ir::fold::TypeSuperFoldable<I>>::super_fold_with
  15: chalk_ir::fold::boring_impls::<impl chalk_ir::fold::TypeFoldable<I> for chalk_ir::GenericArg<I>>::fold_with
  16: core::iter::adapters::try_process
  17: chalk_ir::fold::boring_impls::<impl chalk_ir::fold::TypeFoldable<I> for chalk_ir::Substitution<I>>::fold_with
  18: <chalk_ir::Ty<I> as chalk_ir::fold::TypeSuperFoldable<I>>::super_fold_with
  19: chalk_ir::fold::boring_impls::<impl chalk_ir::fold::TypeFoldable<I> for chalk_ir::GenericArg<I>>::fold_with
  20: core::iter::adapters::try_process
  21: chalk_ir::fold::boring_impls::<impl chalk_ir::fold::TypeFoldable<I> for chalk_ir::Substitution<I>>::fold_with
  22: <chalk_ir::Ty<I> as chalk_ir::fold::TypeSuperFoldable<I>>::super_fold_with
  23: chalk_ir::fold::boring_impls::<impl chalk_ir::fold::TypeFoldable<I> for chalk_ir::GenericArg<I>>::fold_with
  24: core::iter::adapters::try_process
  25: chalk_ir::fold::boring_impls::<impl chalk_ir::fold::TypeFoldable<I> for chalk_ir::Substitution<I>>::fold_with
  26: <chalk_ir::Ty<I> as chalk_ir::fold::TypeSuperFoldable<I>>::super_fold_with
  27: chalk_ir::fold::boring_impls::<impl chalk_ir::fold::TypeFoldable<I> for chalk_ir::GenericArg<I>>::fold_with
  28: core::iter::adapters::try_process
  29: chalk_ir::fold::boring_impls::<impl chalk_ir::fold::TypeFoldable<I> for chalk_ir::Substitution<I>>::fold_with
  30: chalk_ir::_::<impl chalk_ir::fold::TypeFoldable<I> for chalk_ir::WhereClause<I>>::fold_with
  31: chalk_ir::_::<impl chalk_ir::fold::TypeFoldable<I> for chalk_ir::DomainGoal<I>>::fold_with
  32: chalk_ir::_::<impl chalk_ir::fold::TypeFoldable<_I> for chalk_ir::InEnvironment<G>>::fold_with
  33: chalk_solve::infer::InferenceTable<I>::from_canonical
  34: chalk_recursive::solve::SolveIteration::solve_iteration
  35: chalk_recursive::solve::SolveIteration::solve_iteration
  36: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  37: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_root_goal
  38: <hir_ty::db::TraitSolveQueryQuery as salsa::plumbing::QueryFunction>::execute
  39: salsa::runtime::Runtime::execute_query_implementation
  40: core::ptr::drop_in_place<salsa::derived::slot::Memo<hir_ty::db::ProgramClausesForChalkEnvQuery>>
  41: salsa::derived::slot::Slot<Q,MP>::read
  42: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch
  43: salsa::QueryTable<Q>::get
  44: <DB as hir_ty::db::HirDatabase>::trait_solve_query
  45: hir_ty::db::trait_solve_wait
  46: <DB as hir_ty::db::HirDatabase>::trait_solve
  47: hir::Type::impls_trait
  48: ide::inlay_hints::hints
  49: ide::inlay_hints::hints
  50: ide::inlay_hints::hints
  51: <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::fold
  52: ide::inlay_hints::inlay_hints
  53: std::panicking::try
  54: rust_analyzer::handlers::handle_inlay_hints
  55: std::panicking::try
  56: <F as threadpool::FnBox>::call_box
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
[Error - 1:05:46 PM] Request textDocument/inlayHint failed.
  Message: request handler panicked: index out of bounds: the len is 0 but the index is 0
  Code: -32603 

Source:

//! During the year, sows that are set to breed, may have died out. But in reality,
//! these would be replaced with other sows that are allowed to breed, though
//! their breeding time will be shifted.
//!
//! Recording / reporting of this: Unfortunately, this complicates a lot of
//! the breeding events and their annotation; A way to figure out if this
//! has had an effect, would be to count the number of sucessful breeding
//! events with and without replacement, and see if it is closer to the nominal
//! level (e.g. [BreedingCapacity])
//!
use super::animal_group_relation::AnimalGroupMap;
use super::scenario_components::ScenarioIteration;
use super::*;
use crate::scenario_components::ScenarioRng;
use crate::weekly_model::breeding::{
    age_dependent_selection_weeks, sample_breeding_event, BreedingSow,
};
use crate::wild_boar_components::WildBoar;
use crate::wild_boar_type::marker_age_groups::{Adult, Juvenile};
use crate::wild_boar_type::marker_sex::Female;
use crate::wild_boar_type::marker_vital_status::{Alive, Dead};
use crate::wild_boar_type::Time;
use crate::weekly_model::weekly_wild_boar_model_toolbox::AgeWeeks;
#[allow(unused_imports)]
use bevy_log::prelude::*;

/// Using the 3.3.3 rule, 3 months, 3 weeks and 3 days.
const GESTATION_TIME_IN_WEEKS: Time = 16;

/// Parameter for whether or not to perform replacement breeding of the missed
/// events that were missed due to general mortality.
#[derive(
    Debug, Clone, Copy, derive_new::new, derive_more::From, derive_more::Into, Serialize, Component,
)]
pub struct ReplacementBreeding(pub bool);

/// Amends [BreedingSchedule] with replacement events if breeding sows dies
/// out prior to being able to fulfill their duty.
///
/// This should run after mortality, but since it uses the breeding schedule,
/// then it must run after the breeding schedule as well.
///
///
/// This replacement strategy is tied tightly to [crate::weekly_model::breeding]
/// and thus it is advisable to split the breeding-procedure into parts that
/// may be shared with this, so as to maintain cohesion.
///
///
/// Only replace breeding events for sows dying before week 23.
pub fn update_replacement_events(
    mut commands: Commands,
    mut scenario_rng: ResMut<ScenarioRng>,
    mut breeding_schedule: ResMut<BreedingSchedule>,
    scenario_week_counter: Res<WeekCounter>,
    recently_dead_breeding_sows: Query<
        (Entity, &GroupEntity),
        (
            With<WildBoar>,
            Or<(With<Juvenile>, With<Adult>)>,
            Added<Dead>,
            With<BreedingSow>,
        ),
    >,
    // sows that aren't breeding this season
    q_sows: Query<
        (Entity, &AgeWeeks, &GroupEntity),
        (
            With<WildBoar>,
            With<Female>,
            With<Alive>,
            Or<(With<Juvenile>, With<Adult>)>,
            Without<BreedingSow>,
        ),
    >,
    group_map: Res<AnimalGroupMap>,
    q_scenarios: Query<&ReplacementBreeding, With<ScenarioIteration>>,
    q_groups: Query<(), With<WildBoarGroup>>,
) {
    // take note of any deceased animals before week 23
    if scenario_week_counter.week > 23 {
        //skip weeks after 23
        return;
    }

    // dbg!(scenario_week_counter.week);
    let current_week = scenario_week_counter.week;
    // determine which breeding events (and in which groups) that need to be replaced.
    let replacement_breeding_events: HashMap<GroupEntity, Vec<(GroupEntity, BreedingEvent)>> =
        recently_dead_breeding_sows
            .iter()
            .filter_map(|(animal_entity, group_entity)| {
                let dam_group = *group_entity;

                // find out if the replacement-breeding is enabled for this particular
                // iteration
                let scenario_iteration_entity = group_map.get_outgoing_entity(dam_group.into());
                let replacement_breeding = q_scenarios.get(scenario_iteration_entity).unwrap();
                if !replacement_breeding.0 {
                    return None;
                }

                // determine mating date
                let mating_date = current_week + scenario_rng.gen_range(1..=4);
                if mating_date > 23 {
                    return None;
                }

                // new breeding event..
                let new_breeding_date = mating_date + GESTATION_TIME_IN_WEEKS;
                let new_breeding_event = sample_breeding_event(scenario_rng.as_mut().as_mut());
                // remove replacement event where litter-size zero
                new_breeding_event.as_ref()?;
                let mut new_breeding_event = new_breeding_event.unwrap();
                new_breeding_event.week = new_breeding_date as usize;

                Some((dam_group, new_breeding_event))
            })
            // group by groups, as to determine which groups needs to have their
            // breeding events replaced; more than one replacement event may be
            // necessary for a given group
            .into_group_map_by(|(group_entity, _breeding_event)| *group_entity);

    // assign this to a sow that isn't currently breeding...
    let new_breeding_events: Vec<(GroupEntity, Entity, BreedingEvent)> = q_sows
        .iter()
        .filter(|(animal_entity, _age_weeks, group_entity)| {
            // only select groups that have replacement events queued up
            replacement_breeding_events.contains_key(group_entity)
        })
        // {(group_entity) | set to replacement breed } -> {(animal_entity, age) for females, juvenile>=, not breeding sows}
        .into_group_map_by(|(animal_entity, age_weeks, group_entity)| **group_entity)
        .iter()
        .filter_map(move |(group_entity, eligible_sows)| {
            // no replacement sows are available
            if eligible_sows.is_empty() {
                return None;
            }

            // select sows that are to execute the replacement events.
            let replacement_events = replacement_breeding_events
                .get(group_entity)
                .unwrap()
                .clone();
            let replacement_sows = eligible_sows
                .choose_multiple_weighted(
                    scenario_rng.as_mut().as_mut(),
                    replacement_events.len(),
                    |(_0, _1, age_weeks)| age_dependent_selection_weeks(age_weeks.0),
                )
                .unwrap();

            // prepare the replacement events
            // there are more replacement events than sows that may take over...
            Some(replacement_events.into_iter().zip(replacement_sows).map(
                |(
                    (_group_entity, new_breeding_event),
                    (sow_group_entity, sow_entity, _sow_age_weeks),
                )| { (**sow_group_entity, *sow_entity, new_breeding_event) },
            ))
        })
        .flatten()
        .collect();

    if !new_breeding_events.is_empty() {
        // the new sows that are (now) breeding, needs to be added to the record of
        // breeding sows.
        new_breeding_events.iter().for_each(|(_0, sow_entity, _2)| {
            commands.entity(sow_entity).insert(BreedingSow);
        });

        // dbg!(new_breeding_events.len());
        // Add replacement events to the breeding schedule!
        breeding_schedule.push_breeding_events(new_breeding_events);
    }
}

@CGMossa
Copy link
Author

CGMossa commented Jul 16, 2022

Maybe related to #12600 and #12674. Unsure though

@flodiebold
Copy link
Member

Might indeed be #12674. I think it's unrelated to proc macros.

@flodiebold flodiebold added A-ty type system / type inference / traits / method resolution C-support Category: support questions labels Jul 16, 2022
@lowr
Copy link
Contributor

lowr commented Sep 12, 2022

@CGMossa #12674 has been fixed by #13223, but I couldn't test your code as there are too many external types. Would you mind checking whether #13223 fixes your crash if you still have the crashing code?

@CGMossa
Copy link
Author

CGMossa commented Sep 12, 2022

Is that part of the new release?

@lowr
Copy link
Contributor

lowr commented Sep 12, 2022

No, it'll be released next Monday. It would be appreciated if you could build rust-analyzer locally and test it, but waiting for next release is perfectly fine.

@lnicola
Copy link
Member

lnicola commented Sep 12, 2022

A new nightly will be available tomorrow.

@CGMossa
Copy link
Author

CGMossa commented Sep 12, 2022 via email

@CGMossa CGMossa closed this as completed Sep 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ty type system / type inference / traits / method resolution C-support Category: support questions
Projects
None yet
Development

No branches or pull requests

4 participants