Skip to content

Avoid global trait caches while defining opaque types - #162036

Open
dominic-r wants to merge 2 commits into
rust-lang:mainfrom
dominic-r:dominic/issue-159932-obligation-cache
Open

Avoid global trait caches while defining opaque types#162036
dominic-r wants to merge 2 commits into
rust-lang:mainfrom
dominic-r:dominic/issue-159932-obligation-cache

Conversation

@dominic-r

@dominic-r dominic-r commented Aug 31, 2026

Copy link
Copy Markdown

Fixes #159932.

The old trait solver stores evaluated obligations in a global cache so they can be reused across inference contexts. While type checking a body that defines opaque types or coroutines, it avoided the global cache only when the current predicate mentioned one directly.

However, that check was insufficient. A predicate can depend on an opaque type through another obligation without mentioning the opaque type itself. A small source change could alter the order in which obligations were evaluated and therefore change the contents of the global cache. On the next incremental build, rustc could evaluate the same query key with different cache state and produce a different result. Incremental verification detected the changed fingerprint and raised the ICE.

So, this PR removes that exception. While a body defines opaque types or coroutines, the old trait solver now uses only the inference context's local caches. (These still avoid repeated work during the current type-checking run, but results are no longer shared between inference contexts where they may depend on an opaque type being defined.)

Do note that this may reduce global cache hits for async code and return-position impl Trait. It also removes part of the caching compromise introduced in #132625 for the compile-time regression tracked in #132064.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 31, 2026
@rustbot

rustbot commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust Project has assigned @mati865 (or someone else) to review your changes, you should hear from them (or someone else) within the next two weeks.

Please see the contribution instructions and our LLM policy for more information.

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 75 candidates
  • Random selection from 18 candidates

@mati865

mati865 commented Aug 31, 2026

Copy link
Copy Markdown
Member

Not familiar with this area. @rustbot reroll

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

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. 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.

[ICE]: incremental compilation error with evaluate_obligation

4 participants