helix-editor / helix

A post-modern modal text editor.
https://helix-editor.com
Mozilla Public License 2.0
32.23k stars 2.38k forks source link

Helix crashed unexpectedly when trying to <A-o> in Rust #10974

Closed dav-wolff closed 1 month ago

dav-wolff commented 2 months ago

Summary

I tried to expand my selection to the surrounding tree-sitter node when helix crashed with this panic:

thread 'main' panicked at helix-core/src/syntax/tree_cursor.rs:85:31:
invalid HopSlotMap key used
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Reproduction Steps

~Unfortunately I wasn't able to reproduce the bug.~ Update: I was able to reproduce this, see below

I tried this:

  1. hx
  2. Edit some code
  3. Try to expand selection in this line
    PathBuf::from(format!(concat!(env!("SOLITAIRE_CARDS_LOCATION"), "/{value_char}{suit_char}.svg")))

I expected this to happen: Selection gets expanded

Instead, this happened: Helix crashed and immediately dumped me back into the shell.

Helix log

~/.cache/helix/helix.log ``` 2024-06-16T13:39:29.212 helix_term::handlers::signature_help [ERROR] signature help request failed: request 14 timed out 2024-06-16T13:39:31.974 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(1)), original request likely timed out 2024-06-16T13:39:31.975 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(5)), original request likely timed out 2024-06-16T13:39:31.975 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(9)), original request likely timed out 2024-06-16T13:39:31.975 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(8)), original request likely timed out 2024-06-16T13:39:31.975 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(6)), original request likely timed out 2024-06-16T13:39:31.975 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(3)), original request likely timed out 2024-06-16T13:39:31.975 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(2)), original request likely timed out 2024-06-16T13:39:31.975 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(4)), original request likely timed out 2024-06-16T13:39:31.975 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(14)), original request likely timed out 2024-06-16T13:39:31.975 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(12)), original request likely timed out 2024-06-16T13:39:32.134 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(10)), original request likely timed out 2024-06-16T13:39:32.134 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(7)), original request likely timed out 2024-06-16T13:39:32.135 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(11)), original request likely timed out 2024-06-16T13:39:32.135 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(13)), original request likely timed out 2024-06-16T13:42:45.863 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(48)), original request likely timed out 2024-06-16T13:44:46.701 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(58)), original request likely timed out 2024-06-16T13:44:47.356 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(60)), original request likely timed out 2024-06-16T13:46:14.774 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(76)), original request likely timed out 2024-06-16T13:46:44.090 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(112)), original request likely timed out 2024-06-16T13:46:44.092 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(110)), original request likely timed out 2024-06-16T13:47:30.688 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(151)), original request likely timed out 2024-06-16T13:47:56.506 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(165)), original request likely timed out 2024-06-16T13:49:58.652 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(194)), original request likely timed out 2024-06-16T13:49:58.688 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(193)), original request likely timed out 2024-06-16T13:50:55.797 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(230)), original request likely timed out 2024-06-16T13:51:36.379 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(242)), original request likely timed out 2024-06-16T13:51:39.991 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(245)), original request likely timed out 2024-06-16T13:51:39.992 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(246)), original request likely timed out 2024-06-16T13:51:40.023 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(244)), original request likely timed out 2024-06-16T13:51:42.954 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(254)), original request likely timed out 2024-06-16T13:51:59.322 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(268)), original request likely timed out 2024-06-16T13:52:34.919 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(285)), original request likely timed out 2024-06-16T13:52:34.920 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(286)), original request likely timed out 2024-06-16T13:52:34.923 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(283)), original request likely timed out 2024-06-16T13:52:34.925 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(284)), original request likely timed out 2024-06-16T13:52:34.965 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(282)), original request likely timed out 2024-06-16T13:52:37.684 helix_lsp::transport [ERROR] rust-analyzer err <- "2024-06-16T11:52:37.684587Z ERROR rust_analyzer::main_loop: flycheck 0: File with cargo diagnostic not found in VFS: file not found: /rustc/804421dff5542c9c7da5c60257b5dbc849719505/library/core/src/iter/traits/iterator.rs\n" 2024-06-16T13:52:37.684 helix_lsp::transport [ERROR] rust-analyzer err <- "2024-06-16T11:52:37.684954Z ERROR rust_analyzer::main_loop: flycheck 0: File with cargo diagnostic not found in VFS: file not found: /rustc/804421dff5542c9c7da5c60257b5dbc849719505/library/core/src/iter/traits/iterator.rs\n" 2024-06-16T13:52:44.755 helix_lsp::transport [ERROR] rust-analyzer err <- "2024-06-16T11:52:44.755039Z ERROR rust_analyzer::main_loop: flycheck 0: File with cargo diagnostic not found in VFS: file not found: /rustc/804421dff5542c9c7da5c60257b5dbc849719505/library/core/src/iter/traits/iterator.rs\n" 2024-06-16T13:52:44.755 helix_lsp::transport [ERROR] rust-analyzer err <- "2024-06-16T11:52:44.755157Z ERROR rust_analyzer::main_loop: flycheck 0: File with cargo diagnostic not found in VFS: file not found: /rustc/804421dff5542c9c7da5c60257b5dbc849719505/library/core/src/iter/traits/iterator.rs\n" 2024-06-16T13:54:40.025 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(312)), original request likely timed out 2024-06-16T14:00:04.590 helix_lsp::transport [ERROR] rust-analyzer err <- "2024-06-16T12:00:04.590733Z ERROR hir::diagnostics: synthetic syntax\n" 2024-06-16T14:00:04.788 helix_lsp::transport [ERROR] rust-analyzer err <- "2024-06-16T12:00:04.788418Z ERROR hir::diagnostics: synthetic syntax\n" 2024-06-16T14:00:04.856 helix_lsp::transport [ERROR] rust-analyzer err <- "2024-06-16T12:00:04.856036Z ERROR hir::diagnostics: synthetic syntax\n" 2024-06-16T14:00:05.070 helix_lsp::transport [ERROR] rust-analyzer err <- "2024-06-16T12:00:05.070707Z ERROR hir::diagnostics: synthetic syntax\n" 2024-06-16T14:00:05.139 helix_lsp::transport [ERROR] rust-analyzer err <- "2024-06-16T12:00:05.139305Z ERROR hir::diagnostics: synthetic syntax\n" 2024-06-16T14:00:05.477 helix_lsp::transport [ERROR] rust-analyzer err <- "2024-06-16T12:00:05.477033Z ERROR hir::diagnostics: synthetic syntax\n" 2024-06-16T14:00:05.631 helix_lsp::transport [ERROR] rust-analyzer err <- "2024-06-16T12:00:05.631272Z ERROR hir::diagnostics: synthetic syntax\n" 2024-06-16T14:00:05.858 helix_lsp::transport [ERROR] rust-analyzer err <- "2024-06-16T12:00:05.858617Z ERROR hir::diagnostics: synthetic syntax\n" 2024-06-16T14:00:05.996 helix_lsp::transport [ERROR] rust-analyzer err <- "2024-06-16T12:00:05.996908Z ERROR hir::diagnostics: synthetic syntax\n" 2024-06-16T14:00:08.134 helix_lsp::transport [ERROR] rust-analyzer err <- "2024-06-16T12:00:08.134073Z ERROR hir::diagnostics: synthetic syntax\n" 2024-06-16T14:00:08.304 helix_lsp::transport [ERROR] rust-analyzer err <- "2024-06-16T12:00:08.304877Z ERROR hir::diagnostics: synthetic syntax\n" 2024-06-16T14:00:08.504 helix_lsp::transport [ERROR] rust-analyzer err <- "2024-06-16T12:00:08.504724Z ERROR hir::diagnostics: synthetic syntax\n" 2024-06-16T14:00:08.579 helix_lsp::transport [ERROR] rust-analyzer err <- "2024-06-16T12:00:08.579901Z ERROR hir::diagnostics: synthetic syntax\n" 2024-06-16T14:00:09.008 helix_lsp::transport [ERROR] rust-analyzer err <- "2024-06-16T12:00:09.008948Z ERROR hir::diagnostics: synthetic syntax\n" 2024-06-16T14:00:09.154 helix_lsp::transport [ERROR] rust-analyzer err <- "2024-06-16T12:00:09.153969Z ERROR hir::diagnostics: synthetic syntax\n" 2024-06-16T14:00:09.379 helix_lsp::transport [ERROR] rust-analyzer err <- "2024-06-16T12:00:09.379878Z ERROR hir::diagnostics: synthetic syntax\n" 2024-06-16T14:00:09.482 helix_lsp::transport [ERROR] rust-analyzer err <- "2024-06-16T12:00:09.482015Z ERROR hir::diagnostics: synthetic syntax\n" ```

