Skip to content
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

Improve caching of anonymous types #18231

Merged
merged 5 commits into from
Sep 5, 2017
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
295 changes: 119 additions & 176 deletions src/compiler/checker.ts

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3331,13 +3331,12 @@ namespace ts {
}

/* @internal */
export interface MappedType extends ObjectType {
export interface MappedType extends AnonymousType {
declaration: MappedTypeNode;
typeParameter?: TypeParameter;
constraintType?: Type;
templateType?: Type;
modifiersType?: Type;
mapper?: TypeMapper; // Instantiation mapper
}

export interface EvolvingArrayType extends ObjectType {
Expand Down Expand Up @@ -3469,8 +3468,6 @@ namespace ts {
/* @internal */
export interface TypeMapper {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with this change, it would now be easier to read as type TypeMapper = (t: TypeParameter) => Type;

(t: TypeParameter): Type;
mappedTypes?: TypeParameter[]; // Types mapped by this mapper
instantiations?: Type[]; // Cache of instantiations created using this type mapper.
}

export const enum InferencePriority {
Expand Down
3 changes: 1 addition & 2 deletions src/services/signatureHelp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,7 @@ namespace ts.SignatureHelp {
if (isTypeParameterList) {
isVariadic = false; // type parameter lists are not variadic
prefixDisplayParts.push(punctuationPart(SyntaxKind.LessThanToken));
// Use `.mapper` to ensure we get the generic type arguments even if this is an instantiated version of the signature.
const typeParameters = candidateSignature.mapper ? candidateSignature.mapper.mappedTypes : candidateSignature.typeParameters;
const typeParameters = (candidateSignature.target || candidateSignature).typeParameters;
signatureHelpParameters = typeParameters && typeParameters.length > 0 ? map(typeParameters, createSignatureHelpParameterForTypeParameter) : emptyArray;
suffixDisplayParts.push(punctuationPart(SyntaxKind.GreaterThanToken));
const parameterParts = mapToDisplayParts(writer =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/functionConstrain
Type 'void' is not assignable to type 'string'.
tests/cases/conformance/types/typeParameters/typeArgumentLists/functionConstraintSatisfaction2.ts(38,10): error TS2345: Argument of type 'U' is not assignable to parameter of type '(x: string) => string'.
Type 'T' is not assignable to type '(x: string) => string'.
Type '() => void' is not assignable to type '(x: string) => string'.
Type 'void' is not assignable to type 'string'.


==== tests/cases/conformance/types/typeParameters/typeArgumentLists/functionConstraintSatisfaction2.ts (13 errors) ====
Expand Down Expand Up @@ -102,7 +100,5 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/functionConstrain
~
!!! error TS2345: Argument of type 'U' is not assignable to parameter of type '(x: string) => string'.
!!! error TS2345: Type 'T' is not assignable to type '(x: string) => string'.
!!! error TS2345: Type '() => void' is not assignable to type '(x: string) => string'.
!!! error TS2345: Type 'void' is not assignable to type 'string'.
}

4 changes: 2 additions & 2 deletions tests/baselines/reference/limitDeepInstantiations.errors.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tests/cases/compiler/limitDeepInstantiations.ts(3,35): error TS2550: Generic type instantiation is excessively deep and possibly infinite.
tests/cases/compiler/limitDeepInstantiations.ts(3,35): error TS2502: '"true"' is referenced directly or indirectly in its own type annotation.
tests/cases/compiler/limitDeepInstantiations.ts(5,13): error TS2344: Type '"false"' does not satisfy the constraint '"true"'.


Expand All @@ -7,7 +7,7 @@ tests/cases/compiler/limitDeepInstantiations.ts(5,13): error TS2344: Type '"fals

type Foo<T extends "true", B> = { "true": Foo<T, Foo<T, B>> }[T];
~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2550: Generic type instantiation is excessively deep and possibly infinite.
!!! error TS2502: '"true"' is referenced directly or indirectly in its own type annotation.
let f1: Foo<"true", {}>;
let f2: Foo<"false", {}>;
~~~~~~~
Expand Down
2 changes: 0 additions & 2 deletions tests/baselines/reference/promisePermutations.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ tests/cases/compiler/promisePermutations.ts(134,19): error TS2345: Argument of t
tests/cases/compiler/promisePermutations.ts(137,33): error TS2345: Argument of type '(x: any) => IPromise<string>' is not assignable to parameter of type '(error: any) => IPromise<number>'.
Type 'IPromise<string>' is not assignable to type 'IPromise<number>'.
tests/cases/compiler/promisePermutations.ts(144,35): error TS2345: Argument of type '(x: any) => IPromise<string>' is not assignable to parameter of type '(error: any) => IPromise<number>'.
Type 'IPromise<string>' is not assignable to type 'IPromise<number>'.
tests/cases/compiler/promisePermutations.ts(152,36): error TS2345: Argument of type '(x: any) => IPromise<string>' is not assignable to parameter of type '(error: any) => Promise<number>'.
Type 'IPromise<string>' is not assignable to type 'Promise<number>'.
Types of property 'then' are incompatible.
Expand Down Expand Up @@ -290,7 +289,6 @@ tests/cases/compiler/promisePermutations.ts(160,21): error TS2345: Argument of t
var r10d = r10.then(testFunction, sIPromise, nIPromise); // ok
~~~~~~~~~
!!! error TS2345: Argument of type '(x: any) => IPromise<string>' is not assignable to parameter of type '(error: any) => IPromise<number>'.
!!! error TS2345: Type 'IPromise<string>' is not assignable to type 'IPromise<number>'.
var r10e = r10.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok
var s10 = testFunction10P(x => x);
var s10a = s10.then(testFunction10, testFunction10, testFunction10); // ok
Expand Down
2 changes: 0 additions & 2 deletions tests/baselines/reference/promisePermutations2.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ tests/cases/compiler/promisePermutations2.ts(133,19): error TS2345: Argument of
tests/cases/compiler/promisePermutations2.ts(136,33): error TS2345: Argument of type '(x: any) => IPromise<string>' is not assignable to parameter of type '(error: any) => IPromise<number>'.
Type 'IPromise<string>' is not assignable to type 'IPromise<number>'.
tests/cases/compiler/promisePermutations2.ts(143,35): error TS2345: Argument of type '(x: any) => IPromise<string>' is not assignable to parameter of type '(error: any) => IPromise<number>'.
Type 'IPromise<string>' is not assignable to type 'IPromise<number>'.
tests/cases/compiler/promisePermutations2.ts(151,36): error TS2345: Argument of type '(x: any) => IPromise<string>' is not assignable to parameter of type '(error: any) => Promise<number>'.
Type 'IPromise<string>' is not assignable to type 'Promise<number>'.
Types of property 'then' are incompatible.
Expand Down Expand Up @@ -289,7 +288,6 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of
var r10d = r10.then(testFunction, sIPromise, nIPromise); // error
~~~~~~~~~
!!! error TS2345: Argument of type '(x: any) => IPromise<string>' is not assignable to parameter of type '(error: any) => IPromise<number>'.
!!! error TS2345: Type 'IPromise<string>' is not assignable to type 'IPromise<number>'.
var r10e = r10.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok
var s10 = testFunction10P(x => x);
var s10a = s10.then(testFunction10, testFunction10, testFunction10); // ok
Expand Down
2 changes: 0 additions & 2 deletions tests/baselines/reference/promisePermutations3.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ tests/cases/compiler/promisePermutations3.ts(133,19): error TS2345: Argument of
tests/cases/compiler/promisePermutations3.ts(136,33): error TS2345: Argument of type '(x: any) => IPromise<string>' is not assignable to parameter of type '(error: any) => IPromise<number>'.
Type 'IPromise<string>' is not assignable to type 'IPromise<number>'.
tests/cases/compiler/promisePermutations3.ts(143,35): error TS2345: Argument of type '(x: any) => IPromise<string>' is not assignable to parameter of type '(error: any) => IPromise<number>'.
Type 'IPromise<string>' is not assignable to type 'IPromise<number>'.
tests/cases/compiler/promisePermutations3.ts(151,36): error TS2345: Argument of type '(x: any) => IPromise<string>' is not assignable to parameter of type '(error: any) => Promise<number>'.
Type 'IPromise<string>' is not assignable to type 'Promise<number>'.
Types of property 'then' are incompatible.
Expand Down Expand Up @@ -301,7 +300,6 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of
var r10d = r10.then(testFunction, sIPromise, nIPromise); // error
~~~~~~~~~
!!! error TS2345: Argument of type '(x: any) => IPromise<string>' is not assignable to parameter of type '(error: any) => IPromise<number>'.
!!! error TS2345: Type 'IPromise<string>' is not assignable to type 'IPromise<number>'.
var r10e = r10.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok
var s10 = testFunction10P(x => x);
var s10a = s10.then(testFunction10, testFunction10, testFunction10); // ok
Expand Down