Skip to content

Commit 137cec1

Browse files
committed
Verify resolutionCache incremental updates
1 parent 04ae442 commit 137cec1

File tree

4 files changed

+321
-36
lines changed

4 files changed

+321
-36
lines changed

src/compiler/program.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1107,7 +1107,8 @@ export function getInferredLibraryNameResolveFrom(options: CompilerOptions, curr
11071107
return combinePaths(containingDirectory, `__lib_node_modules_lookup_${libFileName}__.ts`);
11081108
}
11091109

1110-
function getLibraryNameFromLibFileName(libFileName: string) {
1110+
/** @internal */
1111+
export function getLibraryNameFromLibFileName(libFileName: string) {
11111112
// Support resolving to lib.dom.d.ts -> @typescript/lib-dom, and
11121113
// lib.dom.iterable.d.ts -> @typescript/lib-dom/iterable
11131114
// lib.es2015.symbol.wellknown.d.ts -> @typescript/lib-es2015/symbol-wellknown

src/compiler/resolutionCache.ts

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,25 @@ export interface HasInvalidatedFromResolutionCache {
9090
* @internal
9191
*/
9292
export interface ResolutionCache {
93+
resolvedModuleNames: Map<Path, ModeAwareCache<CachedResolvedModuleWithFailedLookupLocations>>;
94+
resolvedTypeReferenceDirectives: Map<Path, ModeAwareCache<CachedResolvedTypeReferenceDirectiveWithFailedLookupLocations>>;
95+
resolvedLibraries: Map<string, CachedResolvedModuleWithFailedLookupLocations>;
96+
resolvedFileToResolution: Map<Path, Set<ResolutionWithFailedLookupLocations>>;
97+
resolutionsWithFailedLookups: Set<ResolutionWithFailedLookupLocations>;
98+
resolutionsWithOnlyAffectingLocations: Set<ResolutionWithFailedLookupLocations>;
99+
directoryWatchesOfFailedLookups: Map<string, DirectoryWatchesOfFailedLookup>;
100+
fileWatchesOfAffectingLocations: Map<string, FileWatcherOfAffectingLocation>;
93101
startRecordingFilesWithChangedResolutions(): void;
94102
finishRecordingFilesWithChangedResolutions(): Path[] | undefined;
95103

104+
watchFailedLookupLocationsOfExternalModuleResolutions<T extends ResolutionWithFailedLookupLocations, R extends ResolutionWithResolvedFileName>(
105+
name: string,
106+
resolution: T,
107+
filePath: Path,
108+
getResolutionWithResolvedFileName: GetResolutionWithResolvedFileName<T, R>,
109+
deferWatchingNonRelativeResolution: boolean,
110+
): void;
111+
96112
resolveModuleNameLiterals(
97113
moduleLiterals: readonly StringLiteralLike[],
98114
containingFile: string,
@@ -156,7 +172,8 @@ export interface ResolutionWithFailedLookupLocations {
156172
node10Result?: string;
157173
}
158174

159-
interface ResolutionWithResolvedFileName {
175+
/** @internal */
176+
export interface ResolutionWithResolvedFileName {
160177
resolvedFileName: string | undefined;
161178
packageId?: PackageId;
162179
}
@@ -165,7 +182,8 @@ interface ResolutionWithResolvedFileName {
165182
export interface CachedResolvedModuleWithFailedLookupLocations extends ResolvedModuleWithFailedLookupLocations, ResolutionWithFailedLookupLocations {
166183
}
167184

168-
interface CachedResolvedTypeReferenceDirectiveWithFailedLookupLocations extends ResolvedTypeReferenceDirectiveWithFailedLookupLocations, ResolutionWithFailedLookupLocations {
185+
/** @internal */
186+
export interface CachedResolvedTypeReferenceDirectiveWithFailedLookupLocations extends ResolvedTypeReferenceDirectiveWithFailedLookupLocations, ResolutionWithFailedLookupLocations {
169187
}
170188

171189
/** @internal */
@@ -189,15 +207,17 @@ export interface ResolutionCacheHost extends MinimalResolutionCacheHost {
189207
onDiscoveredSymlink?(): void;
190208
}
191209

192-
interface FileWatcherOfAffectingLocation {
210+
/** @internal */
211+
export interface FileWatcherOfAffectingLocation {
193212
/** watcher for the lookup */
194213
watcher: FileWatcher;
195214
resolutions: number;
196215
files: number;
197216
paths: Set<string>;
198217
}
199218

200-
interface DirectoryWatchesOfFailedLookup {
219+
/** @internal */
220+
export interface DirectoryWatchesOfFailedLookup {
201221
/** watcher for the lookup */
202222
watcher: FileWatcher;
203223
/** ref count keeping this watch alive */
@@ -467,7 +487,8 @@ function resolveModuleNameUsingGlobalCache(
467487
return result;
468488
}
469489

470-
type GetResolutionWithResolvedFileName<T extends ResolutionWithFailedLookupLocations = ResolutionWithFailedLookupLocations, R extends ResolutionWithResolvedFileName = ResolutionWithResolvedFileName> =
490+
/** @internal */
491+
export type GetResolutionWithResolvedFileName<T extends ResolutionWithFailedLookupLocations = ResolutionWithFailedLookupLocations, R extends ResolutionWithResolvedFileName = ResolutionWithResolvedFileName> =
471492
(resolution: T) => R | undefined;
472493

473494
/** @internal */
@@ -479,7 +500,7 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD
479500

480501
const resolutionsWithFailedLookups = new Set<ResolutionWithFailedLookupLocations>();
481502
const resolutionsWithOnlyAffectingLocations = new Set<ResolutionWithFailedLookupLocations>();
482-
const resolvedFileToResolution = new Map<string, Set<ResolutionWithFailedLookupLocations>>();
503+
const resolvedFileToResolution = new Map<Path, Set<ResolutionWithFailedLookupLocations>>();
483504
const impliedFormatPackageJsons = new Map<Path, readonly string[]>();
484505

485506
let hasChangedAutomaticTypeDirectiveNames = false;
@@ -529,6 +550,15 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD
529550
const typeRootsWatches = new Map<string, FileWatcher>();
530551

531552
return {
553+
resolvedModuleNames,
554+
resolvedTypeReferenceDirectives,
555+
resolvedLibraries,
556+
resolvedFileToResolution,
557+
resolutionsWithFailedLookups,
558+
resolutionsWithOnlyAffectingLocations,
559+
directoryWatchesOfFailedLookups,
560+
fileWatchesOfAffectingLocations,
561+
watchFailedLookupLocationsOfExternalModuleResolutions,
532562
getModuleResolutionCache: () => moduleResolutionCache,
533563
startRecordingFilesWithChangedResolutions,
534564
finishRecordingFilesWithChangedResolutions,
@@ -649,7 +679,7 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD
649679
if (!newProgram?.resolvedLibReferences?.has(libFileName)) {
650680
stopWatchFailedLookupLocationOfResolution(
651681
resolution,
652-
resolutionHost.toPath(getInferredLibraryNameResolveFrom(newProgram!.getCompilerOptions(), getCurrentDirectory(), libFileName)),
682+
resolutionHost.toPath(getInferredLibraryNameResolveFrom(resolutionHost.getCompilationSettings(), getCurrentDirectory(), libFileName)),
653683
getResolvedModule,
654684
);
655685
resolvedLibraries.delete(libFileName);

0 commit comments

Comments
 (0)