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

Expand more Vararg elements during re-intersection if valid. #46604

Merged
merged 1 commit into from
Dec 14, 2023

Conversation

N5N3
Copy link
Member

@N5N3 N5N3 commented Sep 2, 2022

At present, out typeintersection "prefers" Tuple with more parameters.
This PR tries to replace Tuple{Vararg{T,N}} with Tuple{T,T,T,Vararg{T,N}} during re-intersection if we can prove that N >= 3 and N is used only for Vararg length.
It is somewhat similar to #39098 but only fucus on the expansion.

Resolve some intersection regression and this TODO from #46446.
https://github.com/JuliaLang/julia/pull/46446/files#diff-5565c704be02f2d46527b6f2f72a2c138c06d703a18e34316b6ec52b17a94bd4R2112-R2113

@N5N3 N5N3 added the domain:types and dispatch Types, subtyping and method dispatch label Sep 2, 2022
@N5N3 N5N3 changed the title Expend more Vararg elements during re-intersection if valid. Expand more Vararg elements during re-intersection if valid. Sep 2, 2022
@N5N3 N5N3 force-pushed the Vararg_expansion2 branch 3 times, most recently from a1e0565 to 2d682f7 Compare September 3, 2022 06:24
Copy link
Sponsor Member

@vtjnash vtjnash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable to me. But maybe Jeff should take a look too?

@vtjnash vtjnash added the needs pkgeval Tests for all registered packages should be run with this change label Dec 14, 2022
@N5N3 N5N3 marked this pull request as draft March 27, 2023 05:22
This should be valid if the type var is used only for `Vararg` length.
This commit add a new field `max_offset` to our type env. which is used to tracks the minimum length of a `Vararg` during the 1st round intersection. (It's value would be set to `-1` if this var has other usage.)

If we got a positive value, then we can expand more elements during the 2nd round intersection safely. With these extra elements, the offset between 2 `Vararg`s will reduce to 0 (hopefully), and thus we get a more accurate result.
@N5N3 N5N3 marked this pull request as ready for review December 13, 2023 15:40
@N5N3
Copy link
Member Author

N5N3 commented Dec 13, 2023

@nanosoldier runtests()

@vtjnash vtjnash added status:merge me PR is reviewed. Merge when all tests are passing and removed needs pkgeval Tests for all registered packages should be run with this change labels Dec 13, 2023
@nanosoldier
Copy link
Collaborator

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

@N5N3 N5N3 merged commit d69bb97 into JuliaLang:master Dec 14, 2023
7 of 10 checks passed
@N5N3 N5N3 deleted the Vararg_expansion2 branch December 14, 2023 12:23
@N5N3 N5N3 removed the status:merge me PR is reviewed. Merge when all tests are passing label Dec 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:types and dispatch Types, subtyping and method dispatch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants