From e7f415d5e517a1020da52dbd8d4d476a730507d0 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Mon, 22 Feb 2016 11:50:52 -0800 Subject: [PATCH 1/2] Merge pull request #7163 from Microsoft/cachePairs do not make inferences with the same source\target pair multiple times --- src/compiler/checker.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e6d3ec5ccea..b4427dbb690 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6446,6 +6446,7 @@ namespace ts { let targetStack: Type[]; let depth = 0; let inferiority = 0; + const visited: Map = {}; inferFromTypes(source, target); function isInProcess(source: Type, target: Type) { @@ -6575,6 +6576,12 @@ namespace ts { return; } + const key = source.id + "," + target.id; + if (hasProperty(visited, key)) { + return; + } + visited[key] = true; + if (depth === 0) { sourceStack = []; targetStack = []; From 365e5446da2f4f042e37a55f09187095c3764913 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Thu, 3 Mar 2016 12:18:49 -0800 Subject: [PATCH 2/2] Merge pull request #7373 from Microsoft/limitInferenceDepth set the maximum depth to explore during type inference --- src/compiler/checker.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b4427dbb690..44713b2c1db 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6444,6 +6444,7 @@ namespace ts { function inferTypes(context: InferenceContext, source: Type, target: Type) { let sourceStack: Type[]; let targetStack: Type[]; + const maxDepth = 5; let depth = 0; let inferiority = 0; const visited: Map = {}; @@ -6572,6 +6573,11 @@ namespace ts { if (isInProcess(source, target)) { return; } + // we delibirately limit the depth we examine to infer types: this speeds up the overall inference process + // and user rarely expects inferences to be made from the deeply nested constituents. + if (depth > maxDepth) { + return; + } if (isDeeplyNestedGeneric(source, sourceStack, depth) && isDeeplyNestedGeneric(target, targetStack, depth)) { return; }