You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix sharing of upper bound edges under speculation
Summary:
## The problem
Short-circuiting constraints that have been seen before in different speculation
branches can be unsound. Consider for example the following
```
type X = (x: $ElementType<{name: string}, 'name'>) => void;
declare var foo: X & X;
foo(1);
```
Here the following sequence happens leading to an unsound result:
```
Speculation begins
Branch A:
A1. new tvar v for EvalT
[...]
A2. v ~> ReposUseT
A3. ReposUseT is added to v.upper
[...]
A4. Speculative Error recorded
Branch B:
B1. reuse cached v for EvalT
[...] (same as in case A)
B2. v ~> ReposUseT
B3. immediate success, because ReposUseT is already in v.upper
```
The problem with the above is that constraint `v ~> ReposUseT` was reused
across speculation branches.
## The fix
This diff ensures that we only short-circuit upper-bounds, when the previous
edge was discovered on the same speculation path (same or ancestor branch).
To do this, it adds an optional (speculation id, case id) pair as part of the key to
the map that stores upper bounds of type variables.
This way, in the example above, the edge created in A2, will not be reused in B3,
since the speculation cases differ.
Reviewed By: mvitousek
Differential Revision: D24848916
fbshipit-source-id: 8c800e7ef6ad691dbf18aa1766c746dbf1a0fd5c
0 commit comments