Skip to content

Commit cdeddf1

Browse files
committed
Call getResolvedSignature only when needed for generics or overloads
1 parent 259ba77 commit cdeddf1

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

src/compiler/checker.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16877,18 +16877,22 @@ namespace ts {
1687716877
}
1687816878
}
1687916879

16880-
function isCallWithEffects(node: CallExpression) {
16880+
function getEffectsSignature(node: CallExpression) {
1688116881
const links = getNodeLinks(node);
16882-
if (links.isCallWithEffects === undefined) {
16882+
let signature = links.effectsSignature;
16883+
if (signature === undefined) {
1688316884
// A call expression parented by an expression statement is a potential assertion. Other call
1688416885
// expressions are potential type predicate function calls.
1688516886
const funcType = node.parent.kind === SyntaxKind.ExpressionStatement ? getTypeOfDottedName(node.expression) :
1688616887
node.expression.kind !== SyntaxKind.SuperKeyword ? checkNonNullExpression(node.expression) :
1688716888
undefined;
16888-
const apparentType = funcType && getApparentType(funcType) || unknownType;
16889-
links.isCallWithEffects = some(getSignaturesOfType(apparentType, SignatureKind.Call), hasTypePredicateOrNeverReturnType);
16889+
const signatures = getSignaturesOfType(funcType && getApparentType(funcType) || unknownType, SignatureKind.Call);
16890+
const candidate = signatures.length === 1 && !signatures[0].typeParameters ? signatures[0] :
16891+
some(signatures, hasTypePredicateOrNeverReturnType) ? getResolvedSignature(node) :
16892+
undefined;
16893+
signature = links.effectsSignature = candidate && hasTypePredicateOrNeverReturnType(candidate) ? candidate : unknownSignature;
1689016894
}
16891-
return links.isCallWithEffects;
16895+
return signature === unknownSignature ? undefined : signature;
1689216896
}
1689316897

1689416898
function hasTypePredicateOrNeverReturnType(signature: Signature) {
@@ -17110,8 +17114,8 @@ namespace ts {
1711017114
}
1711117115

1711217116
function getTypeAtFlowCall(flow: FlowCall): FlowType | undefined {
17113-
if (isCallWithEffects(flow.node)) {
17114-
const signature = getResolvedSignature(flow.node);
17117+
const signature = getEffectsSignature(flow.node);
17118+
if (signature) {
1711517119
const predicate = getTypePredicateOfSignature(signature);
1711617120
if (predicate && predicate.kind === TypePredicateKind.Assertion) {
1711717121
const flowType = getTypeAtFlowNode(flow.antecedent);
@@ -17712,9 +17716,9 @@ namespace ts {
1771217716
}
1771317717

1771417718
function narrowTypeByCallExpression(type: Type, callExpression: CallExpression, assumeTrue: boolean): Type {
17715-
if (hasMatchingArgument(callExpression, reference) && isCallWithEffects(callExpression)) {
17716-
const signature = getResolvedSignature(callExpression);
17717-
const predicate = getTypePredicateOfSignature(signature);
17719+
if (hasMatchingArgument(callExpression, reference)) {
17720+
const signature = getEffectsSignature(callExpression);
17721+
const predicate = signature && getTypePredicateOfSignature(signature);
1771817722
if (predicate && predicate.kind !== TypePredicateKind.Assertion) {
1771917723
return narrowTypeByTypePredicate(type, predicate, callExpression, assumeTrue);
1772017724
}
@@ -23695,7 +23699,8 @@ namespace ts {
2369523699
}
2369623700

2369723701
function isNeverFunctionCall(expr: Expression) {
23698-
return expr.kind === SyntaxKind.CallExpression && isCallWithEffects(<CallExpression>expr) && !!(getTypeOfExpression(expr).flags & TypeFlags.Never);
23702+
const signature = expr.kind === SyntaxKind.CallExpression && getEffectsSignature(<CallExpression>expr);
23703+
return !!(signature && getReturnTypeOfSignature(signature).flags & TypeFlags.Never);
2369923704
}
2370023705

2370123706
function functionHasImplicitReturn(func: FunctionLikeDeclaration) {

src/compiler/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3927,7 +3927,7 @@ namespace ts {
39273927
resolvedSignature?: Signature; // Cached signature of signature node or call expression
39283928
resolvedSymbol?: Symbol; // Cached name resolution result
39293929
resolvedIndexInfo?: IndexInfo; // Cached indexing info resolution result
3930-
isCallWithEffects?: boolean; // Is call expression with possible control flow effects?
3930+
effectsSignature?: Signature; // Signature with possible control flow effects
39313931
enumMemberValue?: string | number; // Constant value of enum member
39323932
isVisible?: boolean; // Is this node visible
39333933
containsArgumentsReference?: boolean; // Whether a function-like declaration contains an 'arguments' reference

0 commit comments

Comments
 (0)