Merge pull request #18174 from Microsoft/fixContextualTypeLogicalOr

Fix exponential compile time for || operator
This commit is contained in:
Anders Hejlsberg 2017-08-31 17:12:51 +01:00 committed by GitHub
commit e294b23500
5 changed files with 241 additions and 1 deletions

View File

@ -13059,7 +13059,7 @@ namespace ts {
// expression has no contextual type, the right operand is contextually typed by the type of the left operand.
let type = getContextualType(binaryExpression);
if (!type && node === binaryExpression.right) {
type = getTypeOfExpression(binaryExpression.left);
type = getTypeOfExpression(binaryExpression.left, /*cache*/ true);
}
return type;
}

View File

@ -0,0 +1,36 @@
//// [contextualTypeLogicalOr.ts]
// Repro from #18005
let x = 123;
var a =
x && [1, 2, 3, 4] ||
x && [1, 2, 3, 4] ||
x && [1, 2, 3, 4] ||
x && [1, 2, 3, 4] ||
x && [1, 2, 3, 4] ||
x && [1, 2, 3, 4] ||
x && [1, 2, 3, 4] ||
x && [1, 2, 3, 4] ||
x && [1, 2, 3, 4] ||
x && [1, 2, 3, 4] ||
x && [1, 2, 3, 4] ||
x && [1, 2, 3, 4] ||
x && [1, 2, 3, 4];
//// [contextualTypeLogicalOr.js]
// Repro from #18005
var x = 123;
var a = x && [1, 2, 3, 4] ||
x && [1, 2, 3, 4] ||
x && [1, 2, 3, 4] ||
x && [1, 2, 3, 4] ||
x && [1, 2, 3, 4] ||
x && [1, 2, 3, 4] ||
x && [1, 2, 3, 4] ||
x && [1, 2, 3, 4] ||
x && [1, 2, 3, 4] ||
x && [1, 2, 3, 4] ||
x && [1, 2, 3, 4] ||
x && [1, 2, 3, 4] ||
x && [1, 2, 3, 4];

View File

@ -0,0 +1,48 @@
=== tests/cases/compiler/contextualTypeLogicalOr.ts ===
// Repro from #18005
let x = 123;
>x : Symbol(x, Decl(contextualTypeLogicalOr.ts, 2, 3))
var a =
>a : Symbol(a, Decl(contextualTypeLogicalOr.ts, 3, 3))
x && [1, 2, 3, 4] ||
>x : Symbol(x, Decl(contextualTypeLogicalOr.ts, 2, 3))
x && [1, 2, 3, 4] ||
>x : Symbol(x, Decl(contextualTypeLogicalOr.ts, 2, 3))
x && [1, 2, 3, 4] ||
>x : Symbol(x, Decl(contextualTypeLogicalOr.ts, 2, 3))
x && [1, 2, 3, 4] ||
>x : Symbol(x, Decl(contextualTypeLogicalOr.ts, 2, 3))
x && [1, 2, 3, 4] ||
>x : Symbol(x, Decl(contextualTypeLogicalOr.ts, 2, 3))
x && [1, 2, 3, 4] ||
>x : Symbol(x, Decl(contextualTypeLogicalOr.ts, 2, 3))
x && [1, 2, 3, 4] ||
>x : Symbol(x, Decl(contextualTypeLogicalOr.ts, 2, 3))
x && [1, 2, 3, 4] ||
>x : Symbol(x, Decl(contextualTypeLogicalOr.ts, 2, 3))
x && [1, 2, 3, 4] ||
>x : Symbol(x, Decl(contextualTypeLogicalOr.ts, 2, 3))
x && [1, 2, 3, 4] ||
>x : Symbol(x, Decl(contextualTypeLogicalOr.ts, 2, 3))
x && [1, 2, 3, 4] ||
>x : Symbol(x, Decl(contextualTypeLogicalOr.ts, 2, 3))
x && [1, 2, 3, 4] ||
>x : Symbol(x, Decl(contextualTypeLogicalOr.ts, 2, 3))
x && [1, 2, 3, 4];
>x : Symbol(x, Decl(contextualTypeLogicalOr.ts, 2, 3))

View File

@ -0,0 +1,139 @@
=== tests/cases/compiler/contextualTypeLogicalOr.ts ===
// Repro from #18005
let x = 123;
>x : number
>123 : 123
var a =
>a : number[]
x && [1, 2, 3, 4] ||
>x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] : number[]
>x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] : number[]
>x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] : number[]
>x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] : number[]
>x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] : number[]
>x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] : number[]
>x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] : number[]
>x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] : number[]
>x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] : number[]
>x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] : number[]
>x && [1, 2, 3, 4] || x && [1, 2, 3, 4] || x && [1, 2, 3, 4] : number[]
>x && [1, 2, 3, 4] || x && [1, 2, 3, 4] : number[]
>x && [1, 2, 3, 4] : number[]
>x : number
>[1, 2, 3, 4] : number[]
>1 : 1
>2 : 2
>3 : 3
>4 : 4
x && [1, 2, 3, 4] ||
>x && [1, 2, 3, 4] : number[]
>x : number
>[1, 2, 3, 4] : number[]
>1 : 1
>2 : 2
>3 : 3
>4 : 4
x && [1, 2, 3, 4] ||
>x && [1, 2, 3, 4] : number[]
>x : number
>[1, 2, 3, 4] : number[]
>1 : 1
>2 : 2
>3 : 3
>4 : 4
x && [1, 2, 3, 4] ||
>x && [1, 2, 3, 4] : number[]
>x : number
>[1, 2, 3, 4] : number[]
>1 : 1
>2 : 2
>3 : 3
>4 : 4
x && [1, 2, 3, 4] ||
>x && [1, 2, 3, 4] : number[]
>x : number
>[1, 2, 3, 4] : number[]
>1 : 1
>2 : 2
>3 : 3
>4 : 4
x && [1, 2, 3, 4] ||
>x && [1, 2, 3, 4] : number[]
>x : number
>[1, 2, 3, 4] : number[]
>1 : 1
>2 : 2
>3 : 3
>4 : 4
x && [1, 2, 3, 4] ||
>x && [1, 2, 3, 4] : number[]
>x : number
>[1, 2, 3, 4] : number[]
>1 : 1
>2 : 2
>3 : 3
>4 : 4
x && [1, 2, 3, 4] ||
>x && [1, 2, 3, 4] : number[]
>x : number
>[1, 2, 3, 4] : number[]
>1 : 1
>2 : 2
>3 : 3
>4 : 4
x && [1, 2, 3, 4] ||
>x && [1, 2, 3, 4] : number[]
>x : number
>[1, 2, 3, 4] : number[]
>1 : 1
>2 : 2
>3 : 3
>4 : 4
x && [1, 2, 3, 4] ||
>x && [1, 2, 3, 4] : number[]
>x : number
>[1, 2, 3, 4] : number[]
>1 : 1
>2 : 2
>3 : 3
>4 : 4
x && [1, 2, 3, 4] ||
>x && [1, 2, 3, 4] : number[]
>x : number
>[1, 2, 3, 4] : number[]
>1 : 1
>2 : 2
>3 : 3
>4 : 4
x && [1, 2, 3, 4] ||
>x && [1, 2, 3, 4] : number[]
>x : number
>[1, 2, 3, 4] : number[]
>1 : 1
>2 : 2
>3 : 3
>4 : 4
x && [1, 2, 3, 4];
>x && [1, 2, 3, 4] : number[]
>x : number
>[1, 2, 3, 4] : number[]
>1 : 1
>2 : 2
>3 : 3
>4 : 4

View File

@ -0,0 +1,17 @@
// Repro from #18005
let x = 123;
var a =
x && [1, 2, 3, 4] ||
x && [1, 2, 3, 4] ||
x && [1, 2, 3, 4] ||
x && [1, 2, 3, 4] ||
x && [1, 2, 3, 4] ||
x && [1, 2, 3, 4] ||
x && [1, 2, 3, 4] ||
x && [1, 2, 3, 4] ||
x && [1, 2, 3, 4] ||
x && [1, 2, 3, 4] ||
x && [1, 2, 3, 4] ||
x && [1, 2, 3, 4] ||
x && [1, 2, 3, 4];