Platform

Linux (NixOS e9ee548d90ff586a6471b4ae80ae9cfcbceb3420)

Terminal Emulator

alacritty 0.13.2

Installation Method

flake

Helix Version

helix 24.3 (dbacaaddcaa4a9dd39c73d0102d03ea7c24ca647)

dav-wolff commented 2 months ago

Update

I was able to reproduce the bug:

  1. Open helix
  2. Open card.rs
  3. Add {} before the / in the previously mentioned line to make it look like this:
    PathBuf::from(format!(concat!(env!("SOLITAIRE_CARDS_LOCATION"), "{}/{value_char}{suit_char}.svg")))
  4. Place the cursor inside the env! macro
  5. Expand the selection 4 times (trying to select env!("SOLITAIRE_CARDS_LOCATION")
  6. Helix crashes

Here's the file in which the bug occurs:

card.rs: ```rust use std::path::PathBuf; use bevy::{prelude::*, utils::HashMap}; use bevy_svg::prelude::*; use strum::{EnumIter, IntoEnumIterator}; #[derive(Clone, Copy, PartialEq, Eq, Hash, EnumIter, Debug)] pub enum Suit { Spades, Clubs, Diamonds, Hearts, } #[derive(Clone, Copy, PartialEq, Eq, Hash, EnumIter, Debug)] pub enum Value { Ace, Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, King, } #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] pub struct Card { suit: Suit, value: Value, } fn asset_path(card: Card) -> PathBuf { use Suit::*; use Value::*; let suit_char = match card.suit { Spades => 'S', Clubs => 'C', Diamonds => 'D', Hearts => 'H', }; let value_char = match card.value { Ace => 'A', Two => '2', Three => '3', Four => '4', Five => '5', Six => '6', Seven => '7', Eight => '8', Nine => '9', Ten => 'T', Jack => 'J', Queen => 'Q', King => 'K', }; PathBuf::from(format!(concat!(env!("SOLITAIRE_CARDS_LOCATION"), "/{value_char}{suit_char}.svg"))) } pub fn load_assets(asset_server: &AssetServer) -> HashMap> { Suit::iter() .flat_map(|suit| { Value::iter() .map(move |value| Card { suit, value, }) }) .map(|card| (card, asset_server.load(asset_path(card)))) .collect() } ```

I could also attach the entire repo if that helps.

Backtrace: ``` ❯ RUST_BACKTRACE=full hx -vv --log helix.log thread 'main' panicked at helix-core/src/syntax/tree_cursor.rs:85:31: invalid HopSlotMap key used stack backtrace: 0: 0x5555564fcaeb - ::fmt::hbb235daedd7c6190 1: 0x555555791970 - core::fmt::write::h3ed6aeaa977c8e45 2: 0x5555564f8953 - std::io::Write::write_fmt::h78b18af5775fedb5 3: 0x5555564fc884 - std::sys_common::backtrace::print::h85035a511aafe7a8 4: 0x5555564fe800 - std::panicking::default_hook::{{closure}}::hcce8cea212785a25 5: 0x5555564fe51f - std::panicking::default_hook::hf5fcb0f213fe709a 6: 0x5555564feecf - std::panicking::rust_panic_with_hook::h095fccf1dc9379ee 7: 0x555555a5173d - std::panicking::begin_panic::{{closure}}::h47cc4e44c886ab69 8: 0x555555a51706 - std::sys_common::backtrace::__rust_end_short_backtrace::h6a5d220ac6382956 9: 0x5555556a6caa - std::panicking::begin_panic::hf1e7707cfae6ff0c 10: 0x555555a483e3 - helix_core::syntax::tree_cursor::TreeCursor::goto_parent::h767fccdc6e81cf25 11: 0x555555a00e91 - helix_core::selection::Selection::transform::h583280d9647dc643 12: 0x5555560e1ad1 - helix_term::commands::expand_selection::{{closure}}::h6e552bc066fa5157 13: 0x555555d0dd04 - helix_term::commands::expand_selection::h92c940e1ec94e9c6 14: 0x555555c91783 - helix_term::ui::editor::EditorView::handle_keymap_event::{{closure}}::h6914fd3f6d002184 15: 0x555555c916b7 - helix_term::ui::editor::EditorView::handle_keymap_event::h6e142924cda12d1e 16: 0x555555c93ecf - ::handle_event::h218627f6ee1aac71 17: 0x555555c4794a - helix_term::compositor::Compositor::handle_event::h109428e72b70c09c 18: 0x55555628626e - hx::main_impl::{{closure}}::hc66340b5c2c14940 19: 0x5555562836a8 - tokio::runtime::park::CachedParkThread::block_on::h79da24126444dd72 20: 0x55555631263c - hx::main::h1177bf41b7e5fa90 21: 0x5555562b2bc3 - std::sys_common::backtrace::__rust_begin_short_backtrace::hd00ebda81688a292 22: 0x5555562babcd - std::rt::lang_start::{{closure}}::h9f7840f43ad49372 23: 0x5555564ef375 - std::rt::lang_start_internal::h6939038e2873596b 24: 0x555556313535 - main 25: 0x7ffff7cf510e - __libc_start_call_main 26: 0x7ffff7cf51c9 - __libc_start_main@@GLIBC_2.34 27: 0x55555570df55 - _start 28: 0x0 - ```

Log file (-vv) is attached: helix.log

woojiq commented 2 months ago

FYI, I can't reproduce on 179673568df2a519fae2537fbc0053a64ecf3d8b Probably a regression.

dav-wolff commented 2 months ago

I also tested it on 179673568df2a519fae2537fbc0053a64ecf3d8b and still got the crash. Can I provide anything else to make reproducing the bug easier?

I made a recording showing the crash: asciicast helix_crash.cast.txt

thomasschafer commented 2 months ago

Just checked and I am also able to reproduce, after making sure to add the {} manually as explained in the updated instructions

RoloEdits commented 2 months ago

Pretty sure this is related to #10909

This provides a reproduction case, which that lacked, so perhaps close #10909 in favor of this?