Skip to content

Commit

Permalink
Merge pull request #7373 from Microsoft/limitInferenceDepth
Browse files Browse the repository at this point in the history
set the maximum depth to explore during type inference
  • Loading branch information
vladima committed Mar 3, 2016
2 parents 24c47f1 + 1589e4f commit 744e510
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6585,6 +6585,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<boolean> = {};
Expand Down Expand Up @@ -6713,6 +6714,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;
}
Expand Down

0 comments on commit 744e510

Please sign in to comment.