Skip to content

Bail when comparing a specialized form of an already ongoing comparison #42727

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17699,9 +17699,16 @@ namespace ts {
targetStack = [];
}
else {
// generate a key where all type parameter id positions are replaced with unconstrained type parameter ids
// this isn't perfect - nested type references passed as type arguments will muck up the indexes and thus
// prevent finding matches- but it should hit up the common cases
const broadestEquivalentId = id.split(",").map(i => i.replace(/-\d+/g, (_match, offset: number) => {
const index = length(id.slice(0, offset).match(/[-=]/g) || undefined);
return `=${index}`;
})).join(",");
for (let i = 0; i < maybeCount; i++) {
// If source and target are already being compared, consider them related with assumptions
if (id === maybeKeys[i]) {
if (id === maybeKeys[i] || broadestEquivalentId === maybeKeys[i]) {
return Ternary.Maybe;
}
}
Expand Down Expand Up @@ -19141,7 +19148,7 @@ namespace ts {
}

function isTypeReferenceWithGenericArguments(type: Type): boolean {
return isNonDeferredTypeReference(type) && some(getTypeArguments(type), t => isUnconstrainedTypeParameter(t) || isTypeReferenceWithGenericArguments(t));
return isNonDeferredTypeReference(type) && some(getTypeArguments(type), t => !!(t.flags & TypeFlags.TypeParameter) || isTypeReferenceWithGenericArguments(t));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
//// [performanceComparisonOfStructurallyIdenticalInterfacesWithGenericSignatures.ts]
export declare type ThenArg<T> = T extends any ? any : T extends PromiseLike<infer U> ? U : T;

export interface InterfaceA<T> {
filter(callback: (newValue: T, oldValue: T) => boolean): InterfaceA<T>;
map<D>(callback: (value: T) => D): InterfaceA<D>;
await<R extends ThenArg<T>>(): InterfaceA<R>;
awaitLatest<R extends ThenArg<T>>(): InterfaceA<R>;
awaitOrdered<R extends ThenArg<T>>(): InterfaceA<R>;
awaitOrdered2<R extends ThenArg<T>>(): InterfaceA<R>;
awaitOrdered3<R extends ThenArg<T>>(): InterfaceA<R>;
awaitOrdered4<R extends ThenArg<T>>(): InterfaceA<R>;
awaitOrdered5<R extends ThenArg<T>>(): InterfaceA<R>;
awaitOrdered6<R extends ThenArg<T>>(): InterfaceA<R>;
awaitOrdered7<R extends ThenArg<T>>(): InterfaceA<R>;
awaitOrdered8<R extends ThenArg<T>>(): InterfaceA<R>;
awaitOrdered9<R extends ThenArg<T>>(): InterfaceA<R>;
}

export interface InterfaceB<T> extends InterfaceA<T> {
map<D>(callback: (value: T) => D): InterfaceB<D>;
await<R extends ThenArg<T>>(): InterfaceB<R>;
awaitLatest<R extends ThenArg<T>>(): InterfaceB<R>;
awaitOrdered<R extends ThenArg<T>>(): InterfaceB<R>;
awaitOrdered2<R extends ThenArg<T>>(): InterfaceB<R>;
awaitOrdered3<R extends ThenArg<T>>(): InterfaceB<R>;
awaitOrdered4<R extends ThenArg<T>>(): InterfaceB<R>;
awaitOrdered5<R extends ThenArg<T>>(): InterfaceB<R>;
awaitOrdered6<R extends ThenArg<T>>(): InterfaceB<R>;
awaitOrdered7<R extends ThenArg<T>>(): InterfaceB<R>;
awaitOrdered8<R extends ThenArg<T>>(): InterfaceB<R>;
awaitOrdered9<R extends ThenArg<T>>(): InterfaceB<R>;
}

export class A<T> implements InterfaceB<T> {
public filter(callback: (newValue: T, oldValue: T) => boolean): B<T> {
return undefined as any;
}

public map<D>(callback: (value: T) => D): B<D> {
return undefined as any;
}

public await<R extends ThenArg<T>>(): B<R> {
return undefined as any;
}

public awaitOrdered<R extends ThenArg<T>>(): B<R> {
return undefined as any;
}

public awaitOrdered2<R extends ThenArg<T>>(): B<R> {
return undefined as any;
}

public awaitOrdered3<R extends ThenArg<T>>(): B<R> {
return undefined as any;
}

public awaitOrdered4<R extends ThenArg<T>>(): B<R> {
return undefined as any;
}

public awaitOrdered5<R extends ThenArg<T>>(): B<R> {
return undefined as any;
}

public awaitOrdered6<R extends ThenArg<T>>(): B<R> {
return undefined as any;
}

public awaitOrdered7<R extends ThenArg<T>>(): B<R> {
return undefined as any;
}

public awaitOrdered8<R extends ThenArg<T>>(): B<R> {
return undefined as any;
}

public awaitOrdered9<R extends ThenArg<T>>(): B<R> {
return undefined as any;
}

public awaitLatest<R extends ThenArg<T>>(): B<R> {
return undefined as any;
}
}

export class B<T> extends A<T> { }

//// [performanceComparisonOfStructurallyIdenticalInterfacesWithGenericSignatures.js]
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
exports.__esModule = true;
exports.B = exports.A = void 0;
var A = /** @class */ (function () {
function A() {
}
A.prototype.filter = function (callback) {
return undefined;
};
A.prototype.map = function (callback) {
return undefined;
};
A.prototype.await = function () {
return undefined;
};
A.prototype.awaitOrdered = function () {
return undefined;
};
A.prototype.awaitOrdered2 = function () {
return undefined;
};
A.prototype.awaitOrdered3 = function () {
return undefined;
};
A.prototype.awaitOrdered4 = function () {
return undefined;
};
A.prototype.awaitOrdered5 = function () {
return undefined;
};
A.prototype.awaitOrdered6 = function () {
return undefined;
};
A.prototype.awaitOrdered7 = function () {
return undefined;
};
A.prototype.awaitOrdered8 = function () {
return undefined;
};
A.prototype.awaitOrdered9 = function () {
return undefined;
};
A.prototype.awaitLatest = function () {
return undefined;
};
return A;
}());
exports.A = A;
var B = /** @class */ (function (_super) {
__extends(B, _super);
function B() {
return _super !== null && _super.apply(this, arguments) || this;
}
return B;
}(A));
exports.B = B;
Loading