Skip to content

[WIP] Persist resolutions and program information and reuse it when building program incrementally or during editor #41004

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

Closed
wants to merge 49 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
226f3ec
Use hash of source file text as version for the source file
sheetalkamat Mar 2, 2021
bf5e953
Add way to handle different script kind for the source file to determ…
sheetalkamat May 11, 2021
364826d
Let source file store resolutions with failed lookup locations
sheetalkamat Mar 2, 2021
4b306e1
Ensure program uses sourceFile version and Path instead of fileNames …
sheetalkamat Oct 7, 2020
1784730
Add assert that redirectTarget file is already seen before redirect f…
sheetalkamat Oct 8, 2020
430462a
Switch program to store name to ResolvedTypeReferenceDirective
sheetalkamat Oct 8, 2020
02bd384
Some more updates to module resolution reuse
sheetalkamat Oct 8, 2020
830df2e
Its ok to compare the file version for redirect files
sheetalkamat Oct 9, 2020
48abe6c
Make getFilesByName buildinfo ready
sheetalkamat Oct 9, 2020
396ec7f
Create Types for ProgramFromBuildInfo
sheetalkamat Oct 8, 2020
69f5ded
Skeleton for buildinfo program
sheetalkamat Oct 9, 2020
31b7991
Add option persistResolutions
sheetalkamat Oct 12, 2020
f854038
CleanResolutions to remove resolutions from tsbuildinfo file
sheetalkamat Oct 12, 2020
9e07d45
Clean resolutions from tsbuild info
sheetalkamat Oct 12, 2020
6ee1739
Tests
sheetalkamat Oct 12, 2020
65c4930
Handle outFile
sheetalkamat Oct 13, 2020
58b95b9
Emit bundle only if there are sections for bundle
sheetalkamat Mar 19, 2021
070b846
Persist resolutions, persists resolutions in program and not watches …
sheetalkamat Oct 13, 2020
cf12c5e
renames to cleanPersistedProgram
sheetalkamat Oct 15, 2020
cfc5f93
Add tests where resolutions are reused which is much more common scen…
sheetalkamat Oct 21, 2020
d073cd4
Store program to persist in buildinfo and clean it as part of cleanRe…
sheetalkamat Oct 21, 2020
c7dcf3c
Use fileIds for filesByName and missingPaths
sheetalkamat Mar 10, 2021
a75a411
More usage of fileId in source file data
sheetalkamat Mar 10, 2021
ecb0ef9
Handle file processing diagnostics and ResolvedProjectReference sourc…
sheetalkamat Mar 10, 2021
d4c5719
Convert fileName and originalFileName in the sourceFile to fileId
sheetalkamat Mar 19, 2021
63490b4
ProjectReference and ResolvedProjectReference mapping
sheetalkamat Mar 19, 2021
59c8b62
rootFileNames and redirectTargets mapping
sheetalkamat Mar 19, 2021
986cd61
Make `cleanPersistedProgram` option internal
sheetalkamat Mar 4, 2021
5c1598b
Ensure that the diagnostic message keys get converted correctly
sheetalkamat Mar 4, 2021
d847b00
Handle typeref, reference directives and lib directives
sheetalkamat Mar 19, 2021
03ee004
Baseline readable file include reason
sheetalkamat Mar 19, 2021
00005be
Map resolutions
sheetalkamat Mar 20, 2021
a3e7aaa
Refactor
sheetalkamat Mar 22, 2021
9d7cdad
More tests
sheetalkamat Mar 4, 2021
0080cb5
MissingFilePaths are on demand and dont need to be stored
sheetalkamat Mar 4, 2021
f0be476
Tests for tsserver scenario
sheetalkamat Mar 5, 2021
0fc318e
Actually make the tsserver tests with persistResolutions
sheetalkamat Mar 5, 2021
4dbd53f
Refactoring
sheetalkamat Mar 24, 2021
86a3b17
Persist resolutions in services
sheetalkamat Mar 25, 2021
8741321
Add more tests
sheetalkamat Mar 30, 2021
841b9ae
persistResolutions will reuse resolutions only if it is resolved
sheetalkamat Mar 30, 2021
688b635
Some more tests
sheetalkamat May 18, 2021
8ec6dab
Do not watch failed lookup locations in persistResolutions if resolve…
sheetalkamat May 18, 2021
76ec5cd
Add tests for auto type reference directives
sheetalkamat May 18, 2021
4118283
Save names of auto type directive names so that we can update program…
sheetalkamat May 25, 2021
d604d19
Tests for project references and persistResolutions (without actually…
sheetalkamat May 26, 2021
5d658c6
Tests with actual persistResolutions
sheetalkamat Jun 1, 2021
f0db440
Handle the difference is useSourceOfProjectReferenceRedirect and proj…
sheetalkamat Jun 2, 2021
dafa644
Merge branch 'main' into persistentResolutions
sheetalkamat Jun 4, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
658 changes: 629 additions & 29 deletions src/compiler/builder.ts

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions src/compiler/builderPublic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ namespace ts {
*/
/*@internal*/
getProgramOrUndefined(): Program | undefined;
/**
* Returns current program that could be undefined if the program was released
*/
/*@internal*/
getProgramOrProgramFromBuildInfoOrUndefined(): Program | ProgramFromBuildInfo | undefined;
/**
* Releases reference to the program, making all the other operations that need program to fail.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/builderState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ namespace ts {

// Handle type reference directives
if (sourceFile.resolvedTypeReferenceDirectiveNames) {
sourceFile.resolvedTypeReferenceDirectiveNames.forEach((resolvedTypeReferenceDirective) => {
sourceFile.resolvedTypeReferenceDirectiveNames.forEach(({ resolvedTypeReferenceDirective }) => {
if (!resolvedTypeReferenceDirective) {
return;
}
Expand Down
8 changes: 4 additions & 4 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ namespace ts {
if (!sf.resolvedModules) return;

forEachEntry(sf.resolvedModules, r => {
if (r && r.packageId) set.add(r.packageId.name);
if (r.resolvedModule?.packageId) set.add(r.resolvedModule.packageId.name);
});
});
return set;
Expand Down Expand Up @@ -40338,11 +40338,11 @@ namespace ts {
if (resolvedTypeReferenceDirectives) {
// populate reverse mapping: file path -> type reference directive that was resolved to this file
fileToDirective = new Map<string, string>();
resolvedTypeReferenceDirectives.forEach((resolvedDirective, key) => {
if (!resolvedDirective || !resolvedDirective.resolvedFileName) {
resolvedTypeReferenceDirectives.forEach(({ resolvedTypeReferenceDirective }, key) => {
if (!resolvedTypeReferenceDirective || !resolvedTypeReferenceDirective.resolvedFileName) {
return;
}
const file = host.getSourceFile(resolvedDirective.resolvedFileName);
const file = host.getSourceFile(resolvedTypeReferenceDirective.resolvedFileName);
if (file) {
// Add the transitive closure of path references loaded by this file (as long as they are not)
// part of an existing type reference.
Expand Down
14 changes: 14 additions & 0 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,13 @@ namespace ts {
isCommandLineOnly: true,
description: Diagnostics.The_locale_used_when_displaying_messages_to_the_user_e_g_en_us
},
{
name: "cleanPersistedProgram",
type: "boolean",
isCommandLineOnly: true,
category: Diagnostics.Modules,
description: Diagnostics.Clean_persisted_program_information_in_tsbuildinfo_file,
},
];

/* @internal */
Expand Down Expand Up @@ -967,6 +974,13 @@ namespace ts {
// so pass --noResolve to avoid reporting missing file errors.
transpileOptionValue: true
},
{
name: "persistResolutions",
type: "boolean",
affectsModuleResolution: true,
category: Diagnostics.Modules,
description: Diagnostics.Save_module_and_type_reference_directive_resolution_information_in_tsbuildinfo_file,
},
{
name: "stripInternal",
type: "boolean",
Expand Down
4 changes: 3 additions & 1 deletion src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,9 @@ namespace ts {
return true;
}

export function arrayIsEqualTo<T>(array1: readonly T[] | undefined, array2: readonly T[] | undefined, equalityComparer: (a: T, b: T, index: number) => boolean = equateValues): boolean {
export function arrayIsEqualTo<T>(array1: readonly T[] | undefined, array2: readonly T[] | undefined, equalityComparer?: (a: T, b: T, index: number) => boolean): boolean;
export function arrayIsEqualTo<T, U>(array1: readonly T[] | undefined, array2: readonly U[] | undefined, equalityComparer: (a: T, b: U, index: number) => boolean): boolean;
export function arrayIsEqualTo<T, U = T>(array1: readonly T[] | undefined, array2: readonly U[] | undefined, equalityComparer: (a: T, b: U, index: number) => boolean = equateValues as any): boolean {
if (!array1 || !array2) {
return array1 === array2;
}
Expand Down
8 changes: 8 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -4919,6 +4919,14 @@
"code": 6257
},

"Save module and type reference directive resolution information in '.tsbuildinfo' file.": {
"category": "Message",
"code": 6258
},
"Clean persisted program information in '.tsbuildinfo' file.": {
"category": "Message",
"code": 6259
},

"Projects to reference": {
"category": "Message",
Expand Down
5 changes: 3 additions & 2 deletions src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ namespace ts {
const prepends = host.getPrependNodes();
if (sourceFiles.length || prepends.length) {
const bundle = factory.createBundle(sourceFiles, prepends);
const result = action(getOutputPathsFor(bundle, host, forceDtsEmit), bundle);
const outputPaths = getOutputPathsFor(bundle, host, forceDtsEmit);
const result = action(!onlyBuildInfo ? outputPaths : { buildInfoPath: outputPaths.buildInfoPath }, bundle);
if (result) {
return result;
}
Expand Down Expand Up @@ -385,7 +386,7 @@ namespace ts {
return;
}
const version = ts.version; // Extracted into a const so the form is stable between namespace and module
writeFile(host, emitterDiagnostics, buildInfoPath, getBuildInfoText({ bundle, program, version }), /*writeByteOrderMark*/ false);
writeFile(host, emitterDiagnostics, buildInfoPath, getBuildInfoText({ bundle: bundle && (bundle.js || bundle.dts) ? bundle : undefined, program, version }), /*writeByteOrderMark*/ false);
}

function emitJsFileOrBundle(
Expand Down
Loading