rust-lang / rust-lang/rust

Expanding type recursion check in debug info generation has false positives

Open
#145,912 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-debuginfo C-bug T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I tried this code: rustc -g non_recursive.rs

struct Wrap<T>(T);

enum NonRecursive<T> {
  A(*const NonRecursive<Wrap<()>>),
  B(T),
}

fn main() {
  let _ = std::hint::black_box(NonRecursive::B(()));
}

I expected to see this happen: No expanding recursion detected and debuginfo is complete.

Instead, this happened: NonRecurse<()> is detected as expanding recursive. NonRecurse<Wrap<()>> has no debuginfo for members.

Meta

rustc --version --verbose:

rustc 1.91.0-dev
binary: rustc
commit-hash: unknown
commit-date: unknown
host: x86_64-unknown-linux-gnu
release: 1.91.0-dev
LLVM version: 21.1.0
Analysis

The expanding recursion check I introduced in #138599 and #145297 is fundamentally flawed.
The idea is that if we see an expanding generic parameter in traversal, then we conclude the type is expanding recursive.
E.g.

enum Recursive<T> {
    Rec(*const Recursive<Wrap<T>>),
    Item(T),
}

If we starts with Recursive<T>, then we'll visit the following types:

  • Recurse<T>
  • *const Recursive<Wrap<T>>
  • Recursive<Wrap<T>> // the generic parameter gets an additional depth.

The problem is that we're working with instantiated types in debug info generation.
There we can't distinguish generic parameters from concrete types.
E.g. for the false positive code, we'll visit the following types:

  • NonRecursive<()>
  • *const NonRecursive<Wrap<()>>
  • NonRecursive<Wrap<()>> // detected but shouldn't.

Maybe the check should be changed into plain old recursion limit.

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

Start by reproducing the issue with rustc -g non_recursive.rs and read the expanding recursion changes from #138599 and #145297. Determine how instantiated types are distinguished during debug info generation and evaluate the suggested recursion-limit direction. Done means the example no longer reports expanding recursion and NonRecursive<Wrap<()>> receives complete debuginfo.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.