Skip to content

Commit 6091050

Browse files
committed
Remove pre-computation of minTypeArgumentCount
1 parent 9ba2a6b commit 6091050

File tree

2 files changed

+29
-36
lines changed

2 files changed

+29
-36
lines changed

src/compiler/checker.ts

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,10 @@ namespace ts {
169169
const noConstraintType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
170170
const circularConstraintType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
171171

172-
const anySignature = createSignature(undefined, undefined, 0, undefined, emptyArray, anyType, /*typePredicate*/ undefined, 0, /*hasRestParameter*/ false, /*hasLiteralTypes*/ false);
173-
const unknownSignature = createSignature(undefined, undefined, 0, undefined, emptyArray, unknownType, /*typePredicate*/ undefined, 0, /*hasRestParameter*/ false, /*hasLiteralTypes*/ false);
174-
const resolvingSignature = createSignature(undefined, undefined, 0, undefined, emptyArray, anyType, /*typePredicate*/ undefined, 0, /*hasRestParameter*/ false, /*hasLiteralTypes*/ false);
175-
const silentNeverSignature = createSignature(undefined, undefined, 0, undefined, emptyArray, silentNeverType, /*typePredicate*/ undefined, 0, /*hasRestParameter*/ false, /*hasLiteralTypes*/ false);
172+
const anySignature = createSignature(undefined, undefined, undefined, emptyArray, anyType, /*typePredicate*/ undefined, 0, /*hasRestParameter*/ false, /*hasLiteralTypes*/ false);
173+
const unknownSignature = createSignature(undefined, undefined, undefined, emptyArray, unknownType, /*typePredicate*/ undefined, 0, /*hasRestParameter*/ false, /*hasLiteralTypes*/ false);
174+
const resolvingSignature = createSignature(undefined, undefined, undefined, emptyArray, anyType, /*typePredicate*/ undefined, 0, /*hasRestParameter*/ false, /*hasLiteralTypes*/ false);
175+
const silentNeverSignature = createSignature(undefined, undefined, undefined, emptyArray, silentNeverType, /*typePredicate*/ undefined, 0, /*hasRestParameter*/ false, /*hasLiteralTypes*/ false);
176176

177177
const enumNumberIndexInfo = createIndexInfo(stringType, /*isReadonly*/ true);
178178

@@ -3845,7 +3845,7 @@ namespace ts {
38453845
function getConstructorsForTypeArguments(type: Type, typeArgumentNodes: TypeNode[]): Signature[] {
38463846
const typeArgCount = length(typeArgumentNodes);
38473847
return filter(getSignaturesOfType(type, SignatureKind.Construct),
3848-
sig => typeArgCount >= sig.minTypeArgumentCount && typeArgCount <= length(sig.typeParameters));
3848+
sig => typeArgCount >= getMinTypeArgumentCount(sig.typeParameters) && typeArgCount <= length(sig.typeParameters));
38493849
}
38503850

38513851
function getInstantiatedConstructorsForTypeArguments(type: Type, typeArgumentNodes: TypeNode[]): Signature[] {
@@ -4059,7 +4059,6 @@ namespace ts {
40594059
type.typeParameters = concatenate(outerTypeParameters, localTypeParameters);
40604060
type.outerTypeParameters = outerTypeParameters;
40614061
type.localTypeParameters = localTypeParameters;
4062-
type.minTypeArgumentCount = getMinTypeArgumentCount(localTypeParameters);
40634062
(<GenericType>type).instantiations = createMap<TypeReference>();
40644063
(<GenericType>type).instantiations.set(getTypeListId(type.typeParameters), <GenericType>type);
40654064
(<GenericType>type).target = <GenericType>type;
@@ -4103,7 +4102,6 @@ namespace ts {
41034102
// Initialize the instantiation cache for generic type aliases. The declared type corresponds to
41044103
// an instantiation of the type alias with the type parameters supplied as type arguments.
41054104
links.typeParameters = typeParameters;
4106-
links.minTypeArgumentCount = getMinTypeArgumentCount(typeParameters);
41074105
links.instantiations = createMap<Type>();
41084106
links.instantiations.set(getTypeListId(typeParameters), type);
41094107
}
@@ -4417,12 +4415,11 @@ namespace ts {
44174415
resolveObjectTypeMembers(type, source, typeParameters, typeArguments);
44184416
}
44194417

4420-
function createSignature(declaration: SignatureDeclaration, typeParameters: TypeParameter[], minTypeArgumentCount: number, thisParameter: Symbol | undefined, parameters: Symbol[],
4418+
function createSignature(declaration: SignatureDeclaration, typeParameters: TypeParameter[], thisParameter: Symbol | undefined, parameters: Symbol[],
44214419
resolvedReturnType: Type, typePredicate: TypePredicate, minArgumentCount: number, hasRestParameter: boolean, hasLiteralTypes: boolean): Signature {
44224420
const sig = new Signature(checker);
44234421
sig.declaration = declaration;
44244422
sig.typeParameters = typeParameters;
4425-
sig.minTypeArgumentCount = minTypeArgumentCount;
44264423
sig.parameters = parameters;
44274424
sig.thisParameter = thisParameter;
44284425
sig.resolvedReturnType = resolvedReturnType;
@@ -4434,27 +4431,26 @@ namespace ts {
44344431
}
44354432

44364433
function cloneSignature(sig: Signature): Signature {
4437-
return createSignature(sig.declaration, sig.typeParameters, sig.minTypeArgumentCount, sig.thisParameter, sig.parameters, sig.resolvedReturnType,
4434+
return createSignature(sig.declaration, sig.typeParameters, sig.thisParameter, sig.parameters, sig.resolvedReturnType,
44384435
sig.typePredicate, sig.minArgumentCount, sig.hasRestParameter, sig.hasLiteralTypes);
44394436
}
44404437

44414438
function getDefaultConstructSignatures(classType: InterfaceType): Signature[] {
44424439
const baseConstructorType = getBaseConstructorTypeOfClass(classType);
44434440
const baseSignatures = getSignaturesOfType(baseConstructorType, SignatureKind.Construct);
44444441
if (baseSignatures.length === 0) {
4445-
return [createSignature(undefined, classType.localTypeParameters, classType.minTypeArgumentCount, undefined, emptyArray, classType, /*typePredicate*/ undefined, 0, /*hasRestParameter*/ false, /*hasLiteralTypes*/ false)];
4442+
return [createSignature(undefined, classType.localTypeParameters, undefined, emptyArray, classType, /*typePredicate*/ undefined, 0, /*hasRestParameter*/ false, /*hasLiteralTypes*/ false)];
44464443
}
44474444
const baseTypeNode = getBaseTypeNodeOfClass(classType);
44484445
const typeArguments = map(baseTypeNode.typeArguments, getTypeFromTypeNode);
44494446
const typeArgCount = length(typeArguments);
44504447
const result: Signature[] = [];
44514448
for (const baseSig of baseSignatures) {
4452-
const minTypeArgumentCount = baseSig.minTypeArgumentCount;
4449+
const minTypeArgumentCount = getMinTypeArgumentCount(baseSig.typeParameters);
44534450
const typeParamCount = length(baseSig.typeParameters);
44544451
if (typeArgCount >= minTypeArgumentCount && typeArgCount <= typeParamCount) {
44554452
const sig = typeParamCount ? createSignatureInstantiation(baseSig, fillMissingTypeArguments(typeArguments, baseSig.typeParameters, minTypeArgumentCount)) : cloneSignature(baseSig);
44564453
sig.typeParameters = classType.localTypeParameters;
4457-
sig.minTypeArgumentCount = classType.minTypeArgumentCount;
44584454
sig.resolvedReturnType = classType;
44594455
result.push(sig);
44604456
}
@@ -5320,7 +5316,7 @@ namespace ts {
53205316
createTypePredicateFromTypePredicateNode(declaration.type as TypePredicateNode) :
53215317
undefined;
53225318

5323-
links.resolvedSignature = createSignature(declaration, typeParameters, getMinTypeArgumentCount(typeParameters), thisParameter, parameters, returnType, typePredicate, minArgumentCount, hasRestParameter(declaration), hasLiteralTypes);
5319+
links.resolvedSignature = createSignature(declaration, typeParameters, thisParameter, parameters, returnType, typePredicate, minArgumentCount, hasRestParameter(declaration), hasLiteralTypes);
53245320
}
53255321
return links.resolvedSignature;
53265322
}
@@ -5451,7 +5447,7 @@ namespace ts {
54515447
}
54525448

54535449
function getSignatureInstantiation(signature: Signature, typeArguments: Type[]): Signature {
5454-
typeArguments = fillMissingTypeArguments(typeArguments, signature.typeParameters, signature.minTypeArgumentCount);
5450+
typeArguments = fillMissingTypeArguments(typeArguments, signature.typeParameters, getMinTypeArgumentCount(signature.typeParameters));
54555451
const instantiations = signature.instantiations || (signature.instantiations = createMap<Signature>());
54565452
const id = getTypeListId(typeArguments);
54575453
let instantiation = instantiations.get(id);
@@ -5618,20 +5614,21 @@ namespace ts {
56185614
const typeParameters = type.localTypeParameters;
56195615
if (typeParameters) {
56205616
const numTypeArguments = length(node.typeArguments);
5621-
if (numTypeArguments < type.minTypeArgumentCount || numTypeArguments > typeParameters.length) {
5617+
const minTypeArgumentCount = getMinTypeArgumentCount(typeParameters);
5618+
if (numTypeArguments < minTypeArgumentCount || numTypeArguments > typeParameters.length) {
56225619
error(node,
5623-
type.minTypeArgumentCount === typeParameters.length
5620+
minTypeArgumentCount === typeParameters.length
56245621
? Diagnostics.Generic_type_0_requires_1_type_argument_s
56255622
: Diagnostics.Generic_type_0_requires_between_1_and_2_type_arguments,
56265623
typeToString(type, /*enclosingDeclaration*/ undefined, TypeFormatFlags.WriteArrayAsGenericType),
5627-
type.minTypeArgumentCount,
5624+
minTypeArgumentCount,
56285625
typeParameters.length);
56295626
return unknownType;
56305627
}
56315628
// In a type reference, the outer type parameters of the referenced class or interface are automatically
56325629
// supplied as type arguments and the type reference only specifies arguments for the local type parameters
56335630
// of the class or interface.
5634-
const typeArguments = concatenate(type.outerTypeParameters, fillMissingTypeArguments(map(node.typeArguments, getTypeFromTypeNode), typeParameters, type.minTypeArgumentCount));
5631+
const typeArguments = concatenate(type.outerTypeParameters, fillMissingTypeArguments(map(node.typeArguments, getTypeFromTypeNode), typeParameters, minTypeArgumentCount));
56355632
return createTypeReference(<GenericType>type, typeArguments);
56365633
}
56375634
if (node.typeArguments) {
@@ -5648,7 +5645,7 @@ namespace ts {
56485645
const id = getTypeListId(typeArguments);
56495646
let instantiation = links.instantiations.get(id);
56505647
if (!instantiation) {
5651-
links.instantiations.set(id, instantiation = instantiateTypeNoAlias(type, createTypeMapper(typeParameters, fillMissingTypeArguments(typeArguments, typeParameters, links.minTypeArgumentCount))));
5648+
links.instantiations.set(id, instantiation = instantiateTypeNoAlias(type, createTypeMapper(typeParameters, fillMissingTypeArguments(typeArguments, typeParameters, getMinTypeArgumentCount(typeParameters)))));
56525649
}
56535650
return instantiation;
56545651
}
@@ -5658,9 +5655,10 @@ namespace ts {
56585655
// declared type. Instantiations are cached using the type identities of the type arguments as the key.
56595656
function getTypeFromTypeAliasReference(node: TypeReferenceNode | ExpressionWithTypeArguments | JSDocTypeReference, symbol: Symbol): Type {
56605657
const type = getDeclaredTypeOfSymbol(symbol);
5661-
const { typeParameters, minTypeArgumentCount } = getSymbolLinks(symbol);
5658+
const typeParameters = getSymbolLinks(symbol).typeParameters;
56625659
if (typeParameters) {
56635660
const numTypeArguments = length(node.typeArguments);
5661+
const minTypeArgumentCount = getMinTypeArgumentCount(typeParameters);
56645662
if (numTypeArguments < minTypeArgumentCount || numTypeArguments > typeParameters.length) {
56655663
error(node,
56665664
minTypeArgumentCount === typeParameters.length
@@ -5897,7 +5895,6 @@ namespace ts {
58975895
type.typeParameters = typeParameters;
58985896
type.outerTypeParameters = undefined;
58995897
type.localTypeParameters = typeParameters;
5900-
type.minTypeArgumentCount = getMinTypeArgumentCount(typeParameters);
59015898
type.instantiations = createMap<TypeReference>();
59025899
type.instantiations.set(getTypeListId(type.typeParameters), <GenericType>type);
59035900
type.target = <GenericType>type;
@@ -6805,7 +6802,7 @@ namespace ts {
68056802
if (signature.typePredicate) {
68066803
freshTypePredicate = cloneTypePredicate(signature.typePredicate, mapper);
68076804
}
6808-
const result = createSignature(signature.declaration, freshTypeParameters, signature.minTypeArgumentCount,
6805+
const result = createSignature(signature.declaration, freshTypeParameters,
68096806
signature.thisParameter && instantiateSymbol(signature.thisParameter, mapper),
68106807
instantiateList(signature.parameters, mapper, instantiateSymbol),
68116808
instantiateType(signature.resolvedReturnType, mapper),
@@ -12937,8 +12934,9 @@ namespace ts {
1293712934
// If the user supplied type arguments, but the number of type arguments does not match
1293812935
// the declared number of type parameters, the call has an incorrect arity.
1293912936
const numTypeParameters = length(signature.typeParameters);
12937+
const minTypeArgumentCount = getMinTypeArgumentCount(signature.typeParameters);
1294012938
const hasRightNumberOfTypeArgs = !typeArguments ||
12941-
(typeArguments.length >= signature.minTypeArgumentCount && typeArguments.length <= numTypeParameters);
12939+
(typeArguments.length >= minTypeArgumentCount && typeArguments.length <= numTypeParameters);
1294212940
if (!hasRightNumberOfTypeArgs) {
1294312941
return false;
1294412942
}
@@ -13637,7 +13635,7 @@ namespace ts {
1363713635
if (candidate.typeParameters) {
1363813636
let typeArgumentTypes: Type[] | undefined;
1363913637
if (typeArguments) {
13640-
typeArgumentTypes = fillMissingTypeArguments(map(typeArguments, getTypeFromTypeNode), candidate.typeParameters, candidate.minTypeArgumentCount);
13638+
typeArgumentTypes = fillMissingTypeArguments(map(typeArguments, getTypeFromTypeNode), candidate.typeParameters, getMinTypeArgumentCount(candidate.typeParameters));
1364113639
typeArgumentsAreValid = checkTypeArguments(candidate, typeArguments, typeArgumentTypes, /*reportErrors*/ false);
1364213640
}
1364313641
else {
@@ -16201,7 +16199,8 @@ namespace ts {
1620116199
checkDecorators(node);
1620216200
}
1620316201

16204-
function checkTypeArgumentConstraints(typeParameters: TypeParameter[], typeArgumentNodes: TypeNode[], minTypeArgumentCount: number): boolean {
16202+
function checkTypeArgumentConstraints(typeParameters: TypeParameter[], typeArgumentNodes: TypeNode[]): boolean {
16203+
const minTypeArgumentCount = getMinTypeArgumentCount(typeParameters);
1620516204
let typeArguments: Type[];
1620616205
let mapper: TypeMapper;
1620716206
let result = true;
@@ -16233,8 +16232,7 @@ namespace ts {
1623316232
if (produceDiagnostics) {
1623416233
const symbol = getNodeLinks(node).resolvedSymbol;
1623516234
const typeParameters = symbol.flags & SymbolFlags.TypeAlias ? getSymbolLinks(symbol).typeParameters : (<TypeReference>type).target.localTypeParameters;
16236-
const minTypeArgumentCount = symbol.flags & SymbolFlags.TypeAlias ? getSymbolLinks(symbol).minTypeArgumentCount : (<TypeReference>type).target.minTypeArgumentCount;
16237-
checkTypeArgumentConstraints(typeParameters, node.typeArguments, minTypeArgumentCount);
16235+
checkTypeArgumentConstraints(typeParameters, node.typeArguments);
1623816236
}
1623916237
}
1624016238
if (type.flags & TypeFlags.Enum && !(<EnumType>type).memberTypes && getNodeLinks(node).resolvedSymbol.flags & SymbolFlags.EnumMember) {
@@ -18482,8 +18480,9 @@ namespace ts {
1848218480
// Resolve the type parameters and minimum type argument count for all declarations
1848318481
resolveTypeParametersOfClassOrInterface(symbol);
1848418482

18485-
const { typeParameters, minTypeArgumentCount } = getSymbolLinks(symbol);
18483+
const typeParameters = getSymbolLinks(symbol).typeParameters;
1848618484
const maxTypeArgumentCount = length(typeParameters);
18485+
const minTypeArgumentCount = getMinTypeArgumentCount(typeParameters);
1848718486
const numTypeParameters = length(node.typeParameters);
1848818487

1848918488
// If this declaration has too few or too many type parameters, we report an error
@@ -18581,7 +18580,6 @@ namespace ts {
1858118580
typeParameters.length = maxTypeArgumentCount;
1858218581
}
1858318582
links.typeParameters = typeParameters || emptyArray;
18584-
links.minTypeArgumentCount = minTypeArgumentCount;
1858518583
}
1858618584
}
1858718585

@@ -18645,7 +18643,7 @@ namespace ts {
1864518643
if (baseTypeNode.typeArguments) {
1864618644
forEach(baseTypeNode.typeArguments, checkSourceElement);
1864718645
for (const constructor of getConstructorsForTypeArguments(staticBaseType, baseTypeNode.typeArguments)) {
18648-
if (!checkTypeArgumentConstraints(constructor.typeParameters, baseTypeNode.typeArguments, constructor.minTypeArgumentCount)) {
18646+
if (!checkTypeArgumentConstraints(constructor.typeParameters, baseTypeNode.typeArguments)) {
1864918647
break;
1865018648
}
1865118649
}

src/compiler/types.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2706,7 +2706,6 @@
27062706
type?: Type; // Type of value symbol
27072707
declaredType?: Type; // Type of class, interface, enum, type alias, or type parameter
27082708
typeParameters?: TypeParameter[]; // Type parameters of type alias (undefined if non-generic)
2709-
minTypeArgumentCount?: number;
27102709
inferredClassType?: Type; // Type of an inferred ES5 class
27112710
instantiations?: Map<Type>; // Instantiations of generic type alias (undefined if non-generic)
27122711
mapper?: TypeMapper; // Type mapper for instantiation alias
@@ -2909,8 +2908,6 @@
29092908
typeParameters: TypeParameter[]; // Type parameters (undefined if non-generic)
29102909
outerTypeParameters: TypeParameter[]; // Outer type parameters (undefined if none)
29112910
localTypeParameters: TypeParameter[]; // Local type parameters (undefined if none)
2912-
/* @internal */
2913-
minTypeArgumentCount: number;
29142911
thisType: TypeParameter; // The "this" type (undefined if none)
29152912
/* @internal */
29162913
resolvedBaseConstructorType?: Type; // Resolved base constructor type of class
@@ -3063,8 +3060,6 @@
30633060
export interface Signature {
30643061
declaration: SignatureDeclaration; // Originating declaration
30653062
typeParameters: TypeParameter[]; // Type parameters (undefined if non-generic)
3066-
/* @internal */
3067-
minTypeArgumentCount: number; // Number of non-optional type parameters
30683063
parameters: Symbol[]; // Parameters
30693064
/* @internal */
30703065
thisParameter?: Symbol; // symbol of this-type parameter

0 commit comments

Comments
 (0)