Skip to content

Commit 41b9f74

Browse files
authored
Merge pull request #15519 from Microsoft/optimizeSignatureRelations
Optimize signature relationship checks
2 parents 14f6bf2 + 3f95b86 commit 41b9f74

File tree

1 file changed

+29
-15
lines changed

1 file changed

+29
-15
lines changed

src/compiler/checker.ts

+29-15
Original file line numberDiff line numberDiff line change
@@ -9228,25 +9228,39 @@ namespace ts {
92289228
let result = Ternary.True;
92299229
const saveErrorInfo = errorInfo;
92309230

9231-
outer: for (const t of targetSignatures) {
9232-
// Only elaborate errors from the first failure
9233-
let shouldElaborateErrors = reportErrors;
9234-
for (const s of sourceSignatures) {
9235-
const related = signatureRelatedTo(s, t, shouldElaborateErrors);
9236-
if (related) {
9237-
result &= related;
9238-
errorInfo = saveErrorInfo;
9239-
continue outer;
9231+
if (getObjectFlags(source) & ObjectFlags.Instantiated && getObjectFlags(target) & ObjectFlags.Instantiated && source.symbol === target.symbol) {
9232+
// We instantiations of the same anonymous type (which typically will be the type of a method).
9233+
// Simply do a pairwise comparison of the signatures in the two signature lists instead of the
9234+
// much more expensive N * M comparison matrix we explore below.
9235+
for (let i = 0; i < targetSignatures.length; i++) {
9236+
const related = signatureRelatedTo(sourceSignatures[i], targetSignatures[i], reportErrors);
9237+
if (!related) {
9238+
return Ternary.False;
92409239
}
9241-
shouldElaborateErrors = false;
9240+
result &= related;
92429241
}
9242+
}
9243+
else {
9244+
outer: for (const t of targetSignatures) {
9245+
// Only elaborate errors from the first failure
9246+
let shouldElaborateErrors = reportErrors;
9247+
for (const s of sourceSignatures) {
9248+
const related = signatureRelatedTo(s, t, shouldElaborateErrors);
9249+
if (related) {
9250+
result &= related;
9251+
errorInfo = saveErrorInfo;
9252+
continue outer;
9253+
}
9254+
shouldElaborateErrors = false;
9255+
}
92439256

9244-
if (shouldElaborateErrors) {
9245-
reportError(Diagnostics.Type_0_provides_no_match_for_the_signature_1,
9246-
typeToString(source),
9247-
signatureToString(t, /*enclosingDeclaration*/ undefined, /*flags*/ undefined, kind));
9257+
if (shouldElaborateErrors) {
9258+
reportError(Diagnostics.Type_0_provides_no_match_for_the_signature_1,
9259+
typeToString(source),
9260+
signatureToString(t, /*enclosingDeclaration*/ undefined, /*flags*/ undefined, kind));
9261+
}
9262+
return Ternary.False;
92489263
}
9249-
return Ternary.False;
92509264
}
92519265
return result;
92529266
}

0 commit comments

Comments
 (0)