Skip to content

Out-of-bounds panics in Worker thread #16200

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
holly-hacker opened this issue Dec 26, 2023 · 6 comments · Fixed by #16221
Closed

Out-of-bounds panics in Worker thread #16200

holly-hacker opened this issue Dec 26, 2023 · 6 comments · Fixed by #16221
Labels
Broken Window Bugs / technical debt to be addressed immediately C-bug Category: bug E-easy E-has-instructions Issue has some instructions and pointers to code to get started

Comments

@holly-hacker
Copy link
Contributor

rust-analyzer version: 0.4.1783-standalone (85fb463 2023-12-24)

rustc version: rustc 1.74.1 (a28077b28 2023-12-04)

relevant settings: n/a


Today when I started using rust-analyzer in a private project, I started getting a lot of errors out of nowhere when typing and hovering over text. The panic message is always an index out of bounds, and it happened on both the current release and current pre-release version of rust-analyzer.

thread 'Worker' panicked at C:\Users\runneradmin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\rust-analyzer-salsa-0.17.0-pre.4\src\interned.rs:107:32:
index out of bounds: the len is 85655 but the index is 4294967039
stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library\std\src\panicking.rs:597
   1: core::panicking::panic_fmt
             at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library\core\src\panicking.rs:72
   2: core::panicking::panic_bounds_check
             at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library\core\src\panicking.rs:180
   3: salsa::QueryTable<Q>::get
   4: <DB as hir_expand::db::ExpandDatabase>::lookup_intern_syntax_context
   5: hir_expand::mod_path::resolve_crate_root
   6: hir_expand::mod_path::convert_path
   7: hir_expand::mod_path::convert_path
   8: hir_expand::mod_path::convert_path
   9: hir_expand::mod_path::convert_path
  10: hir_def::item_tree::lower::Ctx::lower_macro_call
  11: hir_def::item_tree::lower::Ctx::lower_mod_item
  12: hir_def::item_tree::ItemTree::file_item_tree_query
  13: salsa::Cycle::catch
  14: salsa::derived::slot::Slot<Q,MP>::evict
  15: salsa::derived::slot::Slot<Q,MP>::read
  16: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::fetch
  17: <DB as hir_def::db::DefDatabase>::file_item_tree
  18: hir_def::nameres::collector::DefCollector::record_resolved_import
  19: hir_def::data::StaticData::static_data_query
  20: hir_def::nameres::DefMap::block_def_map_query
  21: salsa::Cycle::catch
  22: salsa::derived::slot::Slot<Q,MP>::evict
  23: salsa::derived::slot::Slot<Q,MP>::read
  24: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::fetch
  25: <DB as hir_def::db::DefDatabase>::block_def_map
  26: hir_def::body::lower::ExprCollector::collect_stmt
  27: hir_def::body::lower::ExprCollector::maybe_collect_expr
  28: hir_def::body::lower::ExprCollector::collect_stmt
  29: <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::fold
  30: hir_def::body::lower::ExprCollector::collect_stmt
  31: hir_def::body::lower::ExprCollector::maybe_collect_expr
  32: hir_def::body::lower::ExprCollector::collect_stmt
  33: <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::fold
  34: hir_def::body::lower::ExprCollector::check_cfg
  35: hir_def::body::lower::ExprCollector::maybe_collect_expr
  36: <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter
  37: <alloc::boxed::Box<[I]> as core::iter::traits::collect::FromIterator<I>>::from_iter
  38: hir_def::body::lower::ExprCollector::maybe_collect_expr
  39: hir_def::body::lower::ExprCollector::collect_stmt
  40: hir_def::body::lower::ExprCollector::maybe_collect_expr
  41: hir_def::body::lower::ExprCollector::collect_expr_opt
  42: hir_def::body::lower::lower
  43: hir_def::body::Body::body_with_source_map_query
  44: salsa::Cycle::catch
  45: salsa::derived::slot::Slot<Q,MP>::evict
  46: salsa::derived::slot::Slot<Q,MP>::read
  47: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::fetch
  48: hir::DefWithBody::diagnostics
  49: hir::ModuleDef::diagnostics
  50: hir::Module::diagnostics
  51: hir::DefWithBody::diagnostics
  52: hir::Module::diagnostics
  53: ide_diagnostics::diagnostics
  54: std::panicking::try
  55: ide::Analysis::assists_with_fixes
  56: rust_analyzer::handlers::request::handle_code_action
  57: std::panicking::try
  58: core::ops::function::FnOnce::call_once{{vtable.shim}}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
Panic context:
> 
version: 0.4.1783-standalone (85fb463fc 2023-12-24)
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: "/-snip-/src/routes/api.rs",
            query: None,
            fragment: None,
        },
    },
    previous_result_id: "2",
}
@holly-hacker holly-hacker added the C-bug Category: bug label Dec 26, 2023
@Exotik850
Copy link

Happening to me as well, constantly crashing until it goes to the "Rust-analyzer has crashed 5 times in the last 3 minutes" spiel,
Rustc version: 1.76.0-nightly (6b771f6b5 2023-11-15)
Rust-analyzer extension version: v0.3.1782
Windows 11

@lnicola lnicola added the Broken Window Bugs / technical debt to be addressed immediately label Dec 29, 2023
@lnicola
Copy link
Member

lnicola commented Dec 29, 2023

Does anyone have a way to reproduce this?

@holly-hacker
Copy link
Contributor Author

holly-hacker commented Dec 30, 2023

I've created a fairly minimal example. It depends on rocket v0.5.0, my apologies for the large dependency.

fn main() {}

#[rocket::get("/my-api?<url>")]
async fn ra_16200_repro(url: &str) -> Result<(), ()> {
    Ok(())
}

The error seems to occur here when overing over Result.

Running cargo expand on this results in a very large blob of code that I can't minimize myself, but I hope this is enough to recreate this panic on your end.

In case exact dependencies are important, I've zipped a cargo clean-ed version of my repro project: ra-16200-repro.zip


It's worth noting that in my own codebase, the error happens more often than in this repro (where it only seems to happen when hovering over Result).

@Veykril
Copy link
Member

Veykril commented Dec 30, 2023

4294967039 is a SyntaxContextId::SELF_REF so we are failing to accomodate for that somewhere

@Veykril
Copy link
Member

Veykril commented Dec 30, 2023

let parent = opaque_and_semitransparent;

and
let parent = opaque;

may point to SELF_REF which breaks my assumption that they only occur in opaque_and_semitransparent and opaque fields, we should do a SELF_REF check when assigning to parent and point that to ctxt in that function if it is a SELF_REF

So those should be let parent = handle_self_ref(ctxt, opaque_and_semitransparent) and let parent = handle_self_ref(ctxt, opaque)

@Veykril Veykril added E-has-instructions Issue has some instructions and pointers to code to get started E-easy labels Dec 30, 2023
@holly-hacker
Copy link
Contributor Author

holly-hacker commented Dec 31, 2023

I've tried those changes locally and they do seem to fix the repro case. Strangely, the tooltip now shows an unrelated doc entry, but I assume that's due to a faulty macro (it also happened in places where there was no crash before):
Code_Xhf0XNcbSk

@bors bors closed this as completed in cf52c4b Dec 31, 2023
bors added a commit that referenced this issue Jan 1, 2024
fix: Fix SyntaxContextID using incorrect self IDs

Follow up to #16200, there was another logical bug there.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Broken Window Bugs / technical debt to be addressed immediately C-bug Category: bug E-easy E-has-instructions Issue has some instructions and pointers to code to get started
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants