From 2e9972dd15ca2590a2be813f7801b848036434a1 Mon Sep 17 00:00:00 2001 From: Andrew Casey Date: Fri, 21 Feb 2020 14:27:37 -0800 Subject: [PATCH] Convert UnionOrIntersectionType.couldContainTypeVariables to ObjectFlags ...to save space (and possibly to reduce de-opts, since it appears to be lazily set). --- src/compiler/checker.ts | 16 ++++++++-------- src/compiler/types.ts | 6 ++++-- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3fb59928b301e..f4fa30a0c190c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -17740,18 +17740,18 @@ namespace ts { // results for union and intersection types for performance reasons. function couldContainTypeVariables(type: Type): boolean { const objectFlags = getObjectFlags(type); - return !!(type.flags & TypeFlags.Instantiable || + if (objectFlags & ObjectFlags.CouldContainTypeVariablesComputed) { + return !!(objectFlags & ObjectFlags.CouldContainTypeVariables); + } + const result = !!(type.flags & TypeFlags.Instantiable || objectFlags & ObjectFlags.Reference && ((type).node || forEach(getTypeArguments(type), couldContainTypeVariables)) || objectFlags & ObjectFlags.Anonymous && type.symbol && type.symbol.flags & (SymbolFlags.Function | SymbolFlags.Method | SymbolFlags.Class | SymbolFlags.TypeLiteral | SymbolFlags.ObjectLiteral) && type.symbol.declarations || objectFlags & (ObjectFlags.Mapped | ObjectFlags.ObjectRestType) || - type.flags & TypeFlags.UnionOrIntersection && !(type.flags & TypeFlags.EnumLiteral) && couldUnionOrIntersectionContainTypeVariables(type)); - } - - function couldUnionOrIntersectionContainTypeVariables(type: UnionOrIntersectionType): boolean { - if (type.couldContainTypeVariables === undefined) { - type.couldContainTypeVariables = some(type.types, couldContainTypeVariables); + type.flags & TypeFlags.UnionOrIntersection && !(type.flags & TypeFlags.EnumLiteral) && some((type).types, couldContainTypeVariables)); + if (type.flags & TypeFlags.ObjectFlagsType) { + (type).objectFlags |= ObjectFlags.CouldContainTypeVariablesComputed | (result ? ObjectFlags.CouldContainTypeVariables : 0); } - return type.couldContainTypeVariables; + return result; } function isTypeParameterAtTopLevel(type: Type, typeParameter: TypeParameter): boolean { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 5b334c503217b..f7d6f721f025b 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -4459,6 +4459,10 @@ namespace ts { IsGenericIndexTypeComputed = 1 << 24, // IsGenericIndexType flag has been computed /* @internal */ IsGenericIndexType = 1 << 25, // Union or intersection contains generic index type + /* @internal */ + CouldContainTypeVariablesComputed = 1 << 26, // CouldContainTypeVariables flag has been computed + /* @internal */ + CouldContainTypeVariables = 1 << 27, // Type could contain a type variable ClassOrInterface = Class | Interface, /* @internal */ RequiresWidening = ContainsWideningType | ContainsObjectOrArrayLiteral, @@ -4577,8 +4581,6 @@ namespace ts { resolvedStringIndexType: IndexType; /* @internal */ resolvedBaseConstraint: Type; - /* @internal */ - couldContainTypeVariables: boolean; } export interface UnionType extends UnionOrIntersectionType {