Skip to content

Commit 5c56b4c

Browse files
ahejlsbergmhegazy
authored andcommitted
Optimize signature relationship checks in instantiations of same type
1 parent 03da13c commit 5c56b4c

File tree

1 file changed

+29
-15
lines changed

1 file changed

+29
-15
lines changed

src/compiler/checker.ts

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9204,25 +9204,39 @@ namespace ts {
92049204
let result = Ternary.True;
92059205
const saveErrorInfo = errorInfo;
92069206

9207-
outer: for (const t of targetSignatures) {
9208-
// Only elaborate errors from the first failure
9209-
let shouldElaborateErrors = reportErrors;
9210-
for (const s of sourceSignatures) {
9211-
const related = signatureRelatedTo(s, t, shouldElaborateErrors);
9212-
if (related) {
9213-
result &= related;
9214-
errorInfo = saveErrorInfo;
9215-
continue outer;
9207+
if (getObjectFlags(source) & ObjectFlags.Instantiated && getObjectFlags(target) & ObjectFlags.Instantiated && source.symbol === target.symbol) {
9208+
// We instantiations of the same anonymous type (which typically will be the type of a method).
9209+
// Simply do a pairwise comparison of the signatures in the two signature lists instead of the
9210+
// much more expensive N * M comparison matrix we explore below.
9211+
for (let i = 0; i < targetSignatures.length; i++) {
9212+
const related = signatureRelatedTo(sourceSignatures[i], targetSignatures[i], reportErrors);
9213+
if (!related) {
9214+
return Ternary.False;
92169215
}
9217-
shouldElaborateErrors = false;
9216+
result &= related;
92189217
}
9218+
}
9219+
else {
9220+
outer: for (const t of targetSignatures) {
9221+
// Only elaborate errors from the first failure
9222+
let shouldElaborateErrors = reportErrors;
9223+
for (const s of sourceSignatures) {
9224+
const related = signatureRelatedTo(s, t, shouldElaborateErrors);
9225+
if (related) {
9226+
result &= related;
9227+
errorInfo = saveErrorInfo;
9228+
continue outer;
9229+
}
9230+
shouldElaborateErrors = false;
9231+
}
92199232

9220-
if (shouldElaborateErrors) {
9221-
reportError(Diagnostics.Type_0_provides_no_match_for_the_signature_1,
9222-
typeToString(source),
9223-
signatureToString(t, /*enclosingDeclaration*/ undefined, /*flags*/ undefined, kind));
9233+
if (shouldElaborateErrors) {
9234+
reportError(Diagnostics.Type_0_provides_no_match_for_the_signature_1,
9235+
typeToString(source),
9236+
signatureToString(t, /*enclosingDeclaration*/ undefined, /*flags*/ undefined, kind));
9237+
}
9238+
return Ternary.False;
92249239
}
9225-
return Ternary.False;
92269240
}
92279241
return result;
92289242
}

0 commit comments

Comments
 (0)