From d615d21e6d3f3280895b68261764a64f439d22d9 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 26 Aug 2015 06:41:41 -0700 Subject: [PATCH] Add cache of anonymous object type instantiations to TypeMapper --- src/compiler/checker.ts | 10 ++++++++++ src/compiler/types.ts | 1 + 2 files changed, 11 insertions(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index cff964361a..ff8cf4e365 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4487,6 +4487,15 @@ namespace ts { } function instantiateAnonymousType(type: ObjectType, mapper: TypeMapper): ObjectType { + if (mapper.instantiations) { + let cachedType = mapper.instantiations[type.id]; + if (cachedType) { + return cachedType; + } + } + else { + mapper.instantiations = []; + } // Mark the anonymous type as instantiated such that our infinite instantiation detection logic can recognize it let result = createObjectType(TypeFlags.Anonymous | TypeFlags.Instantiated, type.symbol); result.properties = instantiateList(getPropertiesOfObjectType(type), mapper, instantiateSymbol); @@ -4497,6 +4506,7 @@ namespace ts { let numberIndexType = getIndexTypeOfType(type, IndexKind.Number); if (stringIndexType) result.stringIndexType = instantiateType(stringIndexType, mapper); if (numberIndexType) result.numberIndexType = instantiateType(numberIndexType, mapper); + mapper.instantiations[type.id] = result; return result; } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index dfa4485926..80d82547f8 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1953,6 +1953,7 @@ namespace ts { /* @internal */ export interface TypeMapper { (t: TypeParameter): Type; + instantiations?: Type[]; // Cache of instantiations created using this type mapper. context?: InferenceContext; // The inference context this mapper was created from. // Only inference mappers have this set (in createInferenceMapper). // The identity mapper and regular instantiation mappers do not need it.