Repository navigation
Optimize fun_apply - #16148
Merged
Merged
Optimize fun_apply#16148
Conversation
When applying an intersection of arrows, an arrow whose domain is disjoint from the input does not apply. Refining the return type with it only computes a subset of the result obtained by skipping it, yet each such arrow doubled the number of paths explored.
Compute the meets of all elements upfront when checking tuple emptiness, so negative tuples disjoint on a later element are skipped before splitting the line on earlier elements.
Check the disjointness of all fields upfront when checking map emptiness, so negative maps disjoint on a later field are skipped before splitting the line on earlier fields. Unlike tuples, meets are computed lazily, only on the fields we split, as most map lines are not empty and their checks finish early.
Instead of encoding the input of function application as a tuple, keep it as a list of disjoint products of arguments. This is valid as application distributes over unions. Subtracting an arrow's domain is then done argument by argument, reusing the tuple meets, which tells upfront if the arrow is disjoint and avoids tuple differences and emptiness checks.
When refining the return type with an arrow, every result reachable from that branch is a subset of the refined return. If it is already contained in the accumulated result, the branch cannot add anything.
gldubc
approved these changes
Nov 21, 2026
| # - input: The input type being applied to the function | ||
| # - products: The input being applied to the function, as a list of disjoint | ||
| # products, each product being a list of non-empty static arguments. | ||
| # This is valid because application distributes over unions |
Member
There was a problem hiding this comment.
Suggested change
| # This is valid because application distributes over unions |
Incorrect comment. This is just an equivalent representation of the same set, no need for distribution.
josevalim
force-pushed
the
jv-fun-apply-fast
branch
from
November 21, 2026 17:12
17db1ae to
6a91b31
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Commits can be reviewed individually.