-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
lattice: Allow external lattice to have a say in how to widen #47307
Conversation
0890df3
to
dd1a215
Compare
typea = widenconditional(typea) | ||
typeb = widenconditional(typeb) | ||
return tmerge(widenlattice(lattice), typea, typeb) |
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.
no lattice? (overall, SGTM, though I only partially follow the intended need here)
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.
You mean why spell this as widenconditional
rather than widenlattice
? The lack of widenconditional
here was just an oversight in the original PR. It's there in the non-IPO version of this function. It was exposed here, because I stopped doing an unconditional widenconst
at the Consts
layer. I do think this could be spelled as widenlattice
also, but I wanted to minimize the impact for the time being, since I don't actually have an example of a lattice layer inserted at a place where it would make a difference.
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.
We can probably use widenlattice
in place of widenconditional
where we handle Conditional
all over the place, but that change would be significant. This PR looks reasonable to experiment widenlattice(::AbstractLattice, x)
interface.
dd1a215
to
409134d
Compare
409134d
to
e58e076
Compare
Currently, when e.g. a PartialStruct is not of interest to the lattice code, it just calls `widenconst` on it to pass it to the next lattice layer. This might be insufficient if an intermediate lattice layer has some other representation that is wider that the `PartialStruct`, but narrower than the corresponding `widenconst`. This adds `widenconst(::AbstractLatice, ::Any)` to allow the lattices to insert custom widening code. By default, it ends up calling `widenconst`, so there's no functional change in base, but custom lattices can make use of the extra hook. I'm not entirely sure that this is what we want the final interface to look like (I think it probably does too many type checks), but it works reasonably well and I think is good enough to experiment with.
e58e076
to
cce900c
Compare
I think this is ready to go! |
When merging `PartialStruct`, we are currently merging their fields a bit aggressively (#47307) in order to accelerate convergence. However, when `PartialStruct` wraps external lattice elements, this can be too aggressive since it does not use `tmerge(𝕃, fields...)` recursively and thus the external lattice elements are not merged as expected. This commit adds an additional lattice hook, `tmerge_field`, inside `tmerge(::PartialsLattice)` so that external lattice implementation can provide its own field-merge strategies.
When merging `PartialStruct`, we are currently merging their fields a bit aggressively (#47307) in order to accelerate convergence. However, when `PartialStruct` wraps external lattice elements, this can be too aggressive since it does not use `tmerge(𝕃, fields...)` recursively and thus the external lattice elements are not merged as expected. This commit adds an additional lattice hook, `tmerge_field`, inside `tmerge(::PartialsLattice)` so that external lattice implementation can provide its own field-merge strategies.
Currently, when e.g. a PartialStruct is not of interest to the lattice code, it just calls
widenconst
on it to pass it to the next lattice layer. This might be insufficient if an intermediate lattice layer has some other representation that is wider that thePartialStruct
, but narrower than the correspondingwidenconst
. This addswidenconst(::AbstractLatice, ::Any)
to allow the lattices to insert custom widening code. By default, it ends up callingwidenconst
, so there's no functional change in base, but custom lattices can make use of the extra hook.I'm not entirely sure that this is what we want the final interface to look like (I think it probably does too many type checks), but it works reasonably well and I think is good enough to experiment with.