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

typelimits: Prevent accidental infinite growth in size limiting #48421

Merged
merged 2 commits into from
Feb 5, 2023

Conversation

Keno
Copy link
Member

@Keno Keno commented Jan 26, 2023

There's a few related issues here:

  1. Type size limiting depended on the identity of contained TypeVars. E.g. Base.rewrap_unionall(Foo{Base.unwrap_unionall(A)}, A), would not be limited while the equivalent with typevars substituted would be. This is obviously undesirable because the identity of typevars is an implementation detail.
  2. We were forcing tupledepth to 1 in the typevar case to allow replacing typevars by something concrete. However, this also allowed typevars being replaced by something derived from sources, which could be huge and itself contain TypeVars, allowing infinite growth.
  3. There was a type query that was run on types containg free typevars. This would have asserted in a debug build and gave wrong answers in a release build.

Fix all three issues, which together addresses an inference non-termination seen in #48329.

@Keno Keno requested review from vtjnash and aviatesk January 26, 2023 21:03
@vtjnash vtjnash added the needs pkgeval Tests for all registered packages should be run with this change label Jan 26, 2023
@Keno
Copy link
Member Author

Keno commented Jan 28, 2023

Let's try this version.

@Keno
Copy link
Member Author

Keno commented Jan 28, 2023

@nanosoldier runtests()

@nanosoldier
Copy link
Collaborator

Your package evaluation job has completed - possible new issues were detected.
A full report can be found here.

@Keno
Copy link
Member Author

Keno commented Jan 29, 2023

I don't see anything that looks inference quality related

@vtjnash vtjnash added 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 Jan 29, 2023
Copy link
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.

So it turned out that we don't need to remove the point 2. (forcing tupledepth to be 1 in `type_more_complex's typevar handling)?

Keno and others added 2 commits February 4, 2023 08:36
There's a few related issues here:
1. Type size limiting depended on the identity of contained TypeVars.
   E.g. `Base.rewrap_unionall(Foo{Base.unwrap_unionall(A)}, A)`, would
   not be limited while the equivalent with typevars substituted would be.
   This is obviously undesirable because the identity of typevars is an
   implementation detail.
2. We were forcing `tupledepth` to 1 in the typevar case to allow replacing
   typevars by something concrete. However, this also allowed typevars being
   replaced by something derived from `sources`, which could be huge and itself
   contain TypeVars, allowing infinite growth.
3. There was a type query that was run on types containg free typevars. This
   would have asserted in a debug build and gave wrong answers in a release build.

Fix all three issues, which together addresses an inference non-termination seen in #48329.
@Keno
Copy link
Member Author

Keno commented Feb 4, 2023

Huh, I thought we had merged this. This was supposed to have been merged before #48329, whoops.

@DilumAluthge DilumAluthge merged commit 51e3bc3 into master Feb 5, 2023
@DilumAluthge DilumAluthge deleted the kf/badsizelimit branch February 5, 2023 16:18
@DilumAluthge DilumAluthge removed the merge me PR is reviewed. Merge when all tests are passing label Feb 5, 2023
vtjnash added a commit that referenced this pull request Mar 27, 2023
In #48421 we removed all limits from apply_type, but that can lead to
significant expression complexity which may be hard for subtyping to
deal with. Try adding a heuristic size limiting constraint.
Also do a bunch of code rearrangement and slight cleanup so that this
change does not make the logic look complicated here.

Solves #49127
vtjnash added a commit that referenced this pull request Apr 4, 2023
In #48421 we removed all limits from apply_type, but that can lead to
significant expression complexity which may be hard for subtyping to
deal with. Try adding a heuristic size limiting constraint.
Also do a bunch of code rearrangement and slight cleanup so that this
change does not make the logic look complicated here.

Solves #49127
aviatesk pushed a commit that referenced this pull request Apr 10, 2023
In #48421 we removed all limits from apply_type, but that can lead to
significant expression complexity which may be hard for subtyping to
deal with. Try adding a heuristic size limiting constraint.
Also do a bunch of code rearrangement and slight cleanup so that this
change does not make the logic look complicated here.

Solves #49127
Xnartharax pushed a commit to Xnartharax/julia that referenced this pull request Apr 19, 2023
In JuliaLang#48421 we removed all limits from apply_type, but that can lead to
significant expression complexity which may be hard for subtyping to
deal with. Try adding a heuristic size limiting constraint.
Also do a bunch of code rearrangement and slight cleanup so that this
change does not make the logic look complicated here.

Solves JuliaLang#49127
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.

5 participants