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

Make Signature monomorphic #59192

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
93 changes: 87 additions & 6 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ import {
TypeElement,
TypeFlags,
TypeLiteralNode,
TypeMapper,
TypeNode,
TypeNodeSyntaxKind,
TypeParameter,
Expand Down Expand Up @@ -8209,11 +8210,91 @@ function Type(this: Type, checker: TypeChecker, flags: TypeFlags) {
}
}

function Signature(this: Signature, checker: TypeChecker, flags: SignatureFlags) {
// Note: if modifying this, be sure to update SignatureObject in src/services/services.ts
this.flags = flags;
if (Debug.isDebugging) {
this.checker = checker;
class SignatureDataImpl {
}
/** @internal */
export class SignatureImpl {
flags: SignatureFlags;
checker!: TypeChecker;
declaration?: SignatureDeclaration | JSDocSignature; // Originating declaration
typeParameters?: readonly TypeParameter[]; // Type parameters (undefined if non-generic)
parameters: readonly Symbol[]; // Parameters
thisParameter?: Symbol; // symbol of this-type parameter
resolvedReturnType?: Type; // Lazily set by `getReturnTypeOfSignature`.
resolvedTypePredicate?: TypePredicate;
minArgumentCount: number; // Number of non-optional parameters
resolvedMinArgumentCount?: number; // Number of non-optional parameters (excluding trailing `void`)
target?: Signature; // Instantiation target
mapper?: TypeMapper; // Instantiation mapper
compositeSignatures?: Signature[]; // Underlying signatures of a union/intersection signature
compositeKind?: TypeFlags; // TypeFlags.Union if the underlying signatures are from union members, otherwise TypeFlags.Intersection

constructor(checker: TypeChecker, flags: SignatureFlags) {
// Note: if modifying this, be sure to update SignatureObject in src/services/services.ts
this.flags = flags;
if (Debug.isDebugging) {
this.checker = checker;
}
this.declaration = undefined;
this.typeParameters = undefined;
this.parameters = undefined!;
this.thisParameter = undefined;
this.resolvedReturnType = undefined;
this.resolvedTypePredicate = undefined;
this.minArgumentCount = undefined!;
this.resolvedMinArgumentCount = undefined;
this.target = undefined;
this.mapper = undefined;
this.compositeSignatures = undefined;
this.compositeKind = undefined;
this._data = undefined;
}
// get data(): any { return this; }
_data: any;
get data() {
return this._data ??= new SignatureDataImpl();
}
get erasedSignatureCache() {
return this.data.erasedSignatureCache;
}
set erasedSignatureCache(value: any) {
this.data.erasedSignatureCache = value;
}
get canonicalSignatureCache() {
return this.data.canonicalSignatureCache;
}
set canonicalSignatureCache(value: any) {
this.data.canonicalSignatureCache = value;
}
get baseSignatureCache() {
return this.data.baseSignatureCache;
}
set baseSignatureCache(value: any) {
this.data.baseSignatureCache = value;
}
get optionalCallSignatureCache() {
return this.data.optionalCallSignatureCache;
}
set optionalCallSignatureCache(value: any) {
this.data.optionalCallSignatureCache = value;
}
get isolatedSignatureType() {
return this.data.isolatedSignatureType;
}
set isolatedSignatureType(value: any) {
this.data.isolatedSignatureType = value;
}
get instantiations() {
return this.data.instantiations;
}
set instantiations(value: any) {
this.data.instantiations = value;
}
get implementationSignatureCache() {
return this.data.implementationSignatureCache;
}
set implementationSignatureCache(value: any) {
this.data.implementationSignatureCache = value;
}
}

Expand Down Expand Up @@ -8272,7 +8353,7 @@ export const objectAllocator: ObjectAllocator = {
getSourceFileConstructor: () => Node as any,
getSymbolConstructor: () => Symbol as any,
getTypeConstructor: () => Type as any,
getSignatureConstructor: () => Signature as any,
getSignatureConstructor: () => SignatureImpl as any,
getSourceMapSourceConstructor: () => SourceMapSource as any,
};

Expand Down
34 changes: 8 additions & 26 deletions src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ import {
SignatureHelp,
SignatureHelpItems,
SignatureHelpItemsOptions,
SignatureImpl,
SignatureKind,
singleElementArray,
skipTypeChecking,
Expand Down Expand Up @@ -337,7 +338,6 @@ import {
TypeFlags,
TypeNode,
TypeParameter,
TypePredicate,
TypeReference,
typeToDisplayParts,
UnionOrIntersectionType,
Expand Down Expand Up @@ -927,37 +927,19 @@ class TypeObject implements Type {
}
}

class SignatureObject implements Signature {
flags: SignatureFlags;
checker: TypeChecker;
declaration!: SignatureDeclaration;
typeParameters?: TypeParameter[];
parameters!: Symbol[];
thisParameter!: Symbol;
resolvedReturnType!: Type;
resolvedTypePredicate: TypePredicate | undefined;
minTypeArgumentCount!: number;
minArgumentCount!: number;

// Undefined is used to indicate the value has not been computed. If, after computing, the
// symbol has no doc comment, then the empty array will be returned.
documentationComment?: SymbolDisplayPart[];
jsDocTags?: JSDocTagInfo[]; // same

class SignatureObject extends SignatureImpl implements Signature {
constructor(checker: TypeChecker, flags: SignatureFlags) {
// Note: if modifying this, be sure to update Signature in src/compiler/types.ts
this.flags = flags;
super(checker, flags);
this.checker = checker;
}

getDeclaration(): SignatureDeclaration {
return this.declaration;
return this.declaration as SignatureDeclaration;
}
getTypeParameters(): TypeParameter[] | undefined {
return this.typeParameters;
return this.typeParameters as TypeParameter[];
}
getParameters(): Symbol[] {
return this.parameters;
return this.parameters as Symbol[];
}
getReturnType(): Type {
return this.checker.getReturnTypeOfSignature(this);
Expand All @@ -974,11 +956,11 @@ class SignatureObject implements Signature {
}

getDocumentationComment(): SymbolDisplayPart[] {
return this.documentationComment || (this.documentationComment = getDocumentationComment(singleElementArray(this.declaration), this.checker));
return this.data.documentationComment || (this.data.documentationComment = getDocumentationComment(singleElementArray(this.declaration), this.checker));
}

getJsDocTags(): JSDocTagInfo[] {
return this.jsDocTags || (this.jsDocTags = getJsDocTagsOfDeclarations(singleElementArray(this.declaration), this.checker));
return this.data.jsDocTags || (this.data.jsDocTags = getJsDocTagsOfDeclarations(singleElementArray(this.declaration), this.checker));
}
}

Expand Down