Skip to content

'called Option::unwrap() on a None value' when editing KAS GUI applications #10386

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

Closed
nyanpasu64 opened this issue Sep 29, 2021 · 18 comments · Fixed by #10456
Closed

'called Option::unwrap() on a None value' when editing KAS GUI applications #10386

nyanpasu64 opened this issue Sep 29, 2021 · 18 comments · Fixed by #10456
Labels
A-ty type system / type inference / traits / method resolution Broken Window Bugs / technical debt to be addressed immediately C-bug Category: bug S-actionable Someone could pick this issue up and work on it right now

Comments

@nyanpasu64
Copy link

When I clone kas (https://github.com/kas-gui/kas) and open an example file, every edit or lookup triggers a rust-analyzer panic:

Output log and stack trace
Panic context:
> 
version: 009e6ceb1 2021-09-27 stable
request: textDocument/semanticTokens/full/delta SemanticTokensDeltaParams {
    work_done_progress_params: WorkDoneProgressParams {
        work_done_token: None,
    },
    partial_result_params: PartialResultParams {
        partial_result_token: None,
    },
    text_document: TextDocumentIdentifier {
        uri: Url {
            scheme: "file",
            cannot_be_a_base: false,
            username: "",
            password: None,
            host: None,
            port: None,
            path: "/home/nyanpasu64/code/kas/examples/counter.rs",
            query: None,
            fragment: None,
        },
    },
    previous_result_id: "2",
}

thread '<unnamed>' panicked at 'called `Option::unwrap()` on a `None` value', /home/runner/.cargo/registry/src/gb.xjqchip.workers.dev-1ecc6299db9ec823/salsa-0.17.0-pre.1/src/runtime.rs:324:18
stack backtrace:
   0: rust_begin_unwind
             at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/panicking.rs:515:5
   1: core::panicking::panic_fmt
             at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/core/src/panicking.rs:92:14
   2: core::panicking::panic
             at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/core/src/panicking.rs:50:5
   3: salsa::runtime::Runtime::report_unexpected_cycle
   4: salsa::derived::slot::Slot<Q,MP>::read
   5: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch
   6: <DB as hir_ty::db::HirDatabase>::generic_predicates_for_param
   7: hir_ty::lower::TyLoweringContext::lower_ty_relative_path
   8: hir_ty::lower::TyLoweringContext::lower_partly_resolved_path
   9: hir_ty::lower::TyLoweringContext::lower_ty_ext
  10: hir_ty::lower::TyLoweringContext::substs_from_path_segment
  11: hir_ty::lower::TyLoweringContext::lower_trait_ref_from_path
  12: hir_ty::lower::TyLoweringContext::lower_type_bound
  13: hir_ty::lower::TyLoweringContext::lower_where_predicate
  14: <core::iter::adapters::flatten::FlatMap<I,U,F> as core::iter::traits::iterator::Iterator>::next
  15: <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter
  16: hir_ty::lower::generic_predicates_for_param_query
  17: salsa::runtime::Runtime::execute_query_implementation
  18: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  19: salsa::derived::slot::Slot<Q,MP>::maybe_changed_since
  20: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::maybe_changed_since
  21: salsa::derived::slot::MemoRevisions::validate_memoized_value
  22: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  23: salsa::derived::slot::Slot<Q,MP>::maybe_changed_since
  24: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::maybe_changed_since
  25: salsa::derived::slot::MemoRevisions::validate_memoized_value
  26: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  27: salsa::derived::slot::Slot<Q,MP>::maybe_changed_since
  28: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::maybe_changed_since
  29: salsa::derived::slot::MemoRevisions::validate_memoized_value
  30: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  31: salsa::derived::slot::Slot<Q,MP>::maybe_changed_since
  32: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::maybe_changed_since
  33: salsa::derived::slot::MemoRevisions::validate_memoized_value
  34: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  35: salsa::derived::slot::Slot<Q,MP>::maybe_changed_since
  36: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::maybe_changed_since
  37: salsa::derived::slot::MemoRevisions::validate_memoized_value
  38: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  39: salsa::derived::slot::Slot<Q,MP>::read
  40: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch
  41: <DB as hir_ty::db::HirDatabase>::infer_query
  42: hir_ty::db::infer_wait
  43: hir::source_analyzer::SourceAnalyzer::new_for_body
  44: hir::semantics::SemanticsImpl::analyze_impl
  45: ide_db::defs::NameClass::classify
  46: ide::syntax_highlighting::highlight::element
  47: ide::syntax_highlighting::traverse
  48: ide::syntax_highlighting::highlight
  49: std::panicking::try
  50: rust_analyzer::handlers::handle_semantic_tokens_full_delta
  51: std::panicking::try
  52: <F as threadpool::FnBox>::call_box
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
[Error - 12:41:02 AM] Request textDocument/semanticTokens/full/delta failed.
  Message: server panicked: called `Option::unwrap()` on a `None` value
  Code: -32603 

I think this is related to #5001. I think kas is valid code, but I'm getting report_unexpected_cycle crashes anyway.

The error goes away when I disable rust-analyzer.procMacro.enable or remove all methods from the make_widget! { impl { block.

Currently on vscode 1.60.2 and rust-analyzer extension v0.2.760 (both latest I think).
rust-analyzer version: 009e6ce 2021-09-27 stable

Is there anything that needs to be done to expand macros or minify the test case?

@lnicola
Copy link
Member

lnicola commented Sep 29, 2021

Can you try with a nightly? I was able to reproduce it before (but not after) #10353, and there was also #10305 touching that code.

CC @SkiFire13 just in case.

Unfortunately, I did get this after #10305:

thread '<unnamed>' panicked at 'index out of bounds: the len is 0 but the index is 0', ~/.cargo/registry/src/gb.xjqchip.workers.dev-1ecc6299db9ec823/chalk-ir-0.71.0/src/lib.rs:2752:10
stack backtrace:
   0: rust_begin_unwind
             at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/panicking.rs:515:5
   1: core::panicking::panic_fmt
             at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/core/src/panicking.rs:92:14
   2: core::panicking::panic_bounds_check
             at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/core/src/panicking.rs:69:5
   3: <&chalk_ir::SubstFolder<I,A> as chalk_ir::fold::Folder<I>>::fold_free_var_ty
   4: <chalk_ir::Ty<I> as chalk_ir::fold::SuperFold<I>>::super_fold_with
   5: chalk_ir::fold::boring_impls::<impl chalk_ir::fold::Fold<I> for chalk_ir::GenericArg<I>>::fold_with
   6: <smallvec::SmallVec<A> as core::iter::traits::collect::Extend<<A as smallvec::Array>::Item>>::extend
   7: chalk_ir::fold::boring_impls::<impl chalk_ir::fold::Fold<I> for chalk_ir::Substitution<I>>::fold_with
   8: <chalk_ir::Ty<I> as chalk_ir::fold::SuperFold<I>>::super_fold_with
   9: chalk_ir::fold::boring_impls::<impl chalk_ir::fold::Fold<I> for chalk_ir::GenericArg<I>>::fold_with
  10: <smallvec::SmallVec<A> as core::iter::traits::collect::Extend<<A as smallvec::Array>::Item>>::extend
  11: chalk_ir::fold::boring_impls::<impl chalk_ir::fold::Fold<I> for chalk_ir::Substitution<I>>::fold_with
  12: chalk_ir::_::<impl chalk_ir::fold::Fold<I> for chalk_ir::WhereClause<I>>::fold_with
  13: chalk_ir::_::<impl chalk_ir::fold::Fold<I> for chalk_ir::DomainGoal<I>>::fold_with
  14: chalk_ir::_::<impl chalk_ir::fold::Fold<_I> for chalk_ir::InEnvironment<G>>::fold_with
  15: chalk_solve::infer::InferenceTable<I>::from_canonical
  16: chalk_recursive::solve::SolveIteration::solve_iteration
  17: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  18: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_root_goal
  19: hir_ty::traits::trait_solve_query
  20: salsa::runtime::Runtime::execute_query_implementation
  21: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  22: salsa::derived::slot::Slot<Q,MP>::read
  23: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch
  24: <DB as hir_ty::db::HirDatabase>::trait_solve_query::__shim
  25: <DB as hir_ty::db::HirDatabase>::trait_solve_query
  26: hir_ty::db::trait_solve_wait
  27: <DB as hir_ty::db::HirDatabase>::trait_solve
  28: hir_ty::autoderef::deref_by_trait
  29: hir_ty::autoderef::deref
  30: <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::fold
  31: <hashbrown::map::HashMap<K,V,S,A> as core::iter::traits::collect::Extend<(K,V)>>::extend
  32: ide_db::helpers::import_assets::trait_applicable_items
  33: ide_db::helpers::import_assets::ImportAssets::search_for
  34: ide_db::helpers::import_assets::ImportAssets::search_for_imports
  35: ide_completion::completions::flyimport::import_on_the_fly
  36: ide_completion::completions
  37: std::panicking::try
  38: ide::Analysis::completions
  39: rust_analyzer::handlers::handle_completion
  40: std::panicking::try
  41: <F as threadpool::FnBox>::call_box
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
  103ms - handle_completion
        0   - Semantics::analyze_impl (7 calls)
        3ms - SourceBinder::to_module_def (3 calls)
        0   - crate_def_map:wait (22 calls)
       37ms - descend_into_macros (1 calls)
       12ms - import_on_the_fly (1 calls)
       32ms - iterate_path_candidates (1 calls)
[Error - 13:03:17] Request textDocument/completion failed.
  Message: server panicked: index out of bounds: the len is 0 but the index is 0
  Code: -32603

@dhardy
Copy link

dhardy commented Sep 29, 2021

The file in question: examples/counter.rs.

Using:

$ rls --version
rls 1.41.0 (a82a052 2021-07-21)
$ kate --version
kate 21.08.0

I don't see this error myself, and the RLS plugin is able to report errors within the macro as well as link some of the symbols (Label<String> and VoidMsg) but not others (row!, TextButton and handle_button, the latter not being at all surprising since linkage is defined by the macro).

@lnicola
Copy link
Member

lnicola commented Sep 29, 2021

RLS and rust-analyzer are quite unrelated, and I'd generally expect RLS to be more precise when it works.

For the record, I checked in with the calculator example. I got that crash when editing the code inside the make_widget call.

@jonas-schievink
Copy link
Contributor

The salsa bug is salsa-rs/salsa#257

@SkiFire13
Copy link
Contributor

Can you try with a nightly? I was able to reproduce it before (but not after) #10353, and there was also #10305 touching that code.

CC @SkiFire13 just in case.

Unfortunately, I did get this after #10305:

For the record, I checked in with the calculator example. I got that crash when editing the code inside the make_widget call.

Unfortunately I'm not able to reproduce this. Both nightly and a local-built version seem to not trigger even the salsa panic with the calculator example. They still trigger it with the counter example, but it's not the chalk one.

@nyanpasu64
Copy link
Author

I've created a minimal test case (place this at "examples/counter-expand.rs"):

use std::marker::PhantomData;

struct AnonWidget<T: kas::Widget> {
    buttons: PhantomData<T>,
}

impl<T: kas::Widget> AnonWidget<T> {
    // removing &self stops crashes
    fn fmt(&self) {
        // type something and press ctrl+space on a new line to trigger panic

    }
}

fn main() {}

This doesn't crash on every keystroke like before, but if you place the cursor on the blank line, then repeatedly type some gibberish and trigger autocomplete, within a few cycles you should get rust-analyzer to start panicking (even if you disable proc macros).

rust.analyzer.kas.panic.mp4
Output log and stack trace:
Panic context:
> 
version: 009e6ceb1 2021-09-27 stable
request: textDocument/completion CompletionParams {
    text_document_position: TextDocumentPositionParams {
        text_document: TextDocumentIdentifier {
            uri: Url {
                scheme: "file",
                cannot_be_a_base: false,
                username: "",
                password: None,
                host: None,
                port: None,
                path: "/home/nyanpasu64/code/kas/examples/counter-expand.rs",
                query: None,
                fragment: None,
            },
        },
        position: Position {
            line: 10,
            character: 9,
        },
    },
    work_done_progress_params: WorkDoneProgressParams {
        work_done_token: None,
    },
    partial_result_params: PartialResultParams {
        partial_result_token: None,
    },
    context: Some(
        CompletionContext {
            trigger_kind: Invoked,
            trigger_character: None,
        },
    ),
}

thread '<unnamed>' panicked at 'called `Option::unwrap()` on a `None` value', /home/runner/.cargo/registry/src/gb.xjqchip.workers.dev-1ecc6299db9ec823/salsa-0.17.0-pre.1/src/runtime.rs:324:18
stack backtrace:
   0: rust_begin_unwind
             at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/panicking.rs:515:5
   1: core::panicking::panic_fmt
             at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/core/src/panicking.rs:92:14
   2: core::panicking::panic
             at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/core/src/panicking.rs:50:5
   3: salsa::runtime::Runtime::report_unexpected_cycle
   4: salsa::derived::slot::Slot<Q,MP>::read
   5: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch
   6: <DB as hir_ty::db::HirDatabase>::generic_predicates_for_param
   7: hir_ty::lower::TyLoweringContext::lower_ty_relative_path
   8: hir_ty::lower::TyLoweringContext::lower_partly_resolved_path
   9: hir_ty::lower::TyLoweringContext::lower_ty_ext
  10: hir_ty::lower::TyLoweringContext::substs_from_path_segment
  11: hir_ty::lower::TyLoweringContext::lower_trait_ref_from_path
  12: hir_ty::lower::TyLoweringContext::lower_type_bound
  13: hir_ty::lower::TyLoweringContext::lower_where_predicate
  14: <core::iter::adapters::flatten::FlatMap<I,U,F> as core::iter::traits::iterator::Iterator>::next
  15: <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter
  16: hir_ty::lower::generic_predicates_for_param_query
  17: salsa::runtime::Runtime::execute_query_implementation
  18: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  19: salsa::derived::slot::Slot<Q,MP>::maybe_changed_since
  20: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::maybe_changed_since
  21: salsa::derived::slot::MemoRevisions::validate_memoized_value
  22: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  23: salsa::derived::slot::Slot<Q,MP>::maybe_changed_since
  24: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::maybe_changed_since
  25: salsa::derived::slot::MemoRevisions::validate_memoized_value
  26: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  27: salsa::derived::slot::Slot<Q,MP>::maybe_changed_since
  28: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::maybe_changed_since
  29: salsa::derived::slot::MemoRevisions::validate_memoized_value
  30: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  31: salsa::derived::slot::Slot<Q,MP>::maybe_changed_since
  32: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::maybe_changed_since
  33: salsa::derived::slot::MemoRevisions::validate_memoized_value
  34: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  35: salsa::derived::slot::Slot<Q,MP>::read
  36: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch
  37: <DB as hir_ty::db::HirDatabase>::trait_solve_query::__shim
  38: <DB as hir_ty::db::HirDatabase>::trait_solve_query
  39: hir_ty::db::trait_solve_wait
  40: <DB as hir_ty::db::HirDatabase>::trait_solve
  41: hir_ty::method_resolution::iterate_trait_method_candidates
  42: hir_ty::method_resolution::iterate_method_candidates_by_receiver
  43: hir_ty::method_resolution::iterate_method_candidates_dyn
  44: hir::Type::iterate_method_candidates_dyn
  45: hir::Type::iterate_method_candidates
  46: ide_completion::completions::dot::complete_undotted_self::{{closure}}
  47: hir::semantics::SemanticsScope::process_all_names
  48: ide_completion::completions::dot::complete_dot
  49: ide_completion::completions
  50: std::panicking::try
  51: rust_analyzer::handlers::handle_completion
  52: std::panicking::try
  53: <F as threadpool::FnBox>::call_box
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
[Error - 1:46:13 PM] Request textDocument/completion failed.
  Message: server panicked: called `Option::unwrap()` on a `None` value
  Code: -32603 

The interesting thing I noticed is that kas::Widget is a child of an absurdly long chain of trait single inheritance, ending with pub trait WidgetCore: Any + fmt::Debug. If necessary, I can try to further minimize this by removing the dependence on kas::Widget.

I also get a Salsa crash on "rust-analyzer version: 533ca58 2021-09-28 nightly" (output log and stack trace).

@tmandry
Copy link
Member

tmandry commented Sep 29, 2021

Unfortunately, I did get this after #10305:

Me too. Filed #10390 for this.

@nyanpasu64
Copy link
Author

The full chain of traits is:

  • kas::Widget
  • kas::event::SendEvent
  • kas::event::Handler
  • kas::WidgetConfig
  • kas::Layout
  • kas::WidgetChildren
  • kas::WidgetCore
  • Any + Debug

with some of these traits being re-exports.

I found that all child traits including kas::event::Handler crash, while all parent traits not including it do not crash. And that pub trait Handler { type Msg: 'static; } is sufficient to induce the crash.

Screenshot_20210929_150241

This should be a highly minimal test case. It crashes on completion, including when I restart rust-analyzer or vscode. Unfortunately, I can't reproduce the crash when I move Handler into the same file, either inline with AnonWidget or in a child module.

Is there some local state in my target directory or elsewhere, which could "prime" rust-analyzer to break on certain types, when it wouldn't break on a fresh clone? I haven't tested reproducing this on a fresh clone, but I'm working under the assumption that rust-analyzer has no memory saved across restarts, and this crash isn't related to cached state.


Sometimes clearing out my code stops the crashes, sometimes rust-analyzer even crashes on an empty file and I have to restart RA or vscode to stop the panics.

I found that switching Handler to pub trait Handler { type Msg2: 'static; } still reproduces the crash, but renaming Handler (in event/handler.rs and/or event/mod.rs) stops the crash. I suspect the crash is caused by the usages of this trait (impl Handler for T or impl Trait for Handler), not the trait itself.

@nyanpasu64
Copy link
Author

nyanpasu64 commented Sep 29, 2021

I found that stubbing out the entire kas-widgets crate fixed the crash. While searching through kas-widgets, I found my stripped-down version of mod single_view's struct SingleView was necessary and sufficient to reproduce the crash, if most other modules were stubbed out (kas_widgets was reduced to pub mod view; and kas_widgets::view was reduced to pub mod single_view; pub mod driver; pub use driver::Driver;). I can upload my cut-down git repository if needed. (There may be other sources for similar crashes, which I have not tried to identify.)

Screenshot_20210929_161616

https://github.com/kas-gui/kas/blob/986d013171aa92741b03d64696b83d8bd91daaf4/crates/kas-widgets/src/view/single_view.rs#L30-L33

struct SingleView has 2 type parameters, each with a trait bound constrained by the other type parameter's associated type. This is consistent with the original crash message mentioning report_unexpected_cycle.

Note that T::Item is defined in SingleData and not UpdHandler, so in one sense it's not a cycle. rust-analyzer crashes whether I include SingleData or not in the trait list. I don't know if this code should be valid or not, but I think it compiles fine in rustc.

EDIT: Even in source files where there's truly a cycle, salsa should report an error and not panic.

@lnicola
Copy link
Member

lnicola commented Sep 30, 2021

This doesn't crash on every keystroke like before, but if you place the cursor on the blank line, then repeatedly type some gibberish and trigger autocomplete, within a few cycles you should get rust-analyzer to start panicking (even if you disable proc macros).

Okay, it looks a bit different from yours but I still get a panic on b21f15a23767c8d06ab5da60f59b8b197c45831a with that test case:

thread '<unnamed>' panicked at 'called `Option::unwrap()` on a `None` value', ~/.cargo/registry/src/gb.xjqchip.workers.dev-1ecc6299db9ec823/salsa-0.17.0-pre.1/src/runtime.rs:324:18
stack backtrace:
   0: rust_begin_unwind
             at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/panicking.rs:515:5
   1: core::panicking::panic_fmt
             at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/core/src/panicking.rs:92:14
   2: core::panicking::panic
             at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/core/src/panicking.rs:50:5
   3: salsa::runtime::Runtime::report_unexpected_cycle
   4: salsa::derived::slot::Slot<Q,MP>::read
   5: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch
   6: <DB as hir_ty::db::HirDatabase>::generic_predicates_for_param::__shim
   7: hir_ty::lower::associated_type_shorthand_candidates
   8: hir_ty::lower::TyLoweringContext::lower_ty_relative_path
   9: hir_ty::lower::TyLoweringContext::lower_partly_resolved_path
  10: hir_ty::lower::TyLoweringContext::lower_ty_ext
  11: hir_ty::lower::TyLoweringContext::substs_from_path_segment
  12: hir_ty::lower::TyLoweringContext::lower_trait_ref_from_path
  13: hir_ty::lower::TyLoweringContext::lower_type_bound
  14: hir_ty::lower::TyLoweringContext::lower_where_predicate
  15: <core::iter::adapters::flatten::FlatMap<I,U,F> as core::iter::traits::iterator::Iterator>::next
  16: <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter
  17: hir_ty::lower::generic_predicates_for_param_query
  18: salsa::runtime::Runtime::execute_query_implementation
  19: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  20: salsa::derived::slot::Slot<Q,MP>::maybe_changed_since
  21: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::maybe_changed_since
  22: salsa::derived::slot::MemoRevisions::validate_memoized_value
  23: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  24: salsa::derived::slot::Slot<Q,MP>::maybe_changed_since
  25: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::maybe_changed_since
  26: salsa::derived::slot::MemoRevisions::validate_memoized_value
  27: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  28: salsa::derived::slot::Slot<Q,MP>::maybe_changed_since
  29: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::maybe_changed_since
  30: salsa::derived::slot::MemoRevisions::validate_memoized_value
  31: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  32: salsa::derived::slot::Slot<Q,MP>::maybe_changed_since
  33: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::maybe_changed_since
  34: salsa::derived::slot::MemoRevisions::validate_memoized_value
  35: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  36: salsa::derived::slot::Slot<Q,MP>::read
  37: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch
  38: <DB as hir_ty::db::HirDatabase>::trait_solve_query::__shim
  39: <DB as hir_ty::db::HirDatabase>::trait_solve_query
  40: hir_ty::db::trait_solve_wait
  41: <DB as hir_ty::db::HirDatabase>::trait_solve
  42: hir_ty::method_resolution::iterate_trait_method_candidates
  43: hir_ty::method_resolution::iterate_method_candidates_by_receiver
  44: hir_ty::method_resolution::iterate_method_candidates_dyn
  45: hir::Type::iterate_method_candidates_dyn
  46: hir::Type::iterate_method_candidates
  47: ide_completion::completions::dot::complete_methods
  48: ide_completion::completions::dot::complete_undotted_self::{{closure}}
  49: hir::semantics::SemanticsScope::process_all_names
  50: ide_completion::completions::dot::complete_dot
  51: ide_completion::completions
  52: std::panicking::try
  53: ide::Analysis::completions
  54: rust_analyzer::handlers::handle_completion
  55: std::panicking::try
  56: <F as threadpool::FnBox>::call_box

By the way, what version are you on?

I also get a Salsa crash on "rust-analyzer version: 533ca58 2021-09-28 nightly" (output log and stack trace).

But in your log there's:

version: 009e6ceb1 2021-09-27 stable

@lnicola lnicola added A-ty type system / type inference / traits / method resolution Broken Window Bugs / technical debt to be addressed immediately C-bug Category: bug S-actionable Someone could pick this issue up and work on it right now labels Sep 30, 2021
@nyanpasu64
Copy link
Author

My nightly log is at https://gist.githubusercontent.com/nyanpasu64/b013f27321ed5ff467bbb6c4102a3484/raw/fd7bc4c4f0d66e3e84a75671e1e2d314772c5780/gistfile1.txt. IIRC the 09/29 build crashes in the same circumstances, but I didn't check that the stack traces match.

Also I think SingleView is the problem.

@dhardy
Copy link

dhardy commented Sep 30, 2021

And that pub trait Handler { type Msg: 'static; } is sufficient to induce the crash.

This is a very recent change, so I wonder if some stale cache might be responsible?

Also I think SingleView is the problem.

Not also ListView and MatrixView?

@lnicola
Copy link
Member

lnicola commented Sep 30, 2021

@dhardy Unfortunately, rust-analyzer doesn't have persistent caching.

@nyanpasu64
Copy link
Author

I wonder if some stale cache might be responsible?

I cloned the repo 1 or 2 days ago, and Msg was there since the initial clone, so I think I cloned after that commit was made.

Not also ListView and MatrixView?

I think those files break rust-analyzer too (opening those files and trying to edit them crashes). What my initial tests found was that if I removed all other views, then SingleView was necessary and sufficient to break rust-analyzer.

@nyanpasu64
Copy link
Author

nyanpasu64 commented Sep 30, 2021

Minimal test case:

trait HasT {
    type T;
}

struct Foo<A: HasT + Into<B::T>, B: HasT + Into<A::T>> {
    a: A,
    b: B,
}

(If I change either B::T to B, or A::T to A, the bug no longer triggers.)

Paste this into an empty project. It works fine. Then comment out type T; and everything you do (type, autocomplete, move the cursor, breathe) will trigger panics. If you uncomment the line, the panics continue on many (all?) requests, meaning internal state has been corrupted see #10386 (comment).

The salsa bug is salsa-rs/salsa#257

This has the same error message (stack trace link. However, in this issue, generic_predicates_for_param calls try_fetch, while in the salsa bug, cycle_a calls try_fetch. Are these the same bug or not?

Should I comment on that issue to trigger an email, or file a separate Salsa bug report?

@jonas-schievink
Copy link
Contributor

The salsa bug is already known and a fix was discussed recently in the salsa Zulip

@jonas-schievink
Copy link
Contributor

jonas-schievink commented Sep 30, 2021

Paste this into an empty project. It works fine.

I already get the panic by just pasting the code as-is (and typing something), so there's probably no issue with r-a's internal state going out of sync here.

@jonas-schievink
Copy link
Contributor

Since rustc does not error on that code, but r-a seems to make use of query cycle recovery, there's two bugs here:

Since we have a way to reproduce the bug, fixing the first bug should be possible now.

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 Broken Window Bugs / technical debt to be addressed immediately C-bug Category: bug S-actionable Someone could pick this issue up and work on it right now
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants