Skip to content

impl causes RA to crash repeatedly overflowing stack #11902

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
KerfuffleV2 opened this issue Apr 5, 2022 · 6 comments · Fixed by #12281
Closed

impl causes RA to crash repeatedly overflowing stack #11902

KerfuffleV2 opened this issue Apr 5, 2022 · 6 comments · Fixed by #12281
Labels
A-ty type system / type inference / traits / method resolution C-support Category: support questions

Comments

@KerfuffleV2
Copy link

rust-analyzer version: rust-analyzer version: 5a6918f1c 2022-04-05 nightly

rustc version: rustc 1.60.0-beta.6 (7bccde197 2022-03-22)

relevant settings:

VS Codium 1.66.0 (using VS Code marketplace)

Preferences:

{
  "rust-analyzer.checkOnSave.command": "clippy",
  "rust-analyzer.highlighting.strings": true,
  "rust-analyzer.lens.methodReferences": true,
  "rust-analyzer.lens.references": true,
  "rust-analyzer.procMacro.enable": true,
  "rust-analyzer.server.extraEnv": {
    "CHALK_OVERFLOW_DEPTH": "3000",
    "CHALK_SOLVER_MAX_SIZE": "1500"
  },
  "rust-analyzer.cache.warmup": false,
  "rust-analyzer.experimental.procAttrMacros": false,
  "rust-analyzer.diagnostics.enableExperimental": false,
  "rust-analyzer.inlayHints.reborrowHints": true,
  "rust-analyzer.inlayHints.closureReturnTypeHints": true,
  "rust-analyzer.inlayHints.lifetimeElisionHints.useParameterNames": true,
  "rust-analyzer.inlayHints.lifetimeElisionHints": "always",
  "rust-analyzer.inlayHints.hideNamedConstructorHints": true,
  "rust-analyzer.checkOnSave.extraArgs": ["--no-deps"],
  "rust-analyzer.inlayHints.lifetimeElisionHints.enable": "skip_trivial"
}

This small code fragment causes RA to repeatedly crash until it disables itself:

[package]
name = "testaes"
version = "0.1.0"
edition = "2021"

[dependencies]
aes = "=0.8.1"
use aes::cipher::{generic_array::GenericArray, BlockCipher, KeySizeUser};

struct Testy<CI>(CI);

impl<CI: BlockCipher + KeySizeUser> Testy<CI> {
    pub fn new(_key: GenericArray<u8, <CI as KeySizeUser>::KeySize>) {}
}

fn main() {}

Example output from a crash:

thread '<unknown>' has overflowed its stack
fatal runtime error: stack overflow
[Error - 2:44:59 AM] The Rust Analyzer Language Server server crashed 5 times in the last 3 minutes. The server will not be restarted. See the output for more information.
[Error - 2:44:59 AM] Request textDocument/semanticTokens/full failed.
Error: Connection got disposed.
	at Object.dispose (/home/some_user/.vscode-oss/extensions/matklad.rust-analyzer-0.3.1003-linux-x64/out/main.js:32:4437)
	at Object.dispose (/home/some_user/.vscode-oss/extensions/matklad.rust-analyzer-0.3.1003-linux-x64/out/main.js:37:12019)
	at Rg.handleConnectionClosed (/home/some_user/.vscode-oss/extensions/matklad.rust-analyzer-0.3.1003-linux-x64/out/main.js:39:9883)
	at Rg.handleConnectionClosed (/home/some_user/.vscode-oss/extensions/matklad.rust-analyzer-0.3.1003-linux-x64/out/main.js:39:80621)
	at t (/home/some_user/.vscode-oss/extensions/matklad.rust-analyzer-0.3.1003-linux-x64/out/main.js:39:9591)
	at zd.invoke (/home/some_user/.vscode-oss/extensions/matklad.rust-analyzer-0.3.1003-linux-x64/out/main.js:5:14370)
	at Ri.fire (/home/some_user/.vscode-oss/extensions/matklad.rust-analyzer-0.3.1003-linux-x64/out/main.js:5:15139)
	at qt (/home/some_user/.vscode-oss/extensions/matklad.rust-analyzer-0.3.1003-linux-x64/out/main.js:6:6354)
	at zd.invoke (/home/some_user/.vscode-oss/extensions/matklad.rust-analyzer-0.3.1003-linux-x64/out/main.js:5:14370)
	at Ri.fire (/home/some_user/.vscode-oss/extensions/matklad.rust-analyzer-0.3.1003-linux-x64/out/main.js:5:15139)
	at ca.fireClose (/home/some_user/.vscode-oss/extensions/matklad.rust-analyzer-0.3.1003-linux-x64/out/main.js:5:17394)
	at Socket.<anonymous> (/home/some_user/.vscode-oss/extensions/matklad.rust-analyzer-0.3.1003-linux-x64/out/main.js:5:18924)
	at Socket.emit (node:events:402:35)
	at Pipe.<anonymous> (node:net:687:12)

Please let me know if any further details would be helpful.

@flodiebold
Copy link
Member

This would usually be a Chalk overflow; it's probably not helpful to set CHALK_OVERFLOW_DEPTH that high.

@flodiebold
Copy link
Member

Presumably a duplicate of #11370.

@flodiebold flodiebold added C-support Category: support questions A-ty type system / type inference / traits / method resolution labels Apr 6, 2022
@KerfuffleV2
Copy link
Author

Thanks for the response. I disabled setting those environment variables and it just panics due to hitting the maximum depth.

Is there any other information that would be helpful?

Output (note - some repetition elided):

Panic context:
> 
version: 134dbc610 2022-04-07 nightly
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/some_user/personal/testaes/src/main.rs",
            query: None,
            fragment: None,
        },
    },
    previous_result_id: "1",
}

thread '<unnamed>' panicked at 'overflow depth reached', /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/chalk-recursive-0.81.0/src/fixed_point/stack.rs:51:13
stack backtrace:
   0: std::panicking::begin_panic
   1: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
   2: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
   3: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
   4: chalk_recursive::solve::SolveIteration::solve_iteration
   5: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
   6: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
   7: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
   8: chalk_recursive::solve::SolveIteration::solve_iteration
   9: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
[...]
  88: chalk_recursive::solve::SolveIteration::solve_iteration
  89: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  90: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  91: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
[Error - 4:38:57 AM] Request textDocument/semanticTokens/full/delta failed.
  Message: server panicked: overflow depth reached
  Code: -32603 
Panic context:
> 
version: 134dbc610 2022-04-07 nightly
request: experimental/inlayHints InlayHintsParams {
    text_document: TextDocumentIdentifier {
        uri: Url {
            scheme: "file",
            cannot_be_a_base: false,
            username: "",
            password: None,
            host: None,
            port: None,
            path: "/home/some_user/personal/testaes/src/main.rs",
            query: None,
            fragment: None,
        },
    },
    range: Some(
        Range {
            start: Position {
                line: 0,
                character: 0,
            },
            end: Position {
                line: 9,
                character: 0,
            },
        },
    ),
}

@KerfuffleV2
Copy link
Author

Regarding #11370, setting CHALK_SOLVER_MAX_SIZE to 100 does seem to fix the problem. I guess I don't understand how those settings work, I'd think increasing the maximum size would make it more likely to work instead of less!

@flodiebold
Copy link
Member

Having a lower max size makes it short-circuit the calculation earlier, so it doesn't get as deep. It still means the result might be wrong though.

@lnicola
Copy link
Member

lnicola commented May 22, 2022

This works for me with CHALK_OVERFLOW_DEPTH set to 350 or above. #12281 will probably bump it slightly, but at this point we probably can't avoid the need to tweak these at times.

@bors bors closed this as completed in 65a213c May 22, 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

Successfully merging a pull request may close this issue.

3 participants