8000 [WIP] Caching resolutions in buildInfo and reusing them by sheetalkamat · Pull Request #50007 · microsoft/TypeScript · GitHub
[go: up one dir, main page]

Skip to content

[WIP] Caching resolutions in buildInfo and reusing them #50007

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 31 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
3172629
Add new option to cacheResolution (No actual functionality yet)
sheetalkamat Jun 30, 2022
e1600ab
Add baselining of modules and type refs
sheetalkamat Dec 9, 2022
666eece
Add tests
sheetalkamat Jul 1, 2022
1eeea26
Store resolved module and type reference resolution cache in buildinfo
sheetalkamat Jul 7, 2022
76100d7
Read reusable module cache information from the buildinfo
sheetalkamat Jul 8, 2022
4bc74b9
Add reusing cache stub
sheetalkamat Jul 8, 2022
23cfc79
Buildinfo resolutions actually reused
sheetalkamat Jul 18, 2022
0132dc0
Handle project reference redirects for the module and type reference …
sheetalkamat Jul 22, 2022
d55ab98
Test for module resolutions from different directories
sheetalkamat Jul 22, 2022
ce07d0e
Handle resolutions that would be same in ancestor directory and can b…
sheetalkamat Jul 23, 2022
959206d
Do not store failed lookups with cacheResolution option if it is reso…
sheetalkamat Jul 25, 2022
0446430
Add tests where module resolution caches should reuse the resolutions…
sheetalkamat Jul 25, 2 8000 022
207226a
Reusing resolutions in tsserver scenario
sheetalkamat Jul 25, 2022
591960e
Set old program build info as a location to look for from module reso…
sheetalkamat Jul 25, 2022
71ebed9
Modify resolution cache to update on program creation completion
sheetalkamat Nov 29, 2022
4d127fa
Remove files that are not in program from cache of unresolved imports
sheetalkamat Jul 27, 2022
feb3220
Tests for unresolved imports from multiple places
sheetalkamat Jul 27, 2022
84cda33
More tests for cache reuse directory structure
sheetalkamat Jul 27, 2022
2219b5d
Start using cache as perDirectory lookup
sheetalkamat Nov 16, 2022
6261b6c
Add tests where cache resoluition is incorrectly used because of not …
sheetalkamat Jul 27, 2022
e1ed9ea
Store package json hash in buildinfo
sheetalkamat Nov 29, 2022
7de4780
Use the hashes to verify the affecting location before using the reso…
sheetalkamat Jul 28, 2022
5c11252
Add tests for package json edits
sheetalkamat Aug 2, 2022
e21738c
Store package.json for the directories in buildinfo
sheetalkamat Aug 2, 2022
be5ecb2
During cacheResolutions dont watch failed lookups and dont look at th…
sheetalkamat Aug 3, 2022
78e215f
Dont store package json path if its found in same directory
sheetalkamat Aug 4, 2022
1e123ec
Cache packagejson scopes per directory
sheetalkamat Dec 9, 2022
81a1af9
Dont store isExternalLibraryImport in the buildInfo
sheetalkamat Dec 9, 2022
3115572
Store resolvedFileName as fileId instead of structure if thats the on…
sheetalkamat Dec 10, 2022
2bb56da
Always respect preserveSymlinks
sheetalkamat Dec 10, 2022
b179c7c
Dont store originalPath as separate, instead store originalPath || re…
sheetalkamat Dec 10, 2022
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
Prev Previous commit
Next Next commit
Modify resolution cache to update on program creation completion
  • Loading branch information
sheetalkamat committed Dec 9, 2022
commit 71ebed9c00fb80846fd6bde1e128ef322a36a7f4
14 changes: 6 additions & 8 deletions src/compiler/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1426,9 +1426,7 @@ function getCacheResolutions(state: BuilderProgramState) {
}
const automaticTypeDirectiveNames = state.program!.getAutomaticTypeDirectiveNames();
if (automaticTypeDirectiveNames.length) {
const currentDirectory = state.program!.getCurrentDirectory();
const containingDirectory = state.compilerOptions.configFilePath ? getDirectoryPath(state.compilerOptions.configFilePath) : currentDirectory;
const containingPath = toPath(containingDirectory, currentDirectory, state.program!.getCanonicalFileName);
const containingPath = toPath(state.program!.getAutomaticTypeDirectiveContainingFile(), state.program!.getCurrentDirectory(), state.program!.getCanonicalFileName);
typeRefs = toPerDirectoryAndNonRelativeNameCache(state, typeRefs, getOriginalOrResolvedTypeReferenceFileName, state.program!.getAutomaticTypeDirectiveResolutions(), containingPath);
}
return state.cacheResolutions = { modules, typeRefs };
Expand All @@ -1439,16 +1437,16 @@ function toPerDirectoryAndNonRelativeNameCache<T>(
perDirectoryAndNonRelativeNameCache: PerDirectoryAndNonRelativeNameCache<T> | undefined,
getResolvedFileName: (resolved: T) => string | undefined,
cache: ModeAwareCache<T> | undefined,
fOrDirPath: SourceFile | Path,
fOrPath: SourceFile | Path,
) {
if (!cache?.size()) return perDirectoryAndNonRelativeNameCache;
let dirPath: Path, redirectedReference: ResolvedProjectReference | undefined;
if (!isString(fOrDirPath)) {
redirectedReference = state.program!.getRedirectReferenceForResolution(fOrDirPath);
dirPath = getDirectoryPath(fOrDirPath.path);
if (!isString(fOrPath)) {
redirectedReference = state.program!.getRedirectReferenceForResolution(fOrPath);
dirPath = getDirectoryPath(fOrPath.path);
}
else {
dirPath = fOrDirPath;
dirPath = getDirectoryPath(fOrPath);
}
const mapForRedirects = perDirectoryAndNonRelativeNameCache?.perDirectory.perDirectoryMap.getMapOfCacheRedirects(redirectedReference);
let dirCache = mapForRedirects?.get(dirPath);
Expand Down
11 changes: 7 additions & 4 deletions src/compiler/moduleNameResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -802,8 +802,13 @@ export interface CacheWithRedirects<K, V> {
redirectsMap: Map<CompilerOptions, Map<K, V>>;
}

/** @internal */
export type RedirectsCacheKey = string & { __compilerOptionsKey: any; };
/** @internal */
export function createRedirectsCacheKey(options: CompilerOptions) {
return getKeyForCompilerOptions(options, moduleResolutionOptionDeclarations) as RedirectsCacheKey;
}
function createCacheWithRedirects<K, V>(ownOptions: CompilerOptions | undefined): CacheWithRedirects<K, V> {
type RedirectsCacheKey = string & { __compilerOptionsKey: any; };
const redirectsMap = new Map<CompilerOptions, Map<K, V>>();
const optionsToRedirectsKey = new Map<CompilerOptions, RedirectsCacheKey>();
const redirectsKeyToMap = new Map<RedirectsCacheKey, Map<K, V>>();
Expand Down Expand Up @@ -873,9 +878,7 @@ function createCacheWithRedirects<K, V>(ownOptions: CompilerOptions | undefined)

function getRedirectsCacheKey(options: CompilerOptions) {
let result = optionsToRedirectsKey.get(options);
if (!result) {
optionsToRedirectsKey.set(options, result = getKeyForCompilerOptions(options, moduleResolutionOptionDeclarations) as RedirectsCacheKey);
}
if (!result) optionsToRedirectsKey.set(options, result = createRedirectsCacheKey(options));
return result;
}
}
Expand Down
16 changes: 10 additions & 6 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1689,10 +1689,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
automaticTypeDirectiveResolutions = createModeAwareCache();
if (automaticTypeDirectiveNames.length) {
tracing?.push(tracing.Phase.Program, "processTypeReferences", { count: automaticTypeDirectiveNames.length });
// This containingFilename needs to match with the one used in managed-side
const containingDirectory = options.configFilePath ? getDirectoryPath(options.configFilePath) : host.getCurrentDirectory();
const containingFilename = combinePaths(containingDirectory, inferredTypesContainingFile);
const resolutions = resolveTypeReferenceDirectiveNamesReusingOldState(automaticTypeDirectiveNames, containingFilename);
const resolutions = resolveTypeReferenceDirectiveNamesReusingOldState(automaticTypeDirectiveNames, getAutomaticTypeDirectiveContainingFile());
for (let i = 0; i < automaticTypeDirectiveNames.length; i++) {
// under node16/nodenext module resolution, load `types`/ata include names as cjs resolution results by passing an `undefined` mode
automaticTypeDirectiveResolutions.set(automaticTypeDirectiveNames[i], /*mode*/ undefined, resolutions[i]);
Expand Down Expand Up @@ -1745,13 +1742,13 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
if (shouldCreateNewSourceFile || !newFile || newFile.impliedNodeFormat !== oldSourceFile.impliedNodeFormat ||
// old file wasn't redirect but new file is
(oldSourceFile.resolvedPath === oldSourceFile.path && newFile.resolvedPath !== oldSourceFile.path)) {
host.onReleaseOldSourceFile(oldSourceFile, oldProgram.getCompilerOptions(), !!getSourceFileByPath(oldSourceFile.path));
host.onReleaseOldSourceFile(oldSourceFile, oldProgram.getCompilerOptions());
}
}
if (!host.getParsedCommandLine) {
oldProgram.forEachResolvedProjectReference(resolvedProjectReference => {
if (!getResolvedProjectReferenceByPath(resolvedProjectReference.sourceFile.path)) {
host.onReleaseOldSourceFile!(resolvedProjectReference.sourceFile, oldProgram!.getCompilerOptions(), /*hasSourceFileByPath*/ false);
host.onReleaseOldSourceFile!(resolvedProjectReference.sourceFile, oldProgram!.getCompilerOptions());
}
});
}
Expand Down Expand Up @@ -1811,6 +1808,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
getResolvedTypeReferenceDirectives: () => resolvedTypeReferenceDirectives,
getAutomaticTypeDirectiveNames: () => automaticTypeDirectiveNames!,
getAutomaticTypeDirectiveResolutions: () => automaticTypeDirectiveResolutions,
getAutomaticTypeDirectiveContainingFile,
isSourceFileFromExternalLibrary,
isSourceFileDefaultLibrary,
getSourceFileFromReference,
Expand Down Expand Up @@ -1865,6 +1863,12 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg

return program;

function getAutomaticTypeDirectiveContainingFile() {
// This containingFilename needs to match with the one used in managed-side
const containingDirectory = options.configFilePath ? getDirectoryPath(options.configFilePath) : host.getCurrentDirectory();
return combinePaths(containingDirectory, inferredTypesContainingFile);
}

function addResolutionDiagnostics(resolution: ResolvedModuleWithFailedLookupLocations | ResolvedTypeReferenceDirectiveWithFailedLookupLocations) {
if (!resolution.resolutionDiagnostics?.length) return;
(fileProcessingDiagnostics ??= []).push({
Expand Down
Loading
0