Skip to content

Commit b68662e

Browse files
committed
MissingFilePaths are on demand and dont need to be stored
1 parent 1fbfd84 commit b68662e

19 files changed

+113
-244
lines changed

src/compiler/builder.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ namespace ts {
8787
sourceFileToPackageName: ESMap<Path, string>;
8888
projectReferences: readonly ProjectReference[] | undefined;
8989
resolvedProjectReferences: readonly (ResolvedProjectReferenceOfProgramFromBuildInfo | undefined)[] | undefined;
90-
missingPaths: readonly Path[];
9190
resolvedTypeReferenceDirectives: ESMap<string, ResolvedTypeReferenceDirectiveWithFailedLookupLocations>;
9291
fileProcessingDiagnostics: FilePreprocessingDiagnostic[] | undefined;
9392
}
@@ -351,7 +350,6 @@ namespace ts {
351350
sourceFileToPackageName: state.program.sourceFileToPackageName,
352351
projectReferences: state.program.getProjectReferences(),
353352
resolvedProjectReferences: state.program.getResolvedProjectReferences()?.map(mapResolvedProjectReference),
354-
missingPaths: state.program.getMissingFilePaths(),
355353
resolvedTypeReferenceDirectives: state.program.getResolvedTypeReferenceDirectives(),
356354
fileProcessingDiagnostics: state.program.getFileProcessingDiagnostics(),
357355
};
@@ -897,7 +895,6 @@ namespace ts {
897895
filesByName: readonly [fileId: ProgramBuildInfoFileId, file: ProgramBuildInfoFileId | typeof missingSourceOfProjectReferenceRedirect | typeof missingFile][] | undefined;
898896
projectReferences: readonly PersistedProgramProjectReference[] | undefined;
899897
resolvedProjectReferences: readonly (PersistedProgramResolvedProjectReference | undefined)[] | undefined;
900-
missingPaths: readonly ProgramBuildInfoFileId[] | undefined;
901898
resolvedTypeReferenceDirectives: readonly PersistedProgramResolutionEntry[] | undefined;
902899
fileProcessingDiagnostics: readonly PersistedProgramFilePreprocessingDiagnostic[] | undefined;
903900
resolutions: readonly PersistedProgramResolution[] | undefined;
@@ -998,7 +995,6 @@ namespace ts {
998995
filesByName,
999996
projectReferences: program.getProjectReferences()?.map(toPersistedProgramProjectReference),
1000997
resolvedProjectReferences: program.getResolvedProjectReferences()?.map(toPersistedProgramResolvedProjectReference),
1001-
missingPaths: mapToReadonlyArrayOrUndefined(program.getMissingFilePaths(), toFileId),
1002998
resolvedTypeReferenceDirectives: toPersistedProgramResolutionMap(program.getResolvedTypeReferenceDirectives()),
1003999
fileProcessingDiagnostics: mapToReadonlyArrayOrUndefined(program.getFileProcessingDiagnostics(), toPersistedProgramFilePreprocessingDiagnostic),
10041000
resolutions: mapToReadonlyArrayOrUndefined(resolutions, toPersistedProgramResolution),
@@ -1639,7 +1635,6 @@ namespace ts {
16391635
sourceFileToPackageName,
16401636
projectReferences: program.peristedProgram.projectReferences?.map(toProjectReference),
16411637
resolvedProjectReferences: program.peristedProgram.resolvedProjectReferences?.map(toResolvedProjectReference),
1642-
missingPaths: mapToReadonlyArray(program.peristedProgram.missingPaths, toFilePath),
16431638
resolvedTypeReferenceDirectives: toResolutionMap(program.peristedProgram.resolvedTypeReferenceDirectives) || new Map(),
16441639
fileProcessingDiagnostics: map(program.peristedProgram.fileProcessingDiagnostics, toFileProcessingDiagnostic),
16451640
};
@@ -1771,6 +1766,7 @@ namespace ts {
17711766
}
17721767

17731768
function createProgramFromBuildInfo(persistedProgramInfo: PersistedProgramState, compilerOptions: CompilerOptions): ProgramFromBuildInfo {
1769+
let missingFilePaths: readonly Path[] | undefined;
17741770
return {
17751771
programFromBuildInfo: true,
17761772
getCompilerOptions: () => compilerOptions,
@@ -1782,7 +1778,7 @@ namespace ts {
17821778
},
17831779
getProjectReferences: () => persistedProgramInfo.projectReferences,
17841780
getResolvedProjectReferences: () => persistedProgramInfo.resolvedProjectReferences,
1785-
getMissingFilePaths: () => persistedProgramInfo.missingPaths,
1781+
getMissingFilePaths: () => missingFilePaths ||= getMissingFilePaths(persistedProgramInfo.filesByName),
17861782
getFileIncludeReasons: () => persistedProgramInfo.fileIncludeReasons,
17871783
getResolvedTypeReferenceDirectives: () => persistedProgramInfo.resolvedTypeReferenceDirectives,
17881784
getFilesByNameMap: () => persistedProgramInfo.filesByName,

src/compiler/program.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,17 @@ namespace ts {
759759
}
760760
}
761761

762+
/*@internal*/
763+
export function getMissingFilePaths(filesByName: ESMap<Path, SourceFile | SourceFileOfProgramFromBuildInfo | Path | typeof missingSourceOfProjectReferenceRedirect | typeof missingFile>): readonly Path[] {
764+
let missingFilePaths: Path[] | undefined;
765+
filesByName.forEach((file, path) => {
766+
if (file === missingFile) {
767+
(missingFilePaths ||= []).push(path);
768+
}
769+
});
770+
return missingFilePaths || emptyArray;
771+
}
772+
762773
export function getConfigFileParsingDiagnostics(configFileParseResult: ParsedCommandLine): readonly Diagnostic[] {
763774
return configFileParseResult.options.configFile ?
764775
[...configFileParseResult.options.configFile.parseDiagnostics, ...configFileParseResult.errors] :
@@ -1033,16 +1044,13 @@ namespace ts {
10331044
}
10341045
}
10351046

1036-
missingFilePaths = arrayFrom(mapDefinedIterator(filesByName.entries(), ([path, file]) => file === missingFile ? path : undefined));
10371047
files = stableSort(processingDefaultLibFiles, compareDefaultLibFiles).concat(processingOtherFiles);
10381048
processingDefaultLibFiles = undefined;
10391049
processingOtherFiles = undefined;
10401050
packageIdToSourceFile = undefined!;
10411051
filesByNameIgnoreCase = undefined!;
10421052
}
10431053

1044-
Debug.assert(!!missingFilePaths);
1045-
10461054
// Release any files we have acquired in the old program but are
10471055
// not part of the new program.
10481056
if (oldProgram && !isProgramFromBuildInfo(oldProgram) && host.onReleaseOldSourceFile) {
@@ -1070,7 +1078,7 @@ namespace ts {
10701078
getSourceFile,
10711079
getSourceFileByPath,
10721080
getSourceFiles: () => files,
1073-
getMissingFilePaths: () => missingFilePaths!, // TODO: GH#18217
1081+
getMissingFilePaths,
10741082
getFilesByNameMap: () => filesByName,
10751083
getCompilerOptions: () => options,
10761084
getSyntacticDiagnostics,
@@ -1146,6 +1154,10 @@ namespace ts {
11461154

11471155
return program;
11481156

1157+
function getMissingFilePaths() {
1158+
return missingFilePaths ||= ts.getMissingFilePaths(filesByName);
1159+
}
1160+
11491161
function resolveModuleNamesWorker(moduleNames: string[], containingFile: SourceFile, reusedNames: string[] | undefined): readonly ResolvedModuleWithFailedLookupLocations[] {
11501162
if (!moduleNames.length) return emptyArray;
11511163
const containingFileName = getNormalizedAbsolutePath(containingFile.originalFileName, currentDirectory);
@@ -1658,8 +1670,6 @@ namespace ts {
16581670
return StructureIsReused.SafeModules;
16591671
}
16601672

1661-
missingFilePaths = oldProgram.getMissingFilePaths();
1662-
16631673
// update fileName -> file mapping
16641674
for (let index = 0; index < newSourceFiles.length; index++) {
16651675
const newSourceFile = newSourceFiles[index];
@@ -1734,7 +1744,7 @@ namespace ts {
17341744
// Use local caches
17351745
const path = toPath(f);
17361746
if (getSourceFileByPath(path)) return true;
1737-
if (contains(missingFilePaths, path)) return false;
1747+
if (contains(getMissingFilePaths(), path)) return false;
17381748
// Before falling back to the host
17391749
return host.fileExists(f);
17401750
},

src/testRunner/unittests/tsbuild/helpers.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,6 @@ interface Symbol {
318318
filesByName: MapLike<string | typeof missingSourceOfProjectReferenceRedirect | typeof missingFile> | undefined;
319319
projectReferences: readonly ProjectReference[] | undefined;
320320
resolvedProjectReferences: readonly (ReadablePersistedProgramResolvedProjectReference | undefined)[] | undefined;
321-
missingPaths: readonly string[] | undefined;
322321
resolvedTypeReferenceDirectives: readonly ReadablePersistedProgramResolutionEntry[] | undefined;
323322
fileProcessingDiagnostics: readonly ReadablePersistedProgramFilePreprocessingDiagnostic[] | undefined;
324323
resolutions: readonly ReadablePersistedProgramResolution[] | undefined;
@@ -366,7 +365,6 @@ interface Symbol {
366365
filesByName,
367366
projectReferences: buildInfo.program.peristedProgram.projectReferences?.map(toProjectReference),
368367
resolvedProjectReferences: buildInfo.program.peristedProgram.resolvedProjectReferences?.map(toReadableResolvedProjectReference),
369-
missingPaths: buildInfo.program.peristedProgram.missingPaths?.map(toFileName),
370368
resolvedTypeReferenceDirectives: buildInfo.program.peristedProgram.resolvedTypeReferenceDirectives?.map(toReadablePersistedProgramResolutionEntry),
371369
fileProcessingDiagnostics: buildInfo.program.peristedProgram.fileProcessingDiagnostics?.map(toReadablePersistedProgramFilePreprocessingDiagnostic),
372370
resolutions

0 commit comments

Comments
 (0)