Skip to content

Conversation

@nnethercote
Copy link
Contributor

freshen_{ty,const} take a Result and just do a fold if the input is Ok. It's simpler to do those folds at the call site, and only call freshen_{ty,const} in the Err case. That way we can also avoid useless fold operations on the results of new_{int,uint,float}.

Also, make some bug! calls more concise.

r? @lcnr

`freshen_{ty,const}` take a `Result` and just do a fold if the input is
`Ok`. It's simpler to do those folds at the call site, and only call
`freshen_{ty,const}` in the `Err` case. That way we can also avoid
useless fold operations on the results of `new_{int,uint,float}`.

Also, make some `bug!` calls more concise.
@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 Dec 22, 2025
I have always found this confusingly named, because it creates a new
freshener rather than returning an existing one. We can remove it and
just use `TypeFreshener::new()` at the two call sites, avoiding this
confusion.
Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

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

r=me, but would love for u to look into a related refactor

View changes since this review

Sometimes we freshen using a new `TypeFreshener`, and sometimes we
freshen with an existing `TypeFreshener`. For the former we have the
method `InferCtxt::freshen`. For the latter we just call `fold_with`.
This asymmetry has been confusing to me.

This commit removes `InferCtxt::freshen` so that all the freshening
sites consistently use `fold_with` and it's obvious if each one is using
a new or existing `TypeFreshener`.
Because `fresh_trait_pred` is the name of the field/argument. The `_ref`
suffix appears to be a typo, or left over from earlier versions of the
code.
@nnethercote nnethercote force-pushed the simplify-TypeFreshener-methods branch from 0d4649d to 2d10f47 Compare December 22, 2025 12:47
#[inline(never)]
fn fold_infer_ty(&mut self, v: ty::InferTy) -> Option<Ty<'tcx>> {
match v {
fn fold_infer_ty(&mut self, ty: ty::InferTy) -> Option<Ty<'tcx>> {
Copy link
Contributor

Choose a reason for hiding this comment

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

now always returns Some?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes! I have added a commit to remove the Option.

@nnethercote
Copy link
Contributor Author

Thanks for the suggestions, this has ended up much nicer than the first version.

@lcnr
Copy link
Contributor

lcnr commented Dec 23, 2025

@bors try @rust-timer queue

freshening should be at least somewhat hot?

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

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

@rust-bors
Copy link

rust-bors bot commented Dec 23, 2025

⌛ Trying commit ec5e96e with merge 1f5b4d4

To cancel the try build, run the command @bors try cancel.

Workflow: https://github.com/rust-lang/rust/actions/runs/20457123989

rust-bors bot added a commit that referenced this pull request Dec 23, 2025
…=<try>

Simplify `TypeFreshener` methods.
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Dec 23, 2025
@nnethercote
Copy link
Contributor Author

Freshening is definitely hot, but freshening of inference variables is much less so. Local measurements indicated that the perf effects were negligible, but it doesn't hurt to double check.

@rust-bors
Copy link

rust-bors bot commented Dec 23, 2025

💥 Test timed out after 21600s

@lcnr
Copy link
Contributor

lcnr commented Dec 23, 2025

@bors try

@rust-bors
Copy link

rust-bors bot commented Dec 23, 2025

⌛ Trying commit ec5e96e with merge d1d7c44

To cancel the try build, run the command @bors try cancel.

Workflow: https://github.com/rust-lang/rust/actions/runs/20470354760

rust-bors bot added a commit that referenced this pull request Dec 23, 2025
…=<try>

Simplify `TypeFreshener` methods.
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants