From aa3df25f4ef4d58501d1d7c8988f60a9b9cb259e Mon Sep 17 00:00:00 2001 From: Andrew Casey Date: Wed, 24 Feb 2021 16:38:10 -0800 Subject: [PATCH 1/8] Tracing: dump more info about substitution types --- src/compiler/tracing.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/compiler/tracing.ts b/src/compiler/tracing.ts index 2894e2a8bf72c..7c8d5221e89e3 100644 --- a/src/compiler/tracing.ts +++ b/src/compiler/tracing.ts @@ -228,6 +228,15 @@ namespace ts { // eslint-disable-line one-namespace-per-file }; } + let substitutionProperties: object = {}; + if (type.flags & TypeFlags.Substitution) { + const substitutionType = type as SubstitutionType; + substitutionProperties = { + substitutionBaseType: substitutionType.baseType?.id, + substituteType: substitutionType.substitute?.id, + }; + } + // We can't print out an arbitrary object, so just assign each one a unique number. // Don't call it an "id" so people don't treat it as a type id. let recursionToken: number | undefined; @@ -252,6 +261,7 @@ namespace ts { // eslint-disable-line one-namespace-per-file ...indexedAccessProperties, ...referenceProperties, ...conditionalProperties, + ...substitutionProperties, firstDeclaration: firstDeclaration && { path: firstFile.path, start: indexFromOne(getLineAndCharacterOfPosition(firstFile, firstDeclaration.pos)), From d212a742ab0ad54b03cb5a21af2ef2b9b405ab03 Mon Sep 17 00:00:00 2001 From: Andrew Casey Date: Wed, 24 Feb 2021 17:28:07 -0800 Subject: [PATCH 2/8] Tracing: dump more info about reverse-mapped types --- src/compiler/tracing.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/compiler/tracing.ts b/src/compiler/tracing.ts index 7c8d5221e89e3..f5a90f860587c 100644 --- a/src/compiler/tracing.ts +++ b/src/compiler/tracing.ts @@ -237,6 +237,16 @@ namespace ts { // eslint-disable-line one-namespace-per-file }; } + let reverseMappedProperties: object = {}; + if (objectFlags & ObjectFlags.ReverseMapped) { + const reverseMappedType = type as ReverseMappedType; + reverseMappedProperties = { + reverseMappedSourceType: reverseMappedType.source?.id, + reverseMappedMappedType: reverseMappedType.mappedType?.id, + reverseMappedConstraintType: reverseMappedType.constraintType?.id, + }; + } + // We can't print out an arbitrary object, so just assign each one a unique number. // Don't call it an "id" so people don't treat it as a type id. let recursionToken: number | undefined; @@ -262,6 +272,7 @@ namespace ts { // eslint-disable-line one-namespace-per-file ...referenceProperties, ...conditionalProperties, ...substitutionProperties, + ...reverseMappedProperties, firstDeclaration: firstDeclaration && { path: firstFile.path, start: indexFromOne(getLineAndCharacterOfPosition(firstFile, firstDeclaration.pos)), From 279125e7d42b60f83abc617736400b37f07c2c21 Mon Sep 17 00:00:00 2001 From: Andrew Casey Date: Thu, 25 Feb 2021 10:06:02 -0800 Subject: [PATCH 3/8] Tracing: dump more info about destructuring types --- src/compiler/tracing.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/compiler/tracing.ts b/src/compiler/tracing.ts index f5a90f860587c..add8d5fd5c805 100644 --- a/src/compiler/tracing.ts +++ b/src/compiler/tracing.ts @@ -187,6 +187,8 @@ namespace ts { // eslint-disable-line one-namespace-per-file const symbol = type.aliasSymbol ?? type.symbol; const firstDeclaration = symbol?.declarations?.[0]; const firstFile = firstDeclaration && getSourceFileOfNode(firstDeclaration); + const destructuringPattern = type.pattern; + const destructuringPatternFile = destructuringPattern && getSourceFileOfNode(destructuringPattern); // It's slow to compute the display text, so skip it unless it's really valuable (or cheap) let display: string | undefined; @@ -273,10 +275,15 @@ namespace ts { // eslint-disable-line one-namespace-per-file ...conditionalProperties, ...substitutionProperties, ...reverseMappedProperties, - firstDeclaration: firstDeclaration && { + destructuringPattern: destructuringPatternFile && { + path: destructuringPatternFile.path, + start: indexFromOne(getLineAndCharacterOfPosition(destructuringPatternFile, destructuringPattern!.pos)), + end: indexFromOne(getLineAndCharacterOfPosition(destructuringPatternFile, destructuringPattern!.end)), + }, + firstDeclaration: firstFile && { path: firstFile.path, start: indexFromOne(getLineAndCharacterOfPosition(firstFile, firstDeclaration.pos)), - end: indexFromOne(getLineAndCharacterOfPosition(getSourceFileOfNode(firstDeclaration), firstDeclaration.end)), + end: indexFromOne(getLineAndCharacterOfPosition(firstFile, firstDeclaration.end)), }, flags: Debug.formatTypeFlags(type.flags).split("|"), display, From afa382f66645e22912459fc35020a63e32af11ae Mon Sep 17 00:00:00 2001 From: Andrew Casey Date: Thu, 25 Feb 2021 10:34:02 -0800 Subject: [PATCH 4/8] Tracing: dump more info about evolving-array types --- src/compiler/tracing.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/compiler/tracing.ts b/src/compiler/tracing.ts index add8d5fd5c805..d20a18befcb44 100644 --- a/src/compiler/tracing.ts +++ b/src/compiler/tracing.ts @@ -249,6 +249,15 @@ namespace ts { // eslint-disable-line one-namespace-per-file }; } + let evolvingArrayProperties: object = {}; + if (objectFlags & ObjectFlags.EvolvingArray) { + const evolvingArrayType = type as EvolvingArrayType; + evolvingArrayProperties = { + evolvingArrayElementType: evolvingArrayType.elementType.id, + evolvingArrayFinalType: evolvingArrayType.finalArrayType?.id, + }; + } + // We can't print out an arbitrary object, so just assign each one a unique number. // Don't call it an "id" so people don't treat it as a type id. let recursionToken: number | undefined; @@ -275,6 +284,7 @@ namespace ts { // eslint-disable-line one-namespace-per-file ...conditionalProperties, ...substitutionProperties, ...reverseMappedProperties, + ...evolvingArrayProperties, destructuringPattern: destructuringPatternFile && { path: destructuringPatternFile.path, start: indexFromOne(getLineAndCharacterOfPosition(destructuringPatternFile, destructuringPattern!.pos)), From 18c36609a3ebfae3ac3503ad6c15e6ef541ec651 Mon Sep 17 00:00:00 2001 From: Andrew Casey Date: Thu, 25 Feb 2021 10:51:06 -0800 Subject: [PATCH 5/8] Tracing: dump more info about tuple types --- src/compiler/tracing.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/compiler/tracing.ts b/src/compiler/tracing.ts index d20a18befcb44..d0ba55a8a6863 100644 --- a/src/compiler/tracing.ts +++ b/src/compiler/tracing.ts @@ -275,6 +275,7 @@ namespace ts { // eslint-disable-line one-namespace-per-file intrinsicName: (type as any).intrinsicName, symbolName: symbol?.escapedName && unescapeLeadingUnderscores(symbol.escapedName), recursionId: recursionToken, + isTuple: objectFlags & ObjectFlags.Tuple ? true : undefined, unionTypes: (type.flags & TypeFlags.Union) ? (type as UnionType).types?.map(t => t.id) : undefined, intersectionTypes: (type.flags & TypeFlags.Intersection) ? (type as IntersectionType).types.map(t => t.id) : undefined, aliasTypeArguments: type.aliasTypeArguments?.map(t => t.id), From d29bbfc57d0ded9e45070b3c134ee438f1e35b1b Mon Sep 17 00:00:00 2001 From: Andrew Casey Date: Thu, 25 Feb 2021 12:36:31 -0800 Subject: [PATCH 6/8] Tracing: dump more info about type references --- src/compiler/tracing.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/compiler/tracing.ts b/src/compiler/tracing.ts index d0ba55a8a6863..68d6bdb503f05 100644 --- a/src/compiler/tracing.ts +++ b/src/compiler/tracing.ts @@ -217,6 +217,15 @@ namespace ts { // eslint-disable-line one-namespace-per-file instantiatedType: referenceType.target?.id, typeArguments: referenceType.resolvedTypeArguments?.map(t => t.id), }; + const referenceNode = referenceType.node; + if (referenceNode) { + const sourceFile = getSourceFileOfNode(referenceNode); + (referenceProperties as any).referenceLocation = { + path: sourceFile.path, + start: indexFromOne(getLineAndCharacterOfPosition(sourceFile, referenceNode.pos)), + end: indexFromOne(getLineAndCharacterOfPosition(sourceFile, referenceNode.end)), + } + } } let conditionalProperties: object = {}; From 4d316a6063daf3a11275603b9634e11bf3b67ffe Mon Sep 17 00:00:00 2001 From: Andrew Casey Date: Thu, 25 Feb 2021 13:47:35 -0800 Subject: [PATCH 7/8] Fix lint errors --- src/compiler/tracing.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/tracing.ts b/src/compiler/tracing.ts index 68d6bdb503f05..635168d59bc1c 100644 --- a/src/compiler/tracing.ts +++ b/src/compiler/tracing.ts @@ -224,7 +224,7 @@ namespace ts { // eslint-disable-line one-namespace-per-file path: sourceFile.path, start: indexFromOne(getLineAndCharacterOfPosition(sourceFile, referenceNode.pos)), end: indexFromOne(getLineAndCharacterOfPosition(sourceFile, referenceNode.end)), - } + }; } } @@ -284,7 +284,7 @@ namespace ts { // eslint-disable-line one-namespace-per-file intrinsicName: (type as any).intrinsicName, symbolName: symbol?.escapedName && unescapeLeadingUnderscores(symbol.escapedName), recursionId: recursionToken, - isTuple: objectFlags & ObjectFlags.Tuple ? true : undefined, + isTuple: objectFlags & ObjectFlags.Tuple ? true : undefined, unionTypes: (type.flags & TypeFlags.Union) ? (type as UnionType).types?.map(t => t.id) : undefined, intersectionTypes: (type.flags & TypeFlags.Intersection) ? (type as IntersectionType).types.map(t => t.id) : undefined, aliasTypeArguments: type.aliasTypeArguments?.map(t => t.id), From 509ea1681aab2aeb45ca11c0fb579102c339d939 Mon Sep 17 00:00:00 2001 From: Andrew Casey Date: Fri, 26 Feb 2021 17:27:52 -0800 Subject: [PATCH 8/8] Tracing: extract getLocation helper --- src/compiler/tracing.ts | 47 +++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 28 deletions(-) diff --git a/src/compiler/tracing.ts b/src/compiler/tracing.ts index 635168d59bc1c..151eb3d311de3 100644 --- a/src/compiler/tracing.ts +++ b/src/compiler/tracing.ts @@ -162,11 +162,22 @@ namespace ts { // eslint-disable-line one-namespace-per-file performance.measure("Tracing", "beginTracing", "endTracing"); } - function indexFromOne(lc: LineAndCharacter): LineAndCharacter { - return { - line: lc.line + 1, - character: lc.character + 1, - }; + function getLocation(node: Node | undefined) { + const file = getSourceFileOfNode(node); + return !file + ? undefined + : { + path: file.path, + start: indexFromOne(getLineAndCharacterOfPosition(file, node!.pos)), + end: indexFromOne(getLineAndCharacterOfPosition(file, node!.end)), + }; + + function indexFromOne(lc: LineAndCharacter): LineAndCharacter { + return { + line: lc.line + 1, + character: lc.character + 1, + }; + } } function dumpTypes(types: readonly Type[]) { @@ -185,10 +196,6 @@ namespace ts { // eslint-disable-line one-namespace-per-file const type = types[i]; const objectFlags = (type as any).objectFlags; const symbol = type.aliasSymbol ?? type.symbol; - const firstDeclaration = symbol?.declarations?.[0]; - const firstFile = firstDeclaration && getSourceFileOfNode(firstDeclaration); - const destructuringPattern = type.pattern; - const destructuringPatternFile = destructuringPattern && getSourceFileOfNode(destructuringPattern); // It's slow to compute the display text, so skip it unless it's really valuable (or cheap) let display: string | undefined; @@ -216,16 +223,8 @@ namespace ts { // eslint-disable-line one-namespace-per-file referenceProperties = { instantiatedType: referenceType.target?.id, typeArguments: referenceType.resolvedTypeArguments?.map(t => t.id), + referenceLocation: getLocation(referenceType.node), }; - const referenceNode = referenceType.node; - if (referenceNode) { - const sourceFile = getSourceFileOfNode(referenceNode); - (referenceProperties as any).referenceLocation = { - path: sourceFile.path, - start: indexFromOne(getLineAndCharacterOfPosition(sourceFile, referenceNode.pos)), - end: indexFromOne(getLineAndCharacterOfPosition(sourceFile, referenceNode.end)), - }; - } } let conditionalProperties: object = {}; @@ -295,16 +294,8 @@ namespace ts { // eslint-disable-line one-namespace-per-file ...substitutionProperties, ...reverseMappedProperties, ...evolvingArrayProperties, - destructuringPattern: destructuringPatternFile && { - path: destructuringPatternFile.path, - start: indexFromOne(getLineAndCharacterOfPosition(destructuringPatternFile, destructuringPattern!.pos)), - end: indexFromOne(getLineAndCharacterOfPosition(destructuringPatternFile, destructuringPattern!.end)), - }, - firstDeclaration: firstFile && { - path: firstFile.path, - start: indexFromOne(getLineAndCharacterOfPosition(firstFile, firstDeclaration.pos)), - end: indexFromOne(getLineAndCharacterOfPosition(firstFile, firstDeclaration.end)), - }, + destructuringPattern: getLocation(type.pattern), + firstDeclaration: getLocation(symbol?.declarations?.[0]), flags: Debug.formatTypeFlags(type.flags).split("|"), display, };