Skip to content
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

'overflow depth reached' panic during syntax highlighting, when using aes + ctr + cipher #11370

Closed
ivan opened this issue Jan 29, 2022 · 19 comments · Fixed by #12281
Closed

'overflow depth reached' panic during syntax highlighting, when using aes + ctr + cipher #11370

ivan opened this issue Jan 29, 2022 · 19 comments · Fixed by #12281
Labels
A-ty type system / type inference / traits / method resolution C-bug Category: bug

Comments

@ivan
Copy link
Contributor

ivan commented Jan 29, 2022

rust-analyzer version: 6634eaf 2022-01-29 nightly

rustc version: rustc 1.60.0-nightly (e0a55f449 2022-01-28)

Hello,

I am having a problem with rust-analyzer being unable to syntax-highlight my project. This project builds successfully on Rust nightly with cargo build.

So far I have reduced the issue to:

#![feature(
    generators,
    proc_macro_hygiene,
    stmt_expr_attributes,
)]

use cipher::NewCipher;
use aes::cipher::generic_array::GenericArray;
use futures::stream::BoxStream;
use futures_async_stream::stream;

type Aes128Ctr = ctr::Ctr64BE<aes::Aes128>;

pub fn stream_chunks() -> BoxStream<'static, ()> {
    Box::pin(
        #[stream]
        async move {
            let zeroes = GenericArray::from_slice(&[0; 16]);
            let _cipher = Aes128Ctr::new(zeroes, zeroes);
        }
    )
}

(available in this repo with a Cargo.toml)

rust-analyzer shows these messages when clicking around in lib.rs:

  • Request textDocument/semanticTokens/range failed.
  • Request textDocument/documentHighlight failed.
  • server panicked: overflow depth reached, check the log

I used rust-analyzer v0.3.921 in vscode 1.63.2 and tested with rustc nightly-2022-01-27 on NixOS and rustc nightly-2022-01-28 on Windows 10, both of which do the same thing.

There are other variations that will have the same problem, including () -> String, #[stream] -> #[try_stream], and async -> async move.

The output in vscode shows:

thread '<unnamed>' panicked at 'overflow depth reached', /home/at/.cargo/registry/src/github.com-1ecc6299db9ec823/chalk-recursive-0.76.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::SolveIterationHelpers::solve_from_clauses
   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::SolveIterationHelpers::solve_from_clauses
   9: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  10: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  11: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  12: chalk_recursive::solve::SolveIterationHelpers::solve_from_clauses
  13: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  14: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  15: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  16: chalk_recursive::solve::SolveIterationHelpers::solve_from_clauses
  17: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  18: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  19: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  20: chalk_recursive::solve::SolveIterationHelpers::solve_from_clauses
  21: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  22: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  23: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  24: chalk_recursive::solve::SolveIterationHelpers::solve_from_clauses
  25: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  26: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  27: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  28: chalk_recursive::solve::SolveIterationHelpers::solve_from_clauses
  29: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  30: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  31: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  32: chalk_recursive::solve::SolveIterationHelpers::solve_from_clauses
  33: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  34: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  35: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  36: chalk_recursive::solve::SolveIterationHelpers::solve_from_clauses
  37: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  38: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  39: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  40: chalk_recursive::solve::SolveIterationHelpers::solve_from_clauses
  41: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  42: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  43: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  44: chalk_recursive::solve::SolveIterationHelpers::solve_from_clauses
  45: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  46: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  47: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  48: chalk_recursive::solve::SolveIterationHelpers::solve_from_clauses
  49: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  50: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  51: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  52: chalk_recursive::solve::SolveIterationHelpers::solve_from_clauses
  53: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  54: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  55: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  56: chalk_recursive::solve::SolveIterationHelpers::solve_from_clauses
  57: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  58: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  59: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  60: chalk_recursive::solve::SolveIterationHelpers::solve_from_clauses
  61: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  62: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  63: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  64: chalk_recursive::solve::SolveIterationHelpers::solve_from_clauses
  65: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  66: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  67: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  68: chalk_recursive::solve::SolveIterationHelpers::solve_from_clauses
  69: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  70: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  71: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  72: chalk_recursive::solve::SolveIterationHelpers::solve_from_clauses
  73: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  74: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  75: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  76: chalk_recursive::solve::SolveIterationHelpers::solve_from_clauses
  77: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  78: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  79: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  80: chalk_recursive::solve::SolveIterationHelpers::solve_from_clauses
  81: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  82: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  83: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  84: chalk_recursive::solve::SolveIterationHelpers::solve_from_clauses
  85: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  86: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  87: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  88: chalk_recursive::solve::SolveIterationHelpers::solve_from_clauses
  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.

rust-analyzer Screenshot 2022-01-29 063707

@ivan
Copy link
Contributor Author

ivan commented Jan 29, 2022

CHALK_OVERFLOW_DEPTH=3000
CHALK_SOLVER_MAX_SIZE=1500

does not fix this

@ivan
Copy link
Contributor Author

ivan commented Jan 29, 2022

I have further reduced this to

use cipher::NewCipher;

type Aes128Ctr = ctr::Ctr64BE<aes::Aes128>;

pub fn make_ra_unhappy() {
    let zeroes = [0; 16].into();
    let _cipher = Aes128Ctr::new(&zeroes, &zeroes);
}

and updated the git repo.

@ivan ivan changed the title 'overflow depth reached' panic during syntax highlighting when using futures_async_stream, aes, ctr 'overflow depth reached' panic during syntax highlighting, when using aes + ctr + cipher Jan 29, 2022
@ivan
Copy link
Contributor Author

ivan commented Jan 29, 2022

This alternative works without issues in rust-analyzer:

[dependencies]
aes = { version = "0.7", features = ["ctr"] }
cipher = "0.3"
use aes::Aes128Ctr;
use cipher::NewCipher;

pub fn fail_to_make_ra_unhappy() {
    let zeroes = [0; 16].into();
    let _cipher = Aes128Ctr::new(&zeroes, &zeroes);
}

@Veykril Veykril added the A-ty type system / type inference / traits / method resolution label Jan 29, 2022
@willhug
Copy link

willhug commented Feb 3, 2022

+1 Ran into the same issue, I was able to mitigate it by changing my rust-analyzer version in VSCode to v0.2.853

@ivan
Copy link
Contributor Author

ivan commented Feb 21, 2022

aes 0.8 was released and it no longer has the ctr feature, making my workaround inapplicable to that newer version.

@owen-hope11
Copy link

Going back to rust-analyzer version v0.2.853 in VSCode also fixed this issue for me.

@louds1lence
Copy link

Same issue here, I've reverted to v0.2.853 in VSCode.

@flodiebold flodiebold added the C-bug Category: bug label Mar 6, 2022
@ivan
Copy link
Contributor Author

ivan commented Apr 2, 2022

This issue is still present in d312b45.

It was introduced in 851af5a, which was fixing #11072 in PR #11074.

Using the latest rust-analyzer with the old CHALK_SOLVER_MAX_SIZE=30 value fixes this issue, but presumably causes #11072 again.

CHALK_SOLVER_MAX_SIZE=108 is as high as I could go without causing "server panicked: overflow depth reached, check the log" on x86_64 NixOS 21.11.

I will open a PR with CHALK_SOLVER_MAX_SIZE=100 which will hopefully be suitable.

@lnicola
Copy link
Member

lnicola commented May 22, 2022

The repro in https://github.com/ludios/ra-chalk-overflow-bug works for me with CHALK_OVERFLOW_DEPTH above 450 and the default CHALK_SOLVER_MAX_SIZE. #12281 might increase the former, but it's possible that some users might need to tweak these a little.

@ivan
Copy link
Contributor Author

ivan commented May 25, 2022

@lnicola It looks like I minimized https://github.com/ludios/ra-chalk-overflow-bug to excess. For the code I originally posted in the issue, now in https://github.com/ludios/ra-chalk-overflow-bug-2, there doesn't appear to be any CHALK_OVERFLOW_DEPTH value that makes rust-analyzer not panic.

@lnicola
Copy link
Member

lnicola commented May 25, 2022

I think that repo might be private.

@ivan
Copy link
Contributor Author

ivan commented May 25, 2022

Fixed, sorry about that.

@xr1s
Copy link

xr1s commented Jun 1, 2022

Exactly same issue when working with RustCrypto and Rust-Analyzer.

rust-analyzer f94fa62d6 2022-05-30 stable

Here is my reproduction code:

fn main() {
    use cipher::{BlockDecryptMut, KeyIvInit};
    let zeros = [0; 16].into();
    let mut decryptor = cbc::Decryptor::<aes::Aes128>::new(&zeros, &zeros);
    decryptor.  // rust-analyzer panicked here.
}

Modifying CHALK_* envs seems not work in this situation.

And the output of rust-analyzer shows it just stack overflowed.

thread '<unknown>' has overflowed its stack
fatal runtime error: stack overflow

@lnicola
Copy link
Member

lnicola commented Jun 2, 2022

@ivan can you try rust-analyzer analysis-stats . under https://github.com/ludios/ra-chalk-overflow-bug-2? It works for me by default, and fails with a reduced overflow depth:

$ rust-analyzer analysis-stats .
Database loaded:     796.89ms, 92minstr (metadata 571.68ms, 5080kinstr; build 181.78ms, 1608kinstr)
  crates: 1, mods: 1, decls: 2, fns: 1
Item Collection:     3.08s, 32ginstr
  exprs: 15, ??ty: 2 (13%), ?ty: 4 (26%), !ty: 1
Inference:           4.59s, 35ginstr
Total:               7.67s, 67ginstr
$ CHALK_OVERFLOW_DEPTH=300 rust-analyzer analysis-stats .
Database loaded:     477.88ms, 92minstr (metadata 379.25ms, 5086kinstr; build 55.58ms, 1615kinstr)
  crates: 1, mods: 1, decls: 2, fns: 1
Item Collection:     3.14s, 32ginstr
0/1 0% processing: stream_chunksthread 'main' panicked at 'overflow depth reached', /home/me/.cargo/registry/src/github.com-1ecc6299db9ec823/chalk-recursive-0.82.0/src/fixed_point/stack.rs:51:13
stack backtrace:
   0: std::panicking::begin_panic
   1: chalk_recursive::fixed_point::stack::Stack::push
   2: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
   3: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
   4: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
   5: chalk_recursive::solve::SolveIteration::solve_iteration
   6: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
   7: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
   8: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
   9: chalk_recursive::solve::SolveIteration::solve_iteration
  10: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  11: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  12: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  13: chalk_recursive::solve::SolveIteration::solve_iteration
  14: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  15: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  16: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  17: chalk_recursive::solve::SolveIteration::solve_iteration
  18: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  19: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  20: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  21: chalk_recursive::solve::SolveIteration::solve_iteration
  22: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  23: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  24: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  25: chalk_recursive::solve::SolveIteration::solve_iteration
  26: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  27: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  28: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  29: chalk_recursive::solve::SolveIteration::solve_iteration
  30: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  31: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  32: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  33: chalk_recursive::solve::SolveIteration::solve_iteration
  34: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  35: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  36: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  37: chalk_recursive::solve::SolveIteration::solve_iteration
  38: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  39: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  40: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  41: chalk_recursive::solve::SolveIteration::solve_iteration
  42: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  43: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  44: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  45: chalk_recursive::solve::SolveIteration::solve_iteration
  46: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  47: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  48: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  49: chalk_recursive::solve::SolveIteration::solve_iteration
  50: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  51: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  52: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  53: chalk_recursive::solve::SolveIteration::solve_iteration
  54: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  55: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  56: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  57: chalk_recursive::solve::SolveIteration::solve_iteration
  58: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  59: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  60: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  61: chalk_recursive::solve::SolveIteration::solve_iteration
  62: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  63: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  64: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  65: chalk_recursive::solve::SolveIteration::solve_iteration
  66: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  67: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  68: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  69: chalk_recursive::solve::SolveIteration::solve_iteration
  70: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  71: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  72: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  73: chalk_recursive::solve::SolveIteration::solve_iteration
  74: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  75: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  76: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  77: chalk_recursive::solve::SolveIteration::solve_iteration
  78: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  79: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  80: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  81: chalk_recursive::solve::SolveIteration::solve_iteration
  82: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  83: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  84: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  85: chalk_recursive::solve::SolveIteration::solve_iteration
  86: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  87: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  88: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  89: chalk_recursive::solve::SolveIteration::solve_iteration
  90: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  91: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

It also seems to work in Code, although we show an invalid type mismatch error.

@xr1s that's a different issue.

@ivan
Copy link
Contributor Author

ivan commented Jun 2, 2022

@lnicola You are correct. The official rust-analyzer binary appears to be working fine with https://github.com/ludios/ra-chalk-overflow-bug-2. The one I compile myself still results in 'overflow depth reached' in vscode. Sorry that I did not test earlier, I didn't expect a difference. I will go try to figure out why that happens.

Oddly, my build doesn't crash when running analysis-stats.

at@dev:/home/at/code/rust/ra-chalk-overflow-bug-2:master# /home/at/.vscode-server/data/User/globalStorage/rust-lang.rust-analyzer/rust-analyzer analysis-stats .
Failed to create perf counter: Operation not permitted (os error 1)
Failed to create perf counter: Operation not permitted (os error 1)
Database loaded:     1.82s (metadata 1.38s; build 362.23ms)
Failed to create perf counter: Operation not permitted (os error 1)
  crates: 1, mods: 1, decls: 2, fns: 1
Item Collection:     3.79s
Failed to create perf counter: Operation not permitted (os error 1)
  exprs: 15, ??ty: 2 (13%), ?ty: 4 (26%), !ty: 1
Inference:           5.69s
Total:               9.48s


(self-compiled:)

at@dev:/home/at/code/rust/ra-chalk-overflow-bug-2:master# ~/bin/_rust-analyzer analysis-stats .
Failed to create perf counter: Operation not permitted (os error 1)
Failed to create perf counter: Operation not permitted (os error 1)
Database loaded:     970.80ms (metadata 735.84ms; build 102.85ms)
Failed to create perf counter: Operation not permitted (os error 1)
  crates: 1, mods: 1, decls: 2, fns: 1
Item Collection:     3.18s
Failed to create perf counter: Operation not permitted (os error 1)
  exprs: 15, ??ty: 2 (13%), ?ty: 4 (26%), !ty: 1
Inference:           4.65s
Total:               7.84s

@ivan
Copy link
Contributor Author

ivan commented Jun 3, 2022

The rust-analyzer stack overflows occur with https://github.com/ludios/ra-chalk-overflow-bug-2 only when rust-analyzer is compiled with lto:

diff --git a/Cargo.toml b/Cargo.toml
index 6b68ca823..7438b861d 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -20,6 +20,8 @@ miniz_oxide.opt-level = 3
 incremental = true
 # Set this to 1 or 2 to get more useful backtraces in debugger.
 debug = 0
+lto = true
+codegen-units = 1

 [patch.'crates-io']
 # rowan = { path = "../rowan" }

I thought that the CI-built rust-analyzer was being compiled with full lto, so I did not suspect this as a cause earlier. It looks like it was changed to thin in 3ea6256. When I compile it with thin myself, I still see the stack overflow. Based on the size of the binary that comes with the vscode extension for Linux, I believe it is not compiled with any lto, and that is why it is not crashing here.

@lnicola
Copy link
Member

lnicola commented Jun 3, 2022

Regarding the build size, I tested the following configurations:

The full LTO build (at least) crashes for me with:

thread '<unknown>' has overflowed its stack
fatal runtime error: stack overflow

But this is a different error from the original one (same that xr1s saw earlier).

@lnicola
Copy link
Member

lnicola commented Jun 4, 2022

@ivan can you try the change in #12466? I haven't tested it yet. For best results you might need to disable cache priming or to ignore any errors that show up on load.

bors added a commit that referenced this issue Jun 5, 2022
Increase worker thread stack and name them

CC #11370
@jakerumbles
Copy link

Been dealing with this same type of issue in pretty much any Substrate project I've worked on. I documented some of it here, but haven't found a solution yet https://www.reddit.com/r/rust/comments/w9prbu/rust_analyzer_tooltips_hardly_ever_work_wsubstrate/.

I particularly have issues when working in this repository: https://github.com/InvArch/InvArch-Frames

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-bug Category: bug
Projects
None yet
9 participants