-
-
Notifications
You must be signed in to change notification settings - Fork 14.2k
Simplify TypeFreshener methods.
#150239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Simplify TypeFreshener methods.
#150239
Conversation
`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.
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.
There was a problem hiding this 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
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.
It never happens in practice.
0d4649d to
2d10f47
Compare
| #[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>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now always returns Some?
There was a problem hiding this comment.
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.
It's no longer needed.
|
Thanks for the suggestions, this has ended up much nicer than the first version. |
|
@bors try @rust-timer queue freshening should be at least somewhat hot? |
|
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
|
⌛ Trying commit ec5e96e with merge 1f5b4d4… To cancel the try build, run the command Workflow: https://github.com/rust-lang/rust/actions/runs/20457123989 |
…=<try> Simplify `TypeFreshener` methods.
|
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. |
|
💥 Test timed out after |
|
@bors try |
|
⌛ Trying commit ec5e96e with merge d1d7c44… To cancel the try build, run the command Workflow: https://github.com/rust-lang/rust/actions/runs/20470354760 |
…=<try> Simplify `TypeFreshener` methods.
freshen_{ty,const}take aResultand just do a fold if the input isOk. It's simpler to do those folds at the call site, and only callfreshen_{ty,const}in theErrcase. That way we can also avoid useless fold operations on the results ofnew_{int,uint,float}.Also, make some
bug!calls more concise.r? @lcnr