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

[hir-ty] Missed RPIT in ide/src/rename.rs #19439

Open
snprajwal opened this issue Mar 24, 2025 · 8 comments
Open

[hir-ty] Missed RPIT in ide/src/rename.rs #19439

snprajwal opened this issue Mar 24, 2025 · 8 comments
Labels
A-ty type system / type inference / traits / method resolution C-bug Category: bug I-panic

Comments

@snprajwal
Copy link
Contributor

snprajwal commented Mar 24, 2025

I've written a tool that walks the AST and resolves all exprs, collecting the types. I've tested this on other big projects in debug mode (notably rustfmt) and it works fine. Running it on rust-analyzer itself causes it to panic on line 206 in ide/src/rename.rs with Missed RPIT in `insert_inference_vars_for_rpit` .

syntax: &SyntaxNode,
FilePosition { file_id, offset }: FilePosition,
) -> RenameResult<impl Iterator<Item = (FileRange, SyntaxKind, Definition)>> {
let token = syntax.token_at_offset(offset).find(|t| matches!(t.kind(), SyntaxKind::STRING));

The error is coming from here:

if let Entry::Vacant(e) = self.result.type_of_rpit.entry(id) {
never!("Missed RPIT in `insert_inference_vars_for_rpit`");
e.insert(TyKind::Error.intern(Interner));

Not sure how to reproduce this with a test or code action. No issues in release mode since never! doesn't show up without debug assertions.

@ShoyuVanilla ShoyuVanilla added A-ty type system / type inference / traits / method resolution C-bug Category: bug I-panic labels Mar 24, 2025
@ShoyuVanilla
Copy link
Member

Could you tell me what project causes that panic? Or I think that you could reproduce it by running rust-analyzer analysis-stats in that project.

@lnicola
Copy link
Member

lnicola commented Mar 24, 2025

Sounds like it's panicking on r-a itself, but yeah, we want analysis-stats to catch it.

@ShoyuVanilla
Copy link
Member

Sounds like it's panicking on r-a itself, but yeah, we want analysis-stats to catch it.

Ah, it sounds like that indeed 😅

@snprajwal
Copy link
Contributor Author

$ rust-analyzer analysis-stats --parallel --only ide::rename::find_definitions crates/ide/
Database loaded:     1.60s, 525minstr, 98mb (metadata 604.73ms, 5405kinstr, 1047kb; build 365.18ms, 11minstr, 45kb)
  item trees: 1288
Item Tree Collection: 800.94ms, 6805minstr, 128mb
  crates: 58, mods: 1139, decls: 29656, bodies: 28777, adts: 2049, consts: 1718
Item Collection:     15.26s, 75ginstr, 1474mb
Body lowering:       351.25ms, 2640minstr, 80mb
Parallel Inference:  36.42s, 101kinstr, 1816mb
  exprs: 351, ??ty: 0 (0%), ?ty: 0 (0%), !ty: 0
  pats: 87, ??ty: 0 (0%), ?ty: 0 (0%), !ty: 0
Inference:           39.62ms, 245minstr, 2768b
MIR lowering:        21.27s, 97ginstr, 451mb
Mir failed bodies: 45 (0%)
Data layouts:        86.04ms, 352minstr, 19mb
Failed data layouts: 0 (0%)
Const evaluation:    51.86ms, 219minstr, 4mb
Failed const evals: 3 (0%)
Total:               74.40s, 183ginstr, 3974mb

@ShoyuVanilla
Copy link
Member

$ rust-analyzer analysis-stats --parallel --only ide::rename::find_definitions crates/ide/
Database loaded:     1.60s, 525minstr, 98mb (metadata 604.73ms, 5405kinstr, 1047kb; build 365.18ms, 11minstr, 45kb)
  item trees: 1288
Item Tree Collection: 800.94ms, 6805minstr, 128mb
  crates: 58, mods: 1139, decls: 29656, bodies: 28777, adts: 2049, consts: 1718
Item Collection:     15.26s, 75ginstr, 1474mb
Body lowering:       351.25ms, 2640minstr, 80mb
Parallel Inference:  36.42s, 101kinstr, 1816mb
  exprs: 351, ??ty: 0 (0%), ?ty: 0 (0%), !ty: 0
  pats: 87, ??ty: 0 (0%), ?ty: 0 (0%), !ty: 0
Inference:           39.62ms, 245minstr, 2768b
MIR lowering:        21.27s, 97ginstr, 451mb
Mir failed bodies: 45 (0%)
Data layouts:        86.04ms, 352minstr, 19mb
Failed data layouts: 0 (0%)
Const evaluation:    51.86ms, 219minstr, 4mb
Failed const evals: 3 (0%)
Total:               74.40s, 183ginstr, 3974mb

Did that module panicked? The log shows nothing abnormal 🤔

@snprajwal
Copy link
Contributor Author

So far, with a release build, there is no sign of failure. I'm trying to reproduce it with a local debug build of rust-analyzer. I'll let you know once I'm able to isolate the panic. If this doesn't work, I'll put up a proof-of-concept project where I can reproduce the exact problem.

@ShoyuVanilla
Copy link
Member

I'll try it with a debug build, too

@snprajwal
Copy link
Contributor Author

snprajwal commented Mar 24, 2025

Here's you go: https://github.com/snprajwal/ra-rpit-failure

Just change the path variable in main.rs to point to the local repo, cargo run triggers the panic.

There is also the chance that I'm doing something incorrectly during the setup - if you do figure that out, please let me know :)

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 I-panic
Projects
None yet
Development

No branches or pull requests

3 participants