Skip to content

Commit

Permalink
Merge branch 'master' into distribute-indexes-first
Browse files Browse the repository at this point in the history
  • Loading branch information
weswigham committed Sep 20, 2018
2 parents 6593dad + 928bff9 commit 7cfd206
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13451,6 +13451,7 @@ namespace ts {
let visited: Map<boolean>;
let contravariant = false;
let propagationType: Type;
let allowComplexConstraintInference = true;
inferFromTypes(originalSource, originalTarget);

function inferFromTypes(source: Type, target: Type): void {
Expand Down Expand Up @@ -13628,7 +13629,15 @@ namespace ts {
// getApparentType can return _any_ type, since an indexed access or conditional may simplify to any other type.
// If that occurs and it doesn't simplify to an object or intersection, we'll need to restart `inferFromTypes`
// with the simplified source.
if (apparentSource !== source && !(apparentSource.flags & (TypeFlags.Object | TypeFlags.Intersection))) {
if (apparentSource !== source && allowComplexConstraintInference && !(apparentSource.flags & (TypeFlags.Object | TypeFlags.Intersection))) {
// TODO: The `allowComplexConstraintInference` flag is a hack! This forbids inference from complex constraints within constraints!
// This isn't required algorithmically, but rather is used to lower the memory burden caused by performing inference
// that is _too good_ in projects with complicated constraints (eg, fp-ts). In such cases, if we did not limit ourselves
// here, we might produce more valid inferences for types, causing us to do more checks and perform more instantiations
// (in addition to the extra stack depth here) which, in turn, can push the already close process over its limit.
// TL;DR: If we ever become generally more memory efficienct (or our resource budget ever increases), we should just
// remove this `allowComplexConstraintInference` flag.
allowComplexConstraintInference = false;
return inferFromTypes(apparentSource, target);
}
source = apparentSource;
Expand Down

0 comments on commit 7cfd206

Please sign in to comment.