Skip to content

Commit b5bd38b

Browse files
authored
Convert UnionOrIntersectionType.couldContainTypeVariables to ObjectFlags (#36947)
...to save space (and possibly to reduce de-opts, since it appears to be lazily set).
1 parent 865c120 commit b5bd38b

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/compiler/checker.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17753,18 +17753,18 @@ namespace ts {
1775317753
// results for union and intersection types for performance reasons.
1775417754
function couldContainTypeVariables(type: Type): boolean {
1775517755
const objectFlags = getObjectFlags(type);
17756-
return !!(type.flags & TypeFlags.Instantiable ||
17756+
if (objectFlags & ObjectFlags.CouldContainTypeVariablesComputed) {
17757+
return !!(objectFlags & ObjectFlags.CouldContainTypeVariables);
17758+
}
17759+
const result = !!(type.flags & TypeFlags.Instantiable ||
1775717760
objectFlags & ObjectFlags.Reference && ((<TypeReference>type).node || forEach(getTypeArguments(<TypeReference>type), couldContainTypeVariables)) ||
1775817761
objectFlags & ObjectFlags.Anonymous && type.symbol && type.symbol.flags & (SymbolFlags.Function | SymbolFlags.Method | SymbolFlags.Class | SymbolFlags.TypeLiteral | SymbolFlags.ObjectLiteral) && type.symbol.declarations ||
1775917762
objectFlags & (ObjectFlags.Mapped | ObjectFlags.ObjectRestType) ||
17760-
type.flags & TypeFlags.UnionOrIntersection && !(type.flags & TypeFlags.EnumLiteral) && couldUnionOrIntersectionContainTypeVariables(<UnionOrIntersectionType>type));
17761-
}
17762-
17763-
function couldUnionOrIntersectionContainTypeVariables(type: UnionOrIntersectionType): boolean {
17764-
if (type.couldContainTypeVariables === undefined) {
17765-
type.couldContainTypeVariables = some(type.types, couldContainTypeVariables);
17763+
type.flags & TypeFlags.UnionOrIntersection && !(type.flags & TypeFlags.EnumLiteral) && some((<UnionOrIntersectionType>type).types, couldContainTypeVariables));
17764+
if (type.flags & TypeFlags.ObjectFlagsType) {
17765+
(<ObjectFlagsType>type).objectFlags |= ObjectFlags.CouldContainTypeVariablesComputed | (result ? ObjectFlags.CouldContainTypeVariables : 0);
1776617766
}
17767-
return type.couldContainTypeVariables;
17767+
return result;
1776817768
}
1776917769

1777017770
function isTypeParameterAtTopLevel(type: Type, typeParameter: TypeParameter): boolean {

src/compiler/types.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4459,6 +4459,10 @@ namespace ts {
44594459
IsGenericIndexTypeComputed = 1 << 24, // IsGenericIndexType flag has been computed
44604460
/* @internal */
44614461
IsGenericIndexType = 1 << 25, // Union or intersection contains generic index type
4462+
/* @internal */
4463+
CouldContainTypeVariablesComputed = 1 << 26, // CouldContainTypeVariables flag has been computed
4464+
/* @internal */
4465+
CouldContainTypeVariables = 1 << 27, // Type could contain a type variable
44624466
ClassOrInterface = Class | Interface,
44634467
/* @internal */
44644468
RequiresWidening = ContainsWideningType | ContainsObjectOrArrayLiteral,
@@ -4577,8 +4581,6 @@ namespace ts {
45774581
resolvedStringIndexType: IndexType;
45784582
/* @internal */
45794583
resolvedBaseConstraint: Type;
4580-
/* @internal */
4581-
couldContainTypeVariables: boolean;
45824584
}
45834585

45844586
export interface UnionType extends UnionOrIntersectionType {

0 commit comments

Comments
 (0)