Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: When evaluating spreads inside an array literal, we would "finish" the array type with a different element type for each type that was being spread. This effectively created a "union of array types" instead of a single array type, which could be fanned into an exponential blowup, or worse, an infinite loop, by a suitably crafted cycle in the constraint graph. Now we pin the element type early and thread it through so that we can always "finish" with that element type. Fixes #4070 Fixes #4370 Reviewed By: samwgoldman Differential Revision: D7416763 fbshipit-source-id: 5d6c6e020311bef4fd90d95c96abc83325fea80a
- Loading branch information
1 parent
a7cc8f1
commit 4aac3d4
Showing
13 changed files
with
272 additions
and
93 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// @flow | ||
|
||
function foo(xs: Array<any>) { | ||
const zs = []; | ||
xs | ||
.map( | ||
x => [], | ||
) | ||
.map(ys => | ||
ys | ||
.map(y => []) | ||
.reduce((a, b) => [...a, ...b], []), | ||
) | ||
.reduce((a, b) => [...a, ...b], []) | ||
.forEach(z => { | ||
zs.push(z); | ||
}); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// @flow | ||
|
||
const ys = new Map(); | ||
const y = ys.get('a'); | ||
|
||
ys.set('a', [...y]); | ||
ys.set('a', [...y]); | ||
ys.set('a', [...y]); | ||
ys.set('a', [...y]); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// @flow | ||
export const checkComponent = (obj: any[]): Object[] => | ||
obj.reduce((acc, x) => { | ||
if (x === undefined) { | ||
return [...acc, {}]; | ||
} | ||
|
||
if (x === 'hi') { | ||
return [...acc, {}]; | ||
} | ||
|
||
if (x.err) { | ||
return [...acc, {}]; | ||
} | ||
return acc; | ||
}, []); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// @noflow | ||
|
||
type A = {kind: 'a', e: Type}; | ||
type B = {kind: 'b', k: Type, v: Type}; | ||
type C = {kind: 'c'}; | ||
type Type = A | B | C; | ||
|
||
type TypeCases<R> = {| | ||
a: (A) => R, | ||
b: (B) => R, | ||
c: (C) => R | ||
|}; | ||
|
||
function matcher<R>(cases: TypeCases<R>): (Type) => R { | ||
return (type) => cases[type.kind](type); | ||
} | ||
|
||
const f: Type => Array<string> = matcher({ | ||
a: (a: A) => [...f(a.e)], | ||
b: (b: B) => [...f(b.k), ...f(b.v)], | ||
c: () => [''] | ||
}); |
Oops, something went wrong.