-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[flow] better handing of unions in type guard checks
Summary: This change tries to prevent performance regression in code like the following ``` declare var x: T; declare var foo: (x: mixed) => x is T if (foo(x)) {} ``` where T is a large enum-like union. Before this change, `predicate_no_concretization` on a `LatentP` predicate would do concretize all types, including unions, leading to the breakup of the type of the large union `T`. In `types_differ`, each member of `T` is compared against each member of the type guard type, which also happens to be `T`. This effectively yields a O(n^2) operation which becomes too slow on large enough `T`s. This diff tries to address this by introducing a layer of faster checks before we get to the slow check above. Specifically, 1. we make the initial concretization preserve enum-like unions (which tend to be large) 2. we use fast comparison of this concretized type against the guard (`try_intersect`) 3. if we don't reach a good result, we proceed to concretize the input again, this time using full concretization on unions. 4. for each part of the newly concretized input, we run the same comparison against the guard (`try_intersect`) Changelog: [internal] Reviewed By: SamChou19815 Differential Revision: D69762017 fbshipit-source-id: 39f0af1541f3646c977cdc8860290a2c298fd622
- Loading branch information
1 parent
d3c7390
commit 32c180b
Showing
4 changed files
with
66 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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