Repository navigation
Short-circuit empty branches in function and list emptiness checks - #16032
Merged
Merged
Conversation
Similar to #15619, avoid exploring branches whose result is already known. In phi, a branch whose refined return type (ret ∧ return) or refined argument (arg ∖ type) is empty is true, as empty types are never refined back, so we return true without recursing over the remaining positives. In list_line_empty?, subtype_seen?/3 already computes the difference between the last types, so compute it once instead of computing it again and re-checking its emptiness when the subtype check fails. Timings per subtype?/2 call, before and after: | Case | Before | After | |---------------------------------------------|---------|--------| | fun, 5 arrows with none() args (holds) | 114µs | 6.7µs | | fun, 5 arrows with none() args (fails) | 58µs | 4.4µs | | non_empty_list, 4 negatives cover the tail | 1.62µs | 1.49µs | | non_empty_list, partial cover | 1.27µs | 1.13µs | Assisted-by: Claude Code:claude-opus-5-5
josevalim
force-pushed
the
jv-optimize-fun-phi
branch
from
October 28, 2026 16:14
c4e635b to
e4867f4
Compare
gldubc
approved these changes
Oct 29, 2026
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.
Similar to #15619, avoid exploring branches whose result is already known.
In phi, a branch whose refined return type (ret ∧ return) or refined argument (arg ∖ type) is empty is true, as empty types are never refined back, so we return true without recursing over the remaining positives.
In list_line_empty?, subtype_seen?/3 already computes the difference between the last types, so compute it once instead of computing it again and re-checking its emptiness when the subtype check fails.
Timings per subtype?/2 call, before and after:
Assisted-by: Claude Code:claude-opus-5-5