Improve canonical_param_env_cache - #160673
Open
nnethercote wants to merge 4 commits into
Open
Conversation
Currently it is modified with the very clunky `canonical_param_env_cache_get_or_insert` method, which takes two closures. This commit replaces that with `with_canonical_param_env_cache` a simpler accessor that is very similar to the nearby `with_global_cache`. This lets `canonicalize_param_env` use normal hash map operations. The commit also: - Introduces a dedicated `CanonicalParamEnvCache` newtype. - Adds a helpful comment to `CanonicalizeParamEnvCacheEntry::param_env`.
I now understand what is happening here.
It avoids some repetition.
There are two canonicalization steps done by `canonicalize_input` and `canonicalize_param_env`: `env` (possible cached) and `rest`. `canonicalize_param_env` does the `env` step. It returns several pieces of a canonicalizer (either from the cache or by constructing a canonicalizer) and then `canonicalize_input` uses those parts to construct a second canonicalizer, which it uses for `rest`. This commit changes things so that `canonicalize_param_env` does the `env` part (if necessary) and then returns a canonicalizer that can do the `rest` part. I find this easier to read. In particular, we no longer construct an `env` canonicalizer when it's not necessary, we immediately construct the `rest` canonicalizer.
Contributor
Author
|
@bors try @rust-timer queue |
Collaborator
|
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
This comment has been minimized.
This comment has been minimized.
rust-bors Bot
pushed a commit
that referenced
this pull request
Aug 7, 2026
…, r=<try> Improve `canonical_param_env_cache`
lcnr
reviewed
Aug 7, 2026
| Vec<CanonicalVarKind<I>>, | ||
| HashMap<I::GenericArg, usize>, | ||
| ) { | ||
| fn canonicalize_param_env(delegate: &'a D, param_env: I::ParamEnv) -> (I::ParamEnv, Self) { |
Contributor
There was a problem hiding this comment.
comment on this function. its return type is kinda weird
Contributor
|
nit, otherwise r=me depending on perf |
Contributor
Collaborator
|
Queued c169ced with parent 88f7399, future comparison URL. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This function is messy and has been bothering me. Several cleanups, details in individual commits.
r? @lcnr