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

inference: apply tmerge limit elementwise to the Union #50927

Merged
merged 3 commits into from
Sep 15, 2023

Conversation

vtjnash
Copy link
Sponsor Member

@vtjnash vtjnash commented Aug 15, 2023

This allows forming larger unions, as long as each element in the Union is both relatively distinct and relatively simple. For example:

tmerge(Base.BitSigned, Nothing) == Union{Nothing, Int128, Int16, Int32, Int64, Int8}
tmerge(Tuple{Base.BitSigned, Int}, Nothing) == Union{Nothing, Tuple{Any, Int64}}
tmerge(AbstractVector{Int}, Vector) == AbstractVector
tmerge(AbstractVector{Int}, Array) == AbstractArray

@vtjnash vtjnash added needs tests Unit tests are required for this change needs nanosoldier run This PR should have benchmarks run on it needs pkgeval Tests for all registered packages should be run with this change labels Aug 15, 2023
oscardssmith added a commit that referenced this pull request Aug 17, 2023
…0929)

This is the part of #50927
required to fix #49249.
Specifically, before this change `tmerge(Tuple{Any, Int}, Nothing)`
would be `Union{Nothing, Tuple{Any, Int}}` but `tmerge(Tuple{BIG_UNION,
Int}, Nothing)` would be `Union{Nothing, Tuple{Any, Any}}`. This feels
bad intuitively because giving the compiler more type information led it
to forget type information that it already knew about, and is especially
damaging because it led to unnecessary type instability when iterating
tuples with complex element types (because the iterator state should be
inferrable as an `Int` even if you have no idea what the tuple type is).

This is tagged for backport to 1.10 since it is a relatively unobtrusive
change and it fixes the string regression in a more proper way.
vtjnash pushed a commit to vtjnash/julia that referenced this pull request Aug 18, 2023
…liaLang#50929)

This is the part of JuliaLang#50927
required to fix JuliaLang#49249.
Specifically, before this change `tmerge(Tuple{Any, Int}, Nothing)`
would be `Union{Nothing, Tuple{Any, Int}}` but `tmerge(Tuple{BIG_UNION,
Int}, Nothing)` would be `Union{Nothing, Tuple{Any, Any}}`. This feels
bad intuitively because giving the compiler more type information led it
to forget type information that it already knew about, and is especially
damaging because it led to unnecessary type instability when iterating
tuples with complex element types (because the iterator state should be
inferrable as an `Int` even if you have no idea what the tuple type is).

This is tagged for backport to 1.10 since it is a relatively unobtrusive
change and it fixes the string regression in a more proper way.
vtjnash pushed a commit to vtjnash/julia that referenced this pull request Aug 18, 2023
…liaLang#50929)

This is the part of JuliaLang#50927
required to fix JuliaLang#49249.
Specifically, before this change `tmerge(Tuple{Any, Int}, Nothing)`
would be `Union{Nothing, Tuple{Any, Int}}` but `tmerge(Tuple{BIG_UNION,
Int}, Nothing)` would be `Union{Nothing, Tuple{Any, Any}}`. This feels
bad intuitively because giving the compiler more type information led it
to forget type information that it already knew about, and is especially
damaging because it led to unnecessary type instability when iterating
tuples with complex element types (because the iterator state should be
inferrable as an `Int` even if you have no idea what the tuple type is).

This is tagged for backport to 1.10 since it is a relatively unobtrusive
change and it fixes the string regression in a more proper way.
IanButterworth pushed a commit that referenced this pull request Aug 19, 2023
…0929)

This is the part of #50927
required to fix #49249.
Specifically, before this change `tmerge(Tuple{Any, Int}, Nothing)`
would be `Union{Nothing, Tuple{Any, Int}}` but `tmerge(Tuple{BIG_UNION,
Int}, Nothing)` would be `Union{Nothing, Tuple{Any, Any}}`. This feels
bad intuitively because giving the compiler more type information led it
to forget type information that it already knew about, and is especially
damaging because it led to unnecessary type instability when iterating
tuples with complex element types (because the iterator state should be
inferrable as an `Int` even if you have no idea what the tuple type is).

This is tagged for backport to 1.10 since it is a relatively unobtrusive
change and it fixes the string regression in a more proper way.

(cherry picked from commit 6e2e6d0)
This allows forming larger unions, as long as each element in the Union
is both relatively distinct and relatively simple. For example:

    tmerge(Base.BitSigned, Nothing) == Union{Nothing, Int128, Int16, Int32, Int64, Int8}
    tmerge(Tuple{Base.BitSigned, Int}, Nothing) == Union{Nothing, Tuple{Any, Int64}}
    tmerge(AbstractVector{Int}, Vector) == AbstractVector

Disables a test from dc8d885.

Co-authored-by: Oscar Smith <oscardssmith@gmail.com>
@vtjnash vtjnash removed the needs tests Unit tests are required for this change label Sep 12, 2023
@vtjnash vtjnash marked this pull request as ready for review September 13, 2023 14:23
@vtjnash
Copy link
Sponsor Member Author

vtjnash commented Sep 13, 2023

@nanosoldier runbenchmarks(ALL, vs=":master")

@vtjnash
Copy link
Sponsor Member Author

vtjnash commented Sep 13, 2023

@nanosoldier runtests()

@vtjnash vtjnash added compiler:inference Type inference and removed needs nanosoldier run This PR should have benchmarks run on it needs pkgeval Tests for all registered packages should be run with this change labels Sep 13, 2023
@nanosoldier
Copy link
Collaborator

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here.

@vtjnash
Copy link
Sponsor Member Author

vtjnash commented Sep 13, 2023

Seems that this will eliminate an allocation in sparse matmul, but otherwise does not change anything.

@gbaraldi
Copy link
Member

Doesn't seem to have any regressions in inference so I guess it's still worth

@nanosoldier
Copy link
Collaborator

The package evaluation job you requested has completed - possible new issues were detected.
The full report is available.

@JeffBezanson
Copy link
Sponsor Member

JeffBezanson commented Sep 15, 2023

tmerge(AbstractVector{Int}, Vector) == AbstractArray

Can this be AbstractVector?
Edit: wait --- looks like it already is?

@vtjnash vtjnash merged commit a61d1b4 into master Sep 15, 2023
11 of 12 checks passed
@vtjnash vtjnash deleted the jn/tmerge-elementwise branch September 15, 2023 22:32
@vtjnash
Copy link
Sponsor Member Author

vtjnash commented Sep 15, 2023

Yeah, that was changed in a later version of the PR at Oscar's insistence, and updated in the commit messages but not the PR text. Initially I didn't have the tname_intersection function returning the intersection, so it couldn't match up the parameters.

NHDaly pushed a commit that referenced this pull request Sep 20, 2023
This allows forming larger unions, as long as each element in the Union
is both relatively distinct and relatively simple. For example:

    tmerge(Base.BitSigned, Nothing) == Union{Nothing, Int128, Int16, Int32, Int64, Int8}
    tmerge(Tuple{Base.BitSigned, Int}, Nothing) == Union{Nothing, Tuple{Any, Int64}}
    tmerge(AbstractVector{Int}, Vector) == AbstractVector

Disables a test from dc8d885, which does not seem possible to handle currently.

This makes somewhat drastic changes to make this algorithm more
commutative and simpler, since we dropped the final widening to `Any`.

Co-authored-by: pchintalapudi <34727397+pchintalapudi@users.noreply.github.com>
Co-authored-by: Oscar Smith <oscardssmith@gmail.com>
nalimilan pushed a commit that referenced this pull request Nov 5, 2023
…0929)

This is the part of #50927
required to fix #49249.
Specifically, before this change `tmerge(Tuple{Any, Int}, Nothing)`
would be `Union{Nothing, Tuple{Any, Int}}` but `tmerge(Tuple{BIG_UNION,
Int}, Nothing)` would be `Union{Nothing, Tuple{Any, Any}}`. This feels
bad intuitively because giving the compiler more type information led it
to forget type information that it already knew about, and is especially
damaging because it led to unnecessary type instability when iterating
tuples with complex element types (because the iterator state should be
inferrable as an `Int` even if you have no idea what the tuple type is).

This is tagged for backport to 1.10 since it is a relatively unobtrusive
change and it fixes the string regression in a more proper way.

(cherry picked from commit 6e2e6d0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:inference Type inference
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants