Shared caching for identical function types in relationship checking

This commit is contained in:
Anders Hejlsberg
2019-09-29 16:13:24 -07:00
parent 20e2be1e1a
commit 58dc1e85c4

View File

@@ -16092,6 +16092,21 @@ namespace ts {
return result;
}
function isSimpleFunctionType(type: Type) {
const signature = getSingleCallSignature(type);
return signature && signature.parameters.length <= 2 && !signature.thisParameter &&
!signature.hasRestParameter && !getTypePredicateOfSignature(signature);
}
function getFunctionTypeId(type: ResolvedType): string {
const signature = type.callSignatures[0];
let result = "" + signature.minArgumentCount;
for (const p of signature.parameters) {
result += "@" + getTypeOfSymbol(p).id + p.escapedName;
}
return result + ":" + getReturnTypeOfSignature(signature).id;
}
/**
* To improve caching, the relation key for two generic types uses the target's id plus ids of the type parameters.
* For other cases, the types ids are used.
@@ -16106,6 +16121,9 @@ namespace ts {
const typeParameters: Type[] = [];
return getTypeReferenceId(<TypeReference>source, typeParameters) + "," + getTypeReferenceId(<TypeReference>target, typeParameters);
}
if (isSimpleFunctionType(source) && isSimpleFunctionType(target)) {
return getFunctionTypeId(<ResolvedType>source) + "," + getFunctionTypeId(<ResolvedType>target);
}
return source.id + "," + target.id;
}