-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
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.
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`.
| } | ||
| } | ||
|
|
||
| ty::FreshTy(ct) | ty::FreshIntTy(ct) | ty::FreshFloatTy(ct) => { |
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.
when do we actually encounter existing fresh types when freshening. Looking at this rn, this seems odd, would you mind try to remove this and checking where we ICE?
I feel like we should never have to re-freshen something
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
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