Skip to content

Commit 43f2cba

Browse files
committed
Move anonymous type instantiation cache from AST node to root type
1 parent ad3ae36 commit 43f2cba

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/compiler/checker.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15071,10 +15071,6 @@ namespace ts {
1507115071
filter(typeParameters, tp => isTypeParameterPossiblyReferenced(tp, declaration)) :
1507215072
typeParameters;
1507315073
links.outerTypeParameters = typeParameters;
15074-
if (typeParameters.length) {
15075-
links.instantiations = new Map<string, Type>();
15076-
links.instantiations.set(getTypeListId(typeParameters), target);
15077-
}
1507815074
}
1507915075
if (typeParameters.length) {
1508015076
// We are instantiating an anonymous type that has one or more type parameters in scope. Apply the
@@ -15083,13 +15079,17 @@ namespace ts {
1508315079
const combinedMapper = combineTypeMappers(type.mapper, mapper);
1508415080
const typeArguments = map(typeParameters, t => getMappedType(t, combinedMapper));
1508515081
const id = getTypeListId(typeArguments);
15086-
let result = links.instantiations!.get(id);
15082+
if (!target.instantiations) {
15083+
target.instantiations = new Map<string, Type>();
15084+
target.instantiations.set(getTypeListId(typeParameters), target);
15085+
}
15086+
let result = target.instantiations.get(id);
1508715087
if (!result) {
1508815088
const newMapper = createTypeMapper(typeParameters, typeArguments);
1508915089
result = target.objectFlags & ObjectFlags.Reference ? createDeferredTypeReference((<DeferredTypeReference>type).target, (<DeferredTypeReference>type).node, newMapper) :
1509015090
target.objectFlags & ObjectFlags.Mapped ? instantiateMappedType(<MappedType>target, newMapper) :
1509115091
instantiateAnonymousType(target, newMapper);
15092-
links.instantiations!.set(id, result);
15092+
target.instantiations.set(id, result);
1509315093
}
1509415094
return result;
1509515095
}

src/compiler/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4847,7 +4847,6 @@ namespace ts {
48474847
deferredNodes?: ESMap<NodeId, Node>; // Set of nodes whose checking has been deferred
48484848
capturedBlockScopeBindings?: Symbol[]; // Block-scoped bindings captured beneath this part of an IterationStatement
48494849
outerTypeParameters?: TypeParameter[]; // Outer type parameters of anonymous object type
4850-
instantiations?: ESMap<string, Type>; // Instantiations of generic type alias (undefined if non-generic)
48514850
isExhaustive?: boolean; // Is node an exhaustive switch statement
48524851
skipDirectInference?: true; // Flag set by the API `getContextualType` call on a node when `Completions` is passed to force the checker to skip making inferences to a node's type
48534852
declarationRequiresScopeChange?: boolean; // Set by `useOuterVariableScopeInParameter` in checker when downlevel emit would change the name resolution scope inside of a parameter.
@@ -5141,6 +5140,8 @@ namespace ts {
51415140
node: TypeReferenceNode | ArrayTypeNode | TupleTypeNode;
51425141
/* @internal */
51435142
mapper?: TypeMapper;
5143+
/* @internal */
5144+
instantiations?: ESMap<string, Type>; // Instantiations of generic type alias (undefined if non-generic)
51445145
}
51455146

51465147
/* @internal */
@@ -5221,6 +5222,7 @@ namespace ts {
52215222
export interface AnonymousType extends ObjectType {
52225223
target?: AnonymousType; // Instantiation target
52235224
mapper?: TypeMapper; // Instantiation mapper
5225+
instantiations?: ESMap<string, Type>; // Instantiations of generic type alias (undefined if non-generic)
52245226
}
52255227

52265228
/* @internal */

0 commit comments

Comments
 (0)