Skip to content

Commit 2e9972d

Browse files
committed
Convert UnionOrIntersectionType.couldContainTypeVariables to ObjectFlags
...to save space (and possibly to reduce de-opts, since it appears to be lazily set).
1 parent a5061ef commit 2e9972d

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
@@ -17740,18 +17740,18 @@ namespace ts {
1774017740
// results for union and intersection types for performance reasons.
1774117741
function couldContainTypeVariables(type: Type): boolean {
1774217742
const objectFlags = getObjectFlags(type);
17743-
return !!(type.flags & TypeFlags.Instantiable ||
17743+
if (objectFlags & ObjectFlags.CouldContainTypeVariablesComputed) {
17744+
return !!(objectFlags & ObjectFlags.CouldContainTypeVariables);
17745+
}
17746+
const result = !!(type.flags & TypeFlags.Instantiable ||
1774417747
objectFlags & ObjectFlags.Reference && ((<TypeReference>type).node || forEach(getTypeArguments(<TypeReference>type), couldContainTypeVariables)) ||
1774517748
objectFlags & ObjectFlags.Anonymous && type.symbol && type.symbol.flags & (SymbolFlags.Function | SymbolFlags.Method | SymbolFlags.Class | SymbolFlags.TypeLiteral | SymbolFlags.ObjectLiteral) && type.symbol.declarations ||
1774617749
objectFlags & (ObjectFlags.Mapped | ObjectFlags.ObjectRestType) ||
17747-
type.flags & TypeFlags.UnionOrIntersection && !(type.flags & TypeFlags.EnumLiteral) && couldUnionOrIntersectionContainTypeVariables(<UnionOrIntersectionType>type));
17748-
}
17749-
17750-
function couldUnionOrIntersectionContainTypeVariables(type: UnionOrIntersectionType): boolean {
17751-
if (type.couldContainTypeVariables === undefined) {
17752-
type.couldContainTypeVariables = some(type.types, couldContainTypeVariables);
17750+
type.flags & TypeFlags.UnionOrIntersection && !(type.flags & TypeFlags.EnumLiteral) && some((<UnionOrIntersectionType>type).types, couldContainTypeVariables));
17751+
if (type.flags & TypeFlags.ObjectFlagsType) {
17752+
(<ObjectFlagsType>type).objectFlags |= ObjectFlags.CouldContainTypeVariablesComputed | (result ? ObjectFlags.CouldContainTypeVariables : 0);
1775317753
}
17754-
return type.couldContainTypeVariables;
17754+
return result;
1775517755
}
1775617756

1775717757
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)