Skip to content

Commit

Permalink
Store array only if dtsOnly emit is pending to compress buildinfo (#5…
Browse files Browse the repository at this point in the history
  • Loading branch information
sheetalkamat authored Oct 31, 2022
1 parent e50bb07 commit 18f559f
Show file tree
Hide file tree
Showing 38 changed files with 196 additions and 147 deletions.
15 changes: 11 additions & 4 deletions src/compiler/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ namespace ts {
export type ProgramBuildInfoFileId = number & { __programBuildInfoFileIdBrand: any };
export type ProgramBuildInfoFileIdListId = number & { __programBuildInfoFileIdListIdBrand: any };
export type ProgramBuildInfoDiagnostic = ProgramBuildInfoFileId | [fileId: ProgramBuildInfoFileId, diagnostics: readonly ReusableDiagnostic[]];
export type ProgramBuilderInfoFilePendingEmit = [fileId: ProgramBuildInfoFileId, emitKind: BuilderFileEmit];
export type ProgramBuilderInfoFilePendingEmit = ProgramBuildInfoFileId | [fileId: ProgramBuildInfoFileId];
export type ProgramBuildInfoReferencedMap = [fileId: ProgramBuildInfoFileId, fileIdListId: ProgramBuildInfoFileIdListId][];
export type ProgramBuildInfoBuilderStateFileInfo = Omit<BuilderState.FileInfo, "signature"> & {
/**
Expand Down Expand Up @@ -923,7 +923,10 @@ namespace ts {
const seenFiles = new Set<Path>();
for (const path of state.affectedFilesPendingEmit.slice(state.affectedFilesPendingEmitIndex).sort(compareStringsCaseSensitive)) {
if (tryAddToSet(seenFiles, path)) {
(affectedFilesPendingEmit ||= []).push([toFileId(path), state.affectedFilesPendingEmitKind!.get(path)!]);
const fileId = toFileId(path), emitKind = state.affectedFilesPendingEmitKind!.get(path)!;
(affectedFilesPendingEmit ||= []).push(
emitKind === BuilderFileEmit.Full ? fileId : [fileId]
);
}
}
}
Expand Down Expand Up @@ -1475,6 +1478,10 @@ namespace ts {
{ version: fileInfo.version, signature: fileInfo.signature === false ? undefined : fileInfo.version, affectsGlobalScope: fileInfo.affectsGlobalScope, impliedFormat: fileInfo.impliedFormat };
}

export function toBuilderFileEmit(value: ProgramBuilderInfoFilePendingEmit): BuilderFileEmit{
return isNumber(value) ? BuilderFileEmit.Full : BuilderFileEmit.DtsOnly;
}

export function createBuilderProgramUsingProgramBuildInfo(program: ProgramBuildInfo, buildInfoPath: string, host: ReadBuildProgramHost): EmitAndSemanticDiagnosticsBuilderProgram {
const buildInfoDirectory = getDirectoryPath(getNormalizedAbsolutePath(buildInfoPath, host.getCurrentDirectory()));
const getCanonicalFileName = createGetCanonicalFileName(host.useCaseSensitiveFileNames());
Expand Down Expand Up @@ -1513,8 +1520,8 @@ namespace ts {
exportedModulesMap: toManyToManyPathMap(program.exportedModulesMap),
semanticDiagnosticsPerFile: program.semanticDiagnosticsPerFile && arrayToMap(program.semanticDiagnosticsPerFile, value => toFilePath(isNumber(value) ? value : value[0]), value => isNumber(value) ? emptyArray : value[1]),
hasReusableDiagnostic: true,
affectedFilesPendingEmit: map(program.affectedFilesPendingEmit, value => toFilePath(value[0])),
affectedFilesPendingEmitKind: program.affectedFilesPendingEmit && arrayToMap(program.affectedFilesPendingEmit, value => toFilePath(value[0]), value => value[1]),
affectedFilesPendingEmit: map(program.affectedFilesPendingEmit, value => toFilePath(isNumber(value) ? value : value[0])),
affectedFilesPendingEmitKind: program.affectedFilesPendingEmit && arrayToMap(program.affectedFilesPendingEmit, value => toFilePath(isNumber(value) ? value : value[0]), toBuilderFileEmit),
affectedFilesPendingEmitIndex: program.affectedFilesPendingEmit && 0,
changedFilesSet: new Set(map(program.changeFileSet, toFilePath)),
latestChangedDtsFile,
Expand Down
28 changes: 19 additions & 9 deletions src/testRunner/unittests/tsbuild/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ interface Symbol {
}

type ReadableProgramBuildInfoDiagnostic = string | [string, readonly ReusableDiagnostic[]];
type ReadableProgramBuilderInfoFilePendingEmit = [string, "DtsOnly" | "Full"];
type ReadableProgramBuilderInfoFilePendingEmit = [original: string | [string], emitKind: "DtsOnly" | "Full"];
type ReadableProgramBuildInfoEmitSignature = string | [string, string];
type ReadableProgramBuildInfoFileInfo = Omit<BuilderState.FileInfo, "impliedFormat"> & { impliedFormat: string | undefined; };
type ReadableProgramMultiFileEmitBuildInfo = Omit<ProgramMultiFileEmitBuildInfo,
Expand Down Expand Up @@ -252,12 +252,7 @@ interface Symbol {
toFileName(d) :
[toFileName(d[0]), d[1]]
),
affectedFilesPendingEmit: buildInfo.program.affectedFilesPendingEmit?.map(([fileId, emitKind]) => [
toFileName(fileId),
emitKind === BuilderFileEmit.DtsOnly ? "DtsOnly" :
emitKind === BuilderFileEmit.Full ? "Full" :
Debug.assertNever(emitKind)
]),
affectedFilesPendingEmit: buildInfo.program.affectedFilesPendingEmit?.map(toReadableProgramBuilderInfoFilePendingEmit),
changeFileSet: buildInfo.program.changeFileSet?.map(toFileName),
emitSignatures: buildInfo.program.emitSignatures?.map(s =>
isNumber(s) ?
Expand Down Expand Up @@ -316,6 +311,16 @@ interface Symbol {
}
return result;
}

function toReadableProgramBuilderInfoFilePendingEmit(value: ProgramBuilderInfoFilePendingEmit): ReadableProgramBuilderInfoFilePendingEmit {
const emitKind = toBuilderFileEmit(value);
return [
isNumber(value) ? toFileName(value) : [toFileName(value[0])],
emitKind === BuilderFileEmit.DtsOnly ? "DtsOnly" :
emitKind === BuilderFileEmit.Full ? "Full" :
Debug.assertNever(emitKind),
];
}
}

export function toPathWithSystem(sys: System, fileName: string): Path {
Expand Down Expand Up @@ -438,8 +443,13 @@ interface Symbol {
);
}
let expectedIndex = 0;
incrementalReadableBuildInfo.program.affectedFilesPendingEmit.forEach(([actualFile]) => {
expectedIndex = findIndex((cleanReadableBuildInfo!.program! as ReadableProgramMultiFileEmitBuildInfo).affectedFilesPendingEmit, ([expectedFile]) => actualFile === expectedFile, expectedIndex);
incrementalReadableBuildInfo.program.affectedFilesPendingEmit.forEach(([actualFileOrArray]) => {
const actualFile = isString(actualFileOrArray) ? actualFileOrArray : actualFileOrArray[0];
expectedIndex = findIndex(
(cleanReadableBuildInfo!.program! as ReadableProgramMultiFileEmitBuildInfo).affectedFilesPendingEmit,
([expectedFileOrArray]) => actualFile === (isString(expectedFileOrArray) ? expectedFileOrArray : expectedFileOrArray[0]),
expectedIndex
);
if (expectedIndex === -1) {
addBaseline(
`Incremental build contains ${actualFile} file as pending emit, clean build does not have it: ${outputFile}::`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ exitCode:: ExitStatus.DiagnosticsPresent_OutputsSkipped


//// [/src/lib/core/tsconfig.tsbuildinfo]
{"program":{"fileNames":["../../../lib/lib.d.ts","../../animals/animal.ts","../../animals/dog.ts","../../animals/index.ts","../../core/utilities.ts"],"fileInfos":[{"version":"3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true},"-14984181202-export type Size = \"small\" | \"medium\" | \"large\";\r\nexport default interface Animal {\r\n size: Size;\r\n}\r\n","-10991948013-import Animal from '.';\r\nimport { makeRandomName } from '../core/utilities';\r\n\r\nexport interface Dog extends Animal {\r\n woof(): void;\r\n name: string;\r\n}\r\n\r\nexport function createDog(): Dog {\r\n return ({\r\n size: \"medium\",\r\n woof: function(this: Dog) {\r\n console.log(`${this.name} says \"Woof\"!`);\r\n },\r\n name: makeRandomName()\r\n });\r\n}\r\n\r\n","-5382672599-import Animal from './animal';\r\n\r\nexport default Animal;\r\nimport { createDog, Dog } from './dog';\r\nexport { createDog, Dog };\r\n","-15713992787-import * as A from '../animals';\n\r\nexport function makeRandomName() {\r\n return \"Bob!?! \";\r\n}\r\n\r\nexport function lastElementOf<T>(arr: T[]): T | undefined {\r\n if (arr.length === 0) return undefined;\r\n return arr[arr.length - 1];\r\n}\r\n\r\n"],"options":{"composite":true,"declaration":true,"module":1,"noFallthroughCasesInSwitch":true,"noImplicitReturns":true,"noUnusedLocals":true,"noUnusedParameters":true,"outDir":"./","rootDir":"../../core","strict":true,"target":1},"fileIdsList":[[4,5],[2,3],[4]],"referencedMap":[[3,1],[4,2],[5,3]],"exportedModulesMap":[[3,1],[4,2],[5,3]],"semanticDiagnosticsPerFile":[1,2,3,4,[5,[{"file":"../../core/utilities.ts","start":0,"length":32,"messageText":"'A' is declared but its value is never read.","category":1,"code":6133,"reportsUnnecessary":true}]]],"affectedFilesPendingEmit":[[2,1],[3,1],[4,1],[5,1]],"emitSignatures":[2,3,4,5]},"version":"FakeTSVersion"}
{"program":{"fileNames":["../../../lib/lib.d.ts","../../animals/animal.ts","../../animals/dog.ts","../../animals/index.ts","../../core/utilities.ts"],"fileInfos":[{"version":"3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true},"-14984181202-export type Size = \"small\" | \"medium\" | \"large\";\r\nexport default interface Animal {\r\n size: Size;\r\n}\r\n","-10991948013-import Animal from '.';\r\nimport { makeRandomName } from '../core/utilities';\r\n\r\nexport interface Dog extends Animal {\r\n woof(): void;\r\n name: string;\r\n}\r\n\r\nexport function createDog(): Dog {\r\n return ({\r\n size: \"medium\",\r\n woof: function(this: Dog) {\r\n console.log(`${this.name} says \"Woof\"!`);\r\n },\r\n name: makeRandomName()\r\n });\r\n}\r\n\r\n","-5382672599-import Animal from './animal';\r\n\r\nexport default Animal;\r\nimport { createDog, Dog } from './dog';\r\nexport { createDog, Dog };\r\n","-15713992787-import * as A from '../animals';\n\r\nexport function makeRandomName() {\r\n return \"Bob!?! \";\r\n}\r\n\r\nexport function lastElementOf<T>(arr: T[]): T | undefined {\r\n if (arr.length === 0) return undefined;\r\n return arr[arr.length - 1];\r\n}\r\n\r\n"],"options":{"composite":true,"declaration":true,"module":1,"noFallthroughCasesInSwitch":true,"noImplicitReturns":true,"noUnusedLocals":true,"noUnusedParameters":true,"outDir":"./","rootDir":"../../core","strict":true,"target":1},"fileIdsList":[[4,5],[2,3],[4]],"referencedMap":[[3,1],[4,2],[5,3]],"exportedModulesMap":[[3,1],[4,2],[5,3]],"semanticDiagnosticsPerFile":[1,2,3,4,[5,[{"file":"../../core/utilities.ts","start":0,"length":32,"messageText":"'A' is declared but its value is never read.","category":1,"code":6133,"reportsUnnecessary":true}]]],"affectedFilesPendingEmit":[2,3,4,5],"emitSignatures":[2,3,4,5]},"version":"FakeTSVersion"}

//// [/src/lib/core/tsconfig.tsbuildinfo.readable.baseline.txt]
{
Expand Down Expand Up @@ -355,6 +355,6 @@ exitCode:: ExitStatus.DiagnosticsPresent_OutputsSkipped
]
},
"version": "FakeTSVersion",
"size": 2314
"size": 2298
}

Loading

0 comments on commit 18f559f

Please sign in to comment.