Don't build type catalog during server tracing (#43354)

Bonus: this also drops the redundant type catalog from the
non-diagnostics-producing checker.
This commit is contained in:
Andrew Casey
2021-03-25 15:52:04 -07:00
committed by GitHub
parent e10a32591c
commit 3db6d803d5
8 changed files with 16 additions and 17 deletions
+2 -5
View File
@@ -340,8 +340,6 @@ namespace ts {
let instantiationDepth = 0;
let currentNode: Node | undefined;
const typeCatalog: Type[] = []; // NB: id is index + 1
const emptySymbols = createSymbolTable();
const arrayVariances = [VarianceFlags.Covariant];
@@ -386,7 +384,6 @@ namespace ts {
getNodeCount: () => sum(host.getSourceFiles(), "nodeCount"),
getIdentifierCount: () => sum(host.getSourceFiles(), "identifierCount"),
getSymbolCount: () => sum(host.getSourceFiles(), "symbolCount") + symbolCount,
getTypeCatalog: () => typeCatalog,
getTypeCount: () => typeCount,
getInstantiationCount: () => totalInstantiationCount,
getRelationCacheSizes: () => ({
@@ -3818,8 +3815,8 @@ namespace ts {
const result = new Type(checker, flags);
typeCount++;
result.id = typeCount;
if (tracing) {
typeCatalog.push(result);
if (produceDiagnostics) { // Only record types from one checker
tracing?.recordType(result);
}
return result;
}
-1
View File
@@ -1057,7 +1057,6 @@ namespace ts {
getNodeCount: () => getDiagnosticsProducingTypeChecker().getNodeCount(),
getIdentifierCount: () => getDiagnosticsProducingTypeChecker().getIdentifierCount(),
getSymbolCount: () => getDiagnosticsProducingTypeChecker().getSymbolCount(),
getTypeCatalog: () => getDiagnosticsProducingTypeChecker().getTypeCatalog(),
getTypeCount: () => getDiagnosticsProducingTypeChecker().getTypeCount(),
getInstantiationCount: () => getDiagnosticsProducingTypeChecker().getInstantiationCount(),
getRelationCacheSizes: () => getDiagnosticsProducingTypeChecker().getRelationCacheSizes(),
+12 -3
View File
@@ -17,6 +17,8 @@ namespace ts { // eslint-disable-line one-namespace-per-file
let mode: Mode;
const typeCatalog: Type[] = []; // NB: id is index + 1
let legendPath: string | undefined;
const legend: TraceRecord[] = [];
@@ -39,6 +41,7 @@ namespace ts { // eslint-disable-line one-namespace-per-file
}
mode = tracingMode;
typeCatalog.length = 0;
if (legendPath === undefined) {
legendPath = combinePaths(traceDir, "legend.json");
@@ -76,15 +79,15 @@ namespace ts { // eslint-disable-line one-namespace-per-file
}
/** Stops tracing for the in-progress project and dumps the type catalog. */
export function stopTracing(typeCatalog?: readonly Type[]) {
export function stopTracing() {
Debug.assert(tracing, "Tracing is not in progress");
Debug.assert(!!typeCatalog === (mode !== "server")); // Have a type catalog iff not in server mode
Debug.assert(!!typeCatalog.length === (mode !== "server")); // Have a type catalog iff not in server mode
fs.writeSync(traceFd, `\n]\n`);
fs.closeSync(traceFd);
tracing = undefined;
if (typeCatalog) {
if (typeCatalog.length) {
dumpTypes(typeCatalog);
}
else {
@@ -94,6 +97,12 @@ namespace ts { // eslint-disable-line one-namespace-per-file
}
}
export function recordType(type: Type): void {
if (mode !== "server") {
typeCatalog.push(type);
}
}
export const enum Phase {
Parse = "parse",
Program = "program",
-4
View File
@@ -3868,8 +3868,6 @@ namespace ts {
/* @internal */ getClassifiableNames(): Set<__String>;
getTypeCatalog(): readonly Type[];
getNodeCount(): number;
getIdentifierCount(): number;
getSymbolCount(): number;
@@ -4209,8 +4207,6 @@ namespace ts {
/* @internal */ getGlobalDiagnostics(): Diagnostic[];
/* @internal */ getEmitResolver(sourceFile?: SourceFile, cancellationToken?: CancellationToken): EmitResolver;
/* @internal */ getTypeCatalog(): readonly Type[];
/* @internal */ getNodeCount(): number;
/* @internal */ getIdentifierCount(): number;
/* @internal */ getSymbolCount(): number;
+1 -1
View File
@@ -675,7 +675,7 @@ namespace ts {
const compilerOptions = program.getCompilerOptions();
if (canTrace(sys, compilerOptions)) {
tracing?.stopTracing(program.getTypeCatalog());
tracing?.stopTracing();
}
let statistics: Statistic[];
+1 -1
View File
@@ -743,7 +743,7 @@ namespace ts.server {
exit() {
this.logger.info("Exiting...");
this.projectService.closeLog();
tracing?.stopTracing(ts.emptyArray);
tracing?.stopTracing();
process.exit(0);
}
-1
View File
@@ -2092,7 +2092,6 @@ declare namespace ts {
* Gets a type checker that can be used to semantically analyze source files in the program.
*/
getTypeChecker(): TypeChecker;
getTypeCatalog(): readonly Type[];
getNodeCount(): number;
getIdentifierCount(): number;
getSymbolCount(): number;
-1
View File
@@ -2092,7 +2092,6 @@ declare namespace ts {
* Gets a type checker that can be used to semantically analyze source files in the program.
*/
getTypeChecker(): TypeChecker;
getTypeCatalog(): readonly Type[];
getNodeCount(): number;
getIdentifierCount(): number;
getSymbolCount(): number;