Skip to content

Commit d8086f1

Browse files
authored
BuildInfo refactoring: Now that we dont have bundle we dont need program field explicitly (#58789)
1 parent b9d96df commit d8086f1

File tree

691 files changed

+115694
-119552
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

691 files changed

+115694
-119552
lines changed

src/compiler/builder.ts

+132-131
Large diffs are not rendered by default.

src/compiler/emitter.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,6 @@ import {
341341
PrinterOptions,
342342
PrintHandlers,
343343
PrivateIdentifier,
344-
ProgramBuildInfo,
345344
PropertyAccessExpression,
346345
PropertyAssignment,
347346
PropertyDeclaration,
@@ -787,7 +786,7 @@ export function emitFiles(
787786
emitSkipped = true;
788787
return;
789788
}
790-
const buildInfo = host.getBuildInfo() || createBuildInfo(/*program*/ undefined);
789+
const buildInfo = host.getBuildInfo() || { version };
791790
// Pass buildinfo as additional data to avoid having to reparse
792791
writeFile(host, emitterDiagnostics, buildInfoPath, getBuildInfoText(buildInfo), /*writeByteOrderMark*/ false, /*sourceFiles*/ undefined, { buildInfo });
793792
emittedFilesList?.push(buildInfoPath);
@@ -1105,11 +1104,6 @@ export function emitFiles(
11051104
}
11061105
}
11071106

1108-
/** @internal */
1109-
export function createBuildInfo(program: ProgramBuildInfo | undefined): BuildInfo {
1110-
return { program, version };
1111-
}
1112-
11131107
/** @internal */
11141108
export function getBuildInfoText(buildInfo: BuildInfo) {
11151109
return JSON.stringify(buildInfo);

src/compiler/tsbuildPublic.ts

+22-21
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ import {
7171
getWatchErrorSummaryDiagnosticMessage,
7272
hasProperty,
7373
identity,
74+
IncrementalBuildInfo,
75+
IncrementalBundleEmitBuildInfo,
76+
IncrementalMultiFileEmitBuildInfo,
7477
isIgnoredFileFromWildCardWatching,
78+
isIncrementalBuildInfo,
7579
isIncrementalCompilation,
7680
isPackageJsonInfo,
7781
listFiles,
@@ -89,10 +93,7 @@ import {
8993
Path,
9094
PollingInterval,
9195
Program,
92-
ProgramBuildInfo,
93-
ProgramBundleEmitBuildInfo,
9496
ProgramHost,
95-
ProgramMultiFileEmitBuildInfo,
9697
ProgramUpdateLevel,
9798
readBuilderProgram,
9899
ReadBuildProgramHost,
@@ -1638,7 +1639,7 @@ function getUpToDateStatusWorker<T extends BuilderProgram>(state: SolutionBuilde
16381639
let oldestOutputFileName: string | undefined;
16391640
let oldestOutputFileTime = maximumDate;
16401641
let buildInfoTime: Date | undefined;
1641-
let buildInfoProgram: ProgramBuildInfo | undefined;
1642+
let incrementalBuildInfo: IncrementalBuildInfo | undefined;
16421643
let buildInfoVersionMap: ReturnType<typeof getBuildInfoFileVersionMap> | undefined;
16431644
if (buildInfoPath) {
16441645
const buildInfoCacheEntry = getBuildInfoCacheEntry(state, buildInfoPath, resolvedPath);
@@ -1665,41 +1666,41 @@ function getUpToDateStatusWorker<T extends BuilderProgram>(state: SolutionBuilde
16651666
fileName: buildInfoPath,
16661667
};
16671668
}
1668-
if (buildInfo.program && buildInfo.version !== version) {
1669+
if (isIncrementalBuildInfo(buildInfo) && buildInfo.version !== version) {
16691670
return {
16701671
type: UpToDateStatusType.TsVersionOutputOfDate,
16711672
version: buildInfo.version,
16721673
};
16731674
}
16741675

1675-
if (buildInfo.program) {
1676+
if (isIncrementalBuildInfo(buildInfo)) {
16761677
// If there are pending changes that are not emitted, project is out of date
16771678
// When there are syntax errors, changeFileSet will have list of files changed (irrespective of noEmit)
16781679
// But in case of semantic error we need special treatment.
16791680
// Checking presence of affectedFilesPendingEmit list is fast and good way to tell if there were semantic errors and file emit was blocked
16801681
// But if noEmit is true, affectedFilesPendingEmit will have file list even if there are no semantic errors to preserve list of files to be emitted when running with noEmit false
16811682
// So with noEmit set to true, check on semantic diagnostics needs to be explicit as oppose to when it is false when only files pending emit is sufficient
16821683
if (
1683-
buildInfo.program.changeFileSet?.length ||
1684+
buildInfo.changeFileSet?.length ||
16841685
(!project.options.noEmit ?
1685-
(buildInfo.program as ProgramMultiFileEmitBuildInfo).affectedFilesPendingEmit?.length ||
1686-
buildInfo.program.emitDiagnosticsPerFile?.length ||
1687-
(buildInfo.program as ProgramBundleEmitBuildInfo).pendingEmit !== undefined :
1688-
buildInfo.program.semanticDiagnosticsPerFile?.length)
1686+
(buildInfo as IncrementalMultiFileEmitBuildInfo).affectedFilesPendingEmit?.length ||
1687+
buildInfo.emitDiagnosticsPerFile?.length ||
1688+
(buildInfo as IncrementalBundleEmitBuildInfo).pendingEmit !== undefined :
1689+
buildInfo.semanticDiagnosticsPerFile?.length)
16891690
) {
16901691
return {
16911692
type: UpToDateStatusType.OutOfDateBuildInfo,
16921693
buildInfoFile: buildInfoPath,
16931694
};
16941695
}
16951696

1696-
if (!project.options.noEmit && getPendingEmitKind(project.options, buildInfo.program.options || {})) {
1697+
if (!project.options.noEmit && getPendingEmitKind(project.options, buildInfo.options || {})) {
16971698
return {
16981699
type: UpToDateStatusType.OutOfDateOptions,
16991700
buildInfoFile: buildInfoPath,
17001701
};
17011702
}
1702-
buildInfoProgram = buildInfo.program;
1703+
incrementalBuildInfo = buildInfo;
17031704
}
17041705

17051706
oldestOutputFileTime = buildInfoTime;
@@ -1722,14 +1723,14 @@ function getUpToDateStatusWorker<T extends BuilderProgram>(state: SolutionBuilde
17221723
};
17231724
}
17241725

1725-
const inputPath = buildInfoProgram ? toPath(state, inputFile) : undefined;
1726+
const inputPath = incrementalBuildInfo ? toPath(state, inputFile) : undefined;
17261727
// If an buildInfo is older than the newest input, we can stop checking
17271728
if (buildInfoTime && buildInfoTime < inputTime) {
17281729
let version: string | undefined;
17291730
let currentVersion: string | undefined;
1730-
if (buildInfoProgram) {
1731+
if (incrementalBuildInfo) {
17311732
// Read files and see if they are same, read is anyways cached
1732-
if (!buildInfoVersionMap) buildInfoVersionMap = getBuildInfoFileVersionMap(buildInfoProgram, buildInfoPath!, host);
1733+
if (!buildInfoVersionMap) buildInfoVersionMap = getBuildInfoFileVersionMap(incrementalBuildInfo, buildInfoPath!, host);
17331734
const resolvedInputPath = buildInfoVersionMap.roots.get(inputPath!);
17341735
version = buildInfoVersionMap.fileInfos.get(resolvedInputPath ?? inputPath!);
17351736
const text = version ? state.readFileWithCache(resolvedInputPath ?? inputFile) : undefined;
@@ -1751,11 +1752,11 @@ function getUpToDateStatusWorker<T extends BuilderProgram>(state: SolutionBuilde
17511752
newestInputFileTime = inputTime;
17521753
}
17531754

1754-
if (buildInfoProgram) seenRoots.add(inputPath!);
1755+
if (incrementalBuildInfo) seenRoots.add(inputPath!);
17551756
}
17561757

1757-
if (buildInfoProgram) {
1758-
if (!buildInfoVersionMap) buildInfoVersionMap = getBuildInfoFileVersionMap(buildInfoProgram, buildInfoPath!, host);
1758+
if (incrementalBuildInfo) {
1759+
if (!buildInfoVersionMap) buildInfoVersionMap = getBuildInfoFileVersionMap(incrementalBuildInfo, buildInfoPath!, host);
17591760
const existingRoot = forEachEntry(
17601761
buildInfoVersionMap.roots,
17611762
// File was root file when project was built but its not any more
@@ -1954,8 +1955,8 @@ function getLatestChangedDtsTime<T extends BuilderProgram>(state: SolutionBuilde
19541955
if (!options.composite) return undefined;
19551956
const entry = Debug.checkDefined(state.buildInfoCache.get(resolvedConfigPath));
19561957
if (entry.latestChangedDtsTime !== undefined) return entry.latestChangedDtsTime || undefined;
1957-
const latestChangedDtsTime = entry.buildInfo && entry.buildInfo.program && entry.buildInfo.program.latestChangedDtsFile ?
1958-
state.host.getModifiedTime(getNormalizedAbsolutePath(entry.buildInfo.program.latestChangedDtsFile, getDirectoryPath(entry.path))) :
1958+
const latestChangedDtsTime = entry.buildInfo && isIncrementalBuildInfo(entry.buildInfo) && entry.buildInfo.latestChangedDtsFile ?
1959+
state.host.getModifiedTime(getNormalizedAbsolutePath(entry.buildInfo.latestChangedDtsFile, getDirectoryPath(entry.path))) :
19591960
undefined;
19601961
entry.latestChangedDtsTime = latestChangedDtsTime || false;
19611962
return latestChangedDtsTime;

src/compiler/types.ts

-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
PackageJsonInfo,
1414
PackageJsonInfoCache,
1515
Pattern,
16-
ProgramBuildInfo,
1716
SymlinkCache,
1817
ThisContainer,
1918
} from "./_namespaces/ts.js";
@@ -9597,7 +9596,6 @@ export interface Printer {
95979596

95989597
/** @internal */
95999598
export interface BuildInfo {
9600-
program?: ProgramBuildInfo;
96019599
version: string;
96029600
}
96039601

src/compiler/watchPublic.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
CompilerHost,
1313
CompilerOptions,
1414
ConfigFileDiagnosticsReporter,
15-
createBuilderProgramUsingProgramBuildInfo,
15+
createBuilderProgramUsingIncrementalBuildInfo,
1616
createCachedDirectoryStructureHost,
1717
createCompilerDiagnostic,
1818
createCompilerHostFromProgramHost,
@@ -51,6 +51,7 @@ import {
5151
HasInvalidatedResolutions,
5252
isArray,
5353
isIgnoredFileFromWildCardWatching,
54+
isIncrementalBuildInfo,
5455
isProgramUptoDate,
5556
JSDocParsingMode,
5657
MapLike,
@@ -116,8 +117,8 @@ export function readBuilderProgram(compilerOptions: CompilerOptions, host: ReadB
116117
if (!content) return undefined;
117118
buildInfo = getBuildInfo(buildInfoPath, content);
118119
}
119-
if (!buildInfo || buildInfo.version !== version || !buildInfo.program) return undefined;
120-
return createBuilderProgramUsingProgramBuildInfo(buildInfo, buildInfoPath, host);
120+
if (!buildInfo || buildInfo.version !== version || !isIncrementalBuildInfo(buildInfo)) return undefined;
121+
return createBuilderProgramUsingIncrementalBuildInfo(buildInfo, buildInfoPath, host);
121122
}
122123

123124
export function createIncrementalCompilerHost(options: CompilerOptions, system = sys): CompilerHost {

0 commit comments

Comments
 (0)