rust-lang / rust-lang/rust-analyzer

Thread 'Worker' has overflowed its stack (declarative macro)

Open
#17,538 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-macro C-bug
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

I'm running into an issue where rust-analyzer keeps crashing with the error Thread 'Worker' has overflowed its stack.

The full project code is available here: https://github.com/qwerty01/hextra/tree/0b498e236058f04325d38465ee6ce3fa40d1cea6
I believe the code causing the crash is the declarative macro charmap in src/decode.rs (eventually used in src/decode/printable.rs).

Before it crashes, it's able to fully expand the macro via rust-analyzer: Expand macro recursively at caret.


rust-analyzer version: rust-analyzer version: 0.3.2020-standalone (ea7fdada6 2024-06-30) [c:\Users\user\.vscode\extensions\rust-lang.rust-analyzer-0.3.2020-win32-x64\server\rust-analyzer.exe]

rustc version: rustc 1.79.0-nightly (f9b161492 2024-04-19)

editor or extension: VSCode (extension version v0.3.2020)


Also crashes with up-to-date versions:

rust-analyzer version: rust-analyzer version: 1.81.0-nightly (6292b2af 2024-07-02) [C:\Users\user\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\bin\rust-analyzer.exe]

rustc version: rustc 1.81.0-nightly (6292b2af6 2024-07-02)

editor or extension: VSCode (extension version v0.3.2020)


Code snippet probably causing the problem:

macro_rules! charmap_match {
    ($arr:ident, $v:literal: $start:literal .. => None) => {
        #[allow(unused_comparisons)]
        if $v >= $start {
            $arr[$v as usize] = None;
        }
    };
    ($arr:ident, $v:literal: $start:literal ..= $end:literal => None) => {
        #[allow(unused_comparisons)]
        if $v >= $start && $v <= $end {
            $arr[$v as usize] = None;
        }
    };
    ($arr:ident, $v:literal: $start:literal .. => [$($val:literal),+]) => {
        let v: usize = $v as _;
        #[allow(unused_comparisons)]
        if v >= $start {
            let val: [Option<&str>; 256-$start] = [$($val.into()),+];
            $arr[$v as usize] = val[v - $start];
        }
    };
    ($arr:ident, $v:literal: $start:literal ..= $end:literal => [$($val:literal),+]) => {
        let v: usize = $v as _;
        #[allow(unused_comparisons)]
        if v >= $start && v <= $end {
            let val: [Option<&str>; $end-$start+1] = [$(Some($val)),+];
            $arr[$v as usize] = val[v - $start];
        }
    };
    ($arr:ident, $v:literal: $chr:literal => $val:expr) => {
        if $v == $chr {
            $arr[$v as usize] = $val.into();
        }
    }
}
macro_rules! charmap {
    ($($pat:pat => $val:expr),+) => {{
        let mut val = [None; 256];
        match 0u8 {
            $($pat => ()),+
        }
        seq_macro::seq!(N in 0u8..256 {
            $(
                charmap_match!(val, N: $pat => $val);
            )+
        });
        val
    }};
}
const BASIC_MAP: [Option<&str>; 256] = charmap! {
    0..=31 => None,
    32..=126 => [
        " ", "!", "\"","#", "$", "%", "&", "'", "(", ")", "*", "+", ",", "-", ".", "/",
        "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ":", ";", "<", "=", ">", "?",
        "@", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O",
        "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "[", "\\","]", "^", "_",
        "`", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o",
        "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "{", "|", "}", "~"
    ],
    127.. => None
};

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the crash using the linked hextra project at commit 0b498e236058f04325d38465ee6ce3fa40d1cea6, then inspect the charmap macro in src/decode.rs and its use in src/decode/printable.rs. Try recursive macro expansion in rust-analyzer with the reported toolchain versions; done means analyzing this code no longer causes the Worker thread to overflow its stack.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.