-
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.
fate of the union (a.k.a. the roads not taken)
Summary: This diff re-implements how union (and intersection) types are checked in Flow, fixing serious bugs in the current system. The problem =========== Flow's inference engine is designed to find more errors over time as constraints are added...but it is not designed to backtrack. Unfortunately, checking the type of an expression against a union type does need backtracking: if some branch of the union doesn't work out, the next branch must be tried, and so on. The situation is further complicated by the fact that the type of the expression may be unknown at the point of checking, so that a branch that looks promising now might turn out to be incorrect later. The solution ============ The basic idea is to delay trying a branch until a point where we can decide whether the branch will definitely fail or succeed, without adding constraints. If trying the branch results in failure, we can move on to the next branch without needing to backtrack. If the branch succeeds, we are done. The final case is where the branch looks promising, but we cannot be sure without adding constraints: in this case we try other branches, and *bail* when we run into ambiguities...requesting additional annotations to decide which branch to select. Overall, this means that (1) we never commit to a branch that might turn out to be incorrect and (2) can always select a correct branch (if such exists) given enough annotations. As a matter of implementation, we need to distinguish between annotations and inferred types for this scheme to work: in particular, we fully resolve annotations before branches are tried, and then use whatever partial information we can obtain from inferred types to disambiguate those branches. Fixes #1759 Fixes #1664 Fixes #1663 Fixes #1462 Fixes #1455 Fixes #1371 Fixes #1349 Fixes #824 Fixes #815 Reviewed By: bhosmer Differential Revision: D3229344 fbshipit-source-id: 64da005f4a7eaa4b6a8c74c535b27ab24c7b80bc
- Loading branch information
1 parent
699253b
commit 2df7671
Showing
98 changed files
with
3,713 additions
and
1,982 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
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
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
Oops, something went wrong.
2df7671
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eagerly awaiting this. Any ETA on when this gets shipped in a release?