Skip to content

Improve canonical_param_env_cache - #160673

Open
nnethercote wants to merge 4 commits into
rust-lang:mainfrom
nnethercote:improve-canonical-param-env-cache
Open

Improve canonical_param_env_cache#160673
nnethercote wants to merge 4 commits into
rust-lang:mainfrom
nnethercote:improve-canonical-param-env-cache

Conversation

@nnethercote

Copy link
Copy Markdown
Contributor

This function is messy and has been bothering me. Several cleanups, details in individual commits.

r? @lcnr

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.
@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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Aug 7, 2026
@nnethercote

Copy link
Copy Markdown
Contributor Author

@bors try @rust-timer queue

@rust-timer

Copy link
Copy Markdown
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 7, 2026
@rust-bors

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`
Vec<CanonicalVarKind<I>>,
HashMap<I::GenericArg, usize>,
) {
fn canonicalize_param_env(delegate: &'a D, param_env: I::ParamEnv) -> (I::ParamEnv, Self) {

@lcnr lcnr Aug 7, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment on this function. its return type is kinda weird

View changes since the review

@lcnr

lcnr commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

nit, otherwise r=me depending on perf

@rust-bors

rust-bors Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: c169ced (c169ced75222c26df96e6eb9a2afdec3c7d9222f)
Base parent: 88f7399 (88f7399cb4912680976e1c342ea7661b9dc84940)

@rust-timer

Copy link
Copy Markdown
Collaborator

Queued c169ced with parent 88f7399, future comparison URL.
There are currently 12 preceding artifacts in the queue.
It will probably take at least ~12.0 hours until the benchmark run finishes.

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

Labels

S-waiting-on-perf Status: Waiting on a perf run to be completed. 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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants