Skip to content

Commit

Permalink
Auto merge of #117749 - aliemjay:perf-canon-cache, r=lcnr
Browse files Browse the repository at this point in the history
cache param env canonicalization

Canonicalize ParamEnv only once and store it. Then whenever we try to canonicalize `ParamEnvAnd<'tcx, T>` we only have to canonicalize `T` and then merge the results.

Prelimiary results show ~3-4% savings in diesel and serde benchmarks.

Best to review commits individually. Some commits have a short description.

Initial implementation had a soundness bug (rust-lang/rust#117749 (comment)) due to cache invalidation:
- When canonicalizing `Ty<'?0>` we first try to resolve region variables in the current InferCtxt which may have a constraint `?0 == 'static`. This means that we register `Ty<'?0> => Canonical<Ty<'static>>` in the cache, which is obviously incorrect in another inference context.
- This is fixed by not doing region resolution when canonicalizing the query *input* (vs. response), which is the only place where ParamEnv is used, and then in a later commit we *statically* guard against any form of inference variable resolution of the cached canonical ParamEnv's.

r? `@ghost`
  • Loading branch information
bors committed Dec 14, 2023
2 parents 031926a + b57f3b0 commit 3fee9c9
Showing 0 changed files with 0 additions and 0 deletions.

0 comments on commit 3fee9c9

Please sign in to comment.