Skip to content

Move placeholder error handling to before region inference#142623

Closed
amandasystems wants to merge 11 commits intorust-lang:mainfrom
amandasystems:early-placeholder-errors
Closed

Move placeholder error handling to before region inference#142623
amandasystems wants to merge 11 commits intorust-lang:mainfrom
amandasystems:early-placeholder-errors

Conversation

@amandasystems
Copy link
Copy Markdown
Contributor

@amandasystems amandasystems commented Jun 17, 2025

This PR supersedes #130227. It removes precise tracking of placeholders in borrowck, moving them to an earlier stage. This leads to better performance, since we track less information. It is also part of the preparations for Polonius by moving specialised logic out of region inference itself and into the region graph or other, common pre-processing steps. Originally, the intention was to do this in multiple steps, but since some of them incur performance penalties won back by later stages, doing them in one go makes the net results clearer.

Error reporting changes

  1. Higher-kinded region errors (placeholder outliving a placeholder, etc) are only reported if there are no other borrowck errors.
  2. Due to the less precise nature of the revised tracking, there can be multiple overlapping errors involving the same placeholders/existential regions. In that case, not all errors will be reported. Crucially, only one pair per constraint graph SCC will be reported. A common case is Trait<r1, r2>, which frequently gives two error messages, one for each region. Under this logic it only gives one.
  3. In some cases, finding named regions to slot into diagnostics is now more difficult, since not all outlived named regions are traced. This degrades some diagnostics by replacing named regions with anonymous ones, or by picking differently named ones.
  4. In precisely one test, tests/ui/impl-trait/nested-rpit-hrtb.rs, we now also add r: 'static, which causes an extra error. Being more conservative when rewriting the constraint graph and avoiding it when invalid outlives are already detected breaks existing diagnostics for many, many tests that rely on the extra r: 'static to find out why they error.

Due to reason 2., several UI tests change, a lot, since they rely on diagnostic duplication being turned off to find several duplicate errors.

Code structure changes

  • Placeholder errors are now detected earlier, if they happen.
  • SCC annotations are dynamically chosen to be less rich for region graphs with no placeholders, opting to skip a lot of the logic. This is crucial for performance; both runtime and memory use, since it allows simple function bodies to skip some allocations and extra computation during SCC construction.
  • SCC annotations are now written in an update-style as opposed to the previous, more functional style. It seems to be more performant and it's certainly more succinct.

r? lcnr

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants