Skip to content
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

Merged
merged 1 commit into from
Oct 27, 2022

Conversation

Keno
Copy link
Member

@Keno Keno commented Oct 24, 2022

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.

Comment on lines +471 to 473
typea = widenconditional(typea)
typeb = widenconditional(typeb)
return tmerge(widenlattice(lattice), typea, typeb)
Copy link
Sponsor Member

@vtjnash vtjnash Oct 24, 2022

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)

Copy link
Member Author

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.

Copy link
Sponsor Member

@aviatesk aviatesk left a 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.

base/compiler/typelimits.jl Outdated Show resolved Hide resolved
base/compiler/typelimits.jl Outdated Show resolved Hide resolved
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.
@oscardssmith
Copy link
Member

I think this is ready to go!

@Keno Keno merged commit f71b839 into master Oct 27, 2022
@Keno Keno deleted the kf/widenlatticeelem branch October 27, 2022 16:23
aviatesk added a commit that referenced this pull request Dec 16, 2022
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.
aviatesk added a commit that referenced this pull request Dec 19, 2022
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants