Skip to content

BuildInfo refactoring: Now that we dont have bundle we dont need program field explicitly #58789

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

Merged
merged 1 commit into from
Jun 6, 2024
Merged
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
263 changes: 132 additions & 131 deletions src/compiler/builder.ts

Large diffs are not rendered by default.

8 changes: 1 addition & 7 deletions src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,6 @@ import {
PrinterOptions,
PrintHandlers,
PrivateIdentifier,
ProgramBuildInfo,
PropertyAccessExpression,
PropertyAssignment,
PropertyDeclaration,
Expand Down Expand Up @@ -787,7 +786,7 @@ export function emitFiles(
emitSkipped = true;
return;
}
const buildInfo = host.getBuildInfo() || createBuildInfo(/*program*/ undefined);
const buildInfo = host.getBuildInfo() || { version };
// Pass buildinfo as additional data to avoid having to reparse
writeFile(host, emitterDiagnostics, buildInfoPath, getBuildInfoText(buildInfo), /*writeByteOrderMark*/ false, /*sourceFiles*/ undefined, { buildInfo });
emittedFilesList?.push(buildInfoPath);
Expand Down Expand Up @@ -1105,11 +1104,6 @@ export function emitFiles(
}
}

/** @internal */
export function createBuildInfo(program: ProgramBuildInfo | undefined): BuildInfo {
return { program, version };
}

/** @internal */
export function getBuildInfoText(buildInfo: BuildInfo) {
return JSON.stringify(buildInfo);
Expand Down
43 changes: 22 additions & 21 deletions src/compiler/tsbuildPublic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ import {
getWatchErrorSummaryDiagnosticMessage,
hasProperty,
identity,
IncrementalBuildInfo,
IncrementalBundleEmitBuildInfo,
IncrementalMultiFileEmitBuildInfo,
isIgnoredFileFromWildCardWatching,
isIncrementalBuildInfo,
isIncrementalCompilation,
isPackageJsonInfo,
listFiles,
Expand All @@ -89,10 +93,7 @@ import {
Path,
PollingInterval,
Program,
ProgramBuildInfo,
ProgramBundleEmitBuildInfo,
ProgramHost,
ProgramMultiFileEmitBuildInfo,
ProgramUpdateLevel,
readBuilderProgram,
ReadBuildProgramHost,
Expand Down Expand Up @@ -1638,7 +1639,7 @@ function getUpToDateStatusWorker<T extends BuilderProgram>(state: SolutionBuilde
let oldestOutputFileName: string | undefined;
let oldestOutputFileTime = maximumDate;
let buildInfoTime: Date | undefined;
let buildInfoProgram: ProgramBuildInfo | undefined;
let incrementalBuildInfo: IncrementalBuildInfo | undefined;
let buildInfoVersionMap: ReturnType<typeof getBuildInfoFileVersionMap> | undefined;
if (buildInfoPath) {
const buildInfoCacheEntry = getBuildInfoCacheEntry(state, buildInfoPath, resolvedPath);
Expand All @@ -1665,41 +1666,41 @@ function getUpToDateStatusWorker<T extends BuilderProgram>(state: SolutionBuilde
fileName: buildInfoPath,
};
}
if (buildInfo.program && buildInfo.version !== version) {
if (isIncrementalBuildInfo(buildInfo) && buildInfo.version !== version) {
return {
type: UpToDateStatusType.TsVersionOutputOfDate,
version: buildInfo.version,
};
}

if (buildInfo.program) {
if (isIncrementalBuildInfo(buildInfo)) {
// If there are pending changes that are not emitted, project is out of date
// When there are syntax errors, changeFileSet will have list of files changed (irrespective of noEmit)
// But in case of semantic error we need special treatment.
// Checking presence of affectedFilesPendingEmit list is fast and good way to tell if there were semantic errors and file emit was blocked
// 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
// 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
if (
buildInfo.program.changeFileSet?.length ||
buildInfo.changeFileSet?.length ||
(!project.options.noEmit ?
(buildInfo.program as ProgramMultiFileEmitBuildInfo).affectedFilesPendingEmit?.length ||
buildInfo.program.emitDiagnosticsPerFile?.length ||
(buildInfo.program as ProgramBundleEmitBuildInfo).pendingEmit !== undefined :
buildInfo.program.semanticDiagnosticsPerFile?.length)
(buildInfo as IncrementalMultiFileEmitBuildInfo).affectedFilesPendingEmit?.length ||
buildInfo.emitDiagnosticsPerFile?.length ||
(buildInfo as IncrementalBundleEmitBuildInfo).pendingEmit !== undefined :
buildInfo.semanticDiagnosticsPerFile?.length)
) {
return {
type: UpToDateStatusType.OutOfDateBuildInfo,
buildInfoFile: buildInfoPath,
};
}

if (!project.options.noEmit && getPendingEmitKind(project.options, buildInfo.program.options || {})) {
if (!project.options.noEmit && getPendingEmitKind(project.options, buildInfo.options || {})) {
return {
type: UpToDateStatusType.OutOfDateOptions,
buildInfoFile: buildInfoPath,
};
}
buildInfoProgram = buildInfo.program;
incrementalBuildInfo = buildInfo;
}

oldestOutputFileTime = buildInfoTime;
Expand All @@ -1722,14 +1723,14 @@ function getUpToDateStatusWorker<T extends BuilderProgram>(state: SolutionBuilde
};
}

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

if (buildInfoProgram) seenRoots.add(inputPath!);
if (incrementalBuildInfo) seenRoots.add(inputPath!);
}

if (buildInfoProgram) {
if (!buildInfoVersionMap) buildInfoVersionMap = getBuildInfoFileVersionMap(buildInfoProgram, buildInfoPath!, host);
if (incrementalBuildInfo) {
if (!buildInfoVersionMap) buildInfoVersionMap = getBuildInfoFileVersionMap(incrementalBuildInfo, buildInfoPath!, host);
const existingRoot = forEachEntry(
buildInfoVersionMap.roots,
// File was root file when project was built but its not any more
Expand Down Expand Up @@ -1954,8 +1955,8 @@ function getLatestChangedDtsTime<T extends BuilderProgram>(state: SolutionBuilde
if (!options.composite) return undefined;
const entry = Debug.checkDefined(state.buildInfoCache.get(resolvedConfigPath));
if (entry.latestChangedDtsTime !== undefined) return entry.latestChangedDtsTime || undefined;
const latestChangedDtsTime = entry.buildInfo && entry.buildInfo.program && entry.buildInfo.program.latestChangedDtsFile ?
state.host.getModifiedTime(getNormalizedAbsolutePath(entry.buildInfo.program.latestChangedDtsFile, getDirectoryPath(entry.path))) :
const latestChangedDtsTime = entry.buildInfo && isIncrementalBuildInfo(entry.buildInfo) && entry.buildInfo.latestChangedDtsFile ?
state.host.getModifiedTime(getNormalizedAbsolutePath(entry.buildInfo.latestChangedDtsFile, getDirectoryPath(entry.path))) :
undefined;
entry.latestChangedDtsTime = latestChangedDtsTime || false;
return latestChangedDtsTime;
Expand Down
2 changes: 0 additions & 2 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
PackageJsonInfo,
PackageJsonInfoCache,
Pattern,
ProgramBuildInfo,
SymlinkCache,
ThisContainer,
} from "./_namespaces/ts.js";
Expand Down Expand Up @@ -9597,7 +9596,6 @@ export interface Printer {

/** @internal */
export interface BuildInfo {
program?: ProgramBuildInfo;
version: string;
}

Expand Down
7 changes: 4 additions & 3 deletions src/compiler/watchPublic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
CompilerHost,
CompilerOptions,
ConfigFileDiagnosticsReporter,
createBuilderProgramUsingProgramBuildInfo,
createBuilderProgramUsingIncrementalBuildInfo,
createCachedDirectoryStructureHost,
createCompilerDiagnostic,
createCompilerHostFromProgramHost,
Expand Down Expand Up @@ -51,6 +51,7 @@ import {
HasInvalidatedResolutions,
isArray,
isIgnoredFileFromWildCardWatching,
isIncrementalBuildInfo,
isProgramUptoDate,
JSDocParsingMode,
MapLike,
Expand Down Expand Up @@ -116,8 +117,8 @@ export function readBuilderProgram(compilerOptions: CompilerOptions, host: ReadB
if (!content) return undefined;
buildInfo = getBuildInfo(buildInfoPath, content);
}
if (!buildInfo || buildInfo.version !== version || !buildInfo.program) return undefined;
return createBuilderProgramUsingProgramBuildInfo(buildInfo, buildInfoPath, host);
if (!buildInfo || buildInfo.version !== version || !isIncrementalBuildInfo(buildInfo)) return undefined;
return createBuilderProgramUsingIncrementalBuildInfo(buildInfo, buildInfoPath, host);
}

export function createIncrementalCompilerHost(options: CompilerOptions, system = sys): CompilerHost {
Expand Down
Loading