Skip to content

🤖 Pick PR #61861 (Watch failed lookups, affecting loc...) into release-5.8 #61864

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

Open
wants to merge 2 commits into
base: release-5.8
Choose a base branch
from
Open
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
  •  
  •  
  •  
78 changes: 44 additions & 34 deletions src/compiler/resolutionCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD
let filesWithChangedSetOfUnresolvedImports: Path[] | undefined;
let filesWithInvalidatedResolutions: Set<Path> | undefined;
let filesWithInvalidatedNonRelativeUnresolvedImports: ReadonlyMap<Path, readonly string[]> | undefined;
const nonRelativeExternalModuleResolutions = new Set<ResolutionWithFailedLookupLocations>();
const nonRelativeExternalModuleResolutions = new Set<ResolvedModuleWithFailedLookupLocations>();

const resolutionsWithFailedLookups = new Set<ResolutionWithFailedLookupLocations>();
const resolutionsWithOnlyAffectingLocations = new Set<ResolutionWithFailedLookupLocations>();
Expand Down Expand Up @@ -1103,10 +1103,10 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD
(resolution.files ??= new Set()).add(filePath);
if (resolution.files.size !== 1) return;
if (!deferWatchingNonRelativeResolution || isExternalModuleNameRelative(name)) {
watchFailedLookupLocationOfResolution(resolution);
watchFailedLookupLocationOfResolution(resolution, getResolutionWithResolvedFileName);
}
else {
nonRelativeExternalModuleResolutions.add(resolution);
nonRelativeExternalModuleResolutions.add(resolution as unknown as ResolvedModuleWithFailedLookupLocations);
}
const resolved = getResolutionWithResolvedFileName(resolution);
if (resolved && resolved.resolvedFileName) {
Expand Down Expand Up @@ -1143,25 +1143,34 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD
return setAtRoot;
}

function watchFailedLookupLocationOfResolution(resolution: ResolutionWithFailedLookupLocations) {
function watchFailedLookupLocationOfModule(resolution: ResolvedModuleWithFailedLookupLocations) {
watchFailedLookupLocationOfResolution(resolution, getResolvedModuleFromResolution);
}

function watchFailedLookupLocationOfResolution<T extends ResolutionWithFailedLookupLocations, R extends ResolutionWithResolvedFileName>(
resolution: T,
getResolutionWithResolvedFileName: GetResolutionWithResolvedFileName<T, R>,
) {
Debug.assert(!!resolution.files?.size);

const { failedLookupLocations, affectingLocations, alternateResult } = resolution;
if (!failedLookupLocations?.length && !affectingLocations?.length && !alternateResult) return;
if (failedLookupLocations?.length || alternateResult) resolutionsWithFailedLookups.add(resolution);

let setAtRoot = false;
if (failedLookupLocations) {
for (const failedLookupLocation of failedLookupLocations) {
setAtRoot = watchFailedLookupLocation(failedLookupLocation, setAtRoot);
const resolvedFileName = getResolutionWithResolvedFileName(resolution)?.resolvedFileName;
if (!resolvedFileName) {
if (failedLookupLocations?.length || alternateResult) resolutionsWithFailedLookups.add(resolution);
let setAtRoot = false;
if (failedLookupLocations) {
for (const failedLookupLocation of failedLookupLocations) {
setAtRoot = watchFailedLookupLocation(failedLookupLocation, setAtRoot);
}
}
if (alternateResult) setAtRoot = watchFailedLookupLocation(alternateResult, setAtRoot);
if (setAtRoot) {
// This is always non recursive
setDirectoryWatcher(rootDir, rootPath, /*packageDir*/ undefined, /*packageDirPath*/ undefined, /*nonRecursive*/ true);
}
watchAffectingLocationsOfResolution(resolution, !!resolvedFileName);
}
if (alternateResult) setAtRoot = watchFailedLookupLocation(alternateResult, setAtRoot);
if (setAtRoot) {
// This is always non recursive
setDirectoryWatcher(rootDir, rootPath, /*packageDir*/ undefined, /*packageDirPath*/ undefined, /*nonRecursive*/ true);
}
watchAffectingLocationsOfResolution(resolution, !failedLookupLocations?.length && !alternateResult);
}

function watchAffectingLocationsOfResolution(resolution: ResolutionWithFailedLookupLocations, addToResolutionsWithOnlyAffectingLocations: boolean) {
Expand Down Expand Up @@ -1241,7 +1250,7 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD
}

function watchFailedLookupLocationOfNonRelativeModuleResolutions() {
nonRelativeExternalModuleResolutions.forEach(watchFailedLookupLocationOfResolution);
nonRelativeExternalModuleResolutions.forEach(watchFailedLookupLocationOfModule);
nonRelativeExternalModuleResolutions.clear();
}

Expand Down Expand Up @@ -1384,26 +1393,27 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD
const resolutions = resolvedFileToResolution.get(key);
if (resolutions?.delete(resolution) && !resolutions.size) resolvedFileToResolution.delete(key);
}

const { failedLookupLocations, affectingLocations, alternateResult } = resolution;
if (resolutionsWithFailedLookups.delete(resolution)) {
let removeAtRoot = false;
if (failedLookupLocations) {
for (const failedLookupLocation of failedLookupLocations) {
removeAtRoot = stopWatchFailedLookupLocation(failedLookupLocation, removeAtRoot);
else {
const { failedLookupLocations, affectingLocations, alternateResult } = resolution;
if (resolutionsWithFailedLookups.delete(resolution)) {
let removeAtRoot = false;
if (failedLookupLocations) {
for (const failedLookupLocation of failedLookupLocations) {
removeAtRoot = stopWatchFailedLookupLocation(failedLookupLocation, removeAtRoot);
}
}
if (alternateResult) removeAtRoot = stopWatchFailedLookupLocation(alternateResult, removeAtRoot);
if (removeAtRoot) removeDirectoryWatcher(rootPath);
}
else if (affectingLocations?.length) {
resolutionsWithOnlyAffectingLocations.delete(resolution);
}
if (alternateResult) removeAtRoot = stopWatchFailedLookupLocation(alternateResult, removeAtRoot);
if (removeAtRoot) removeDirectoryWatcher(rootPath);
}
else if (affectingLocations?.length) {
resolutionsWithOnlyAffectingLocations.delete(resolution);
}

if (affectingLocations) {
for (const affectingLocation of affectingLocations) {
const watcher = fileWatchesOfAffectingLocations.get(affectingLocation)!;
watcher.resolutions--;
if (affectingLocations) {
for (const affectingLocation of affectingLocations) {
const watcher = fileWatchesOfAffectingLocations.get(affectingLocation)!;
watcher.resolutions--;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@ PolledWatches::
FsWatches::
/home/src/tslibs/TS/Lib/lib.d.ts: *new*
{}
/user/username/projects/myproject: *new*
{}
/user/username/projects/myproject/a.ts: *new*
{}
/user/username/projects/myproject/b.d.ts: *new*
Expand All @@ -150,9 +148,6 @@ FsWatchesRecursive::
/user/username/projects/myproject: *new*
{}

Timeout callback:: count: 1
2: timerToInvalidateFailedLookupResolutions *new*

Program root files: [
"/user/username/projects/myproject/a.ts",
"/user/username/projects/myproject/b.d.ts",
Expand Down Expand Up @@ -195,13 +190,11 @@ export class C
}


Timeout callback:: count: 2
2: timerToInvalidateFailedLookupResolutions
3: timerToUpdateProgram *new*
Timeout callback:: count: 1
1: timerToUpdateProgram *new*

Before running Timeout callback:: count: 2
2: timerToInvalidateFailedLookupResolutions
3: timerToUpdateProgram
Before running Timeout callback:: count: 1
1: timerToUpdateProgram

Host is moving to new time
After running Timeout callback:: count: 0
Expand Down Expand Up @@ -324,10 +317,10 @@ export class C


Timeout callback:: count: 1
4: timerToUpdateProgram *new*
2: timerToUpdateProgram *new*

Before running Timeout callback:: count: 1
4: timerToUpdateProgram
2: timerToUpdateProgram

Host is moving to new time
After running Timeout callback:: count: 0
Expand Down Expand Up @@ -450,10 +443,10 @@ export class C


Timeout callback:: count: 1
5: timerToUpdateProgram *new*
3: timerToUpdateProgram *new*

Before running Timeout callback:: count: 1
5: timerToUpdateProgram
3: timerToUpdateProgram

Host is moving to new time
After running Timeout callback:: count: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ PolledWatches::
FsWatches::
/home/src/tslibs/TS/Lib/lib.d.ts: *new*
{}
/user/username/projects/myproject: *new*
{}
/user/username/projects/myproject/a.ts: *new*
{}
/user/username/projects/myproject/b.d.ts: *new*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@ PolledWatches::
FsWatches::
/home/src/tslibs/TS/Lib/lib.d.ts: *new*
{}
/user/username/projects/myproject: *new*
{}
/user/username/projects/myproject/a.ts: *new*
{}
/user/username/projects/myproject/b.d.ts: *new*
Expand All @@ -159,9 +157,6 @@ FsWatchesRecursive::
/user/username/projects/myproject: *new*
{}

Timeout callback:: count: 1
2: timerToInvalidateFailedLookupResolutions *new*

Program root files: [
"/user/username/projects/myproject/a.ts",
"/user/username/projects/myproject/b.d.ts",
Expand Down Expand Up @@ -205,13 +200,11 @@ export class C
}


Timeout callback:: count: 2
2: timerToInvalidateFailedLookupResolutions
3: timerToUpdateProgram *new*
Timeout callback:: count: 1
1: timerToUpdateProgram *new*

Before running Timeout callback:: count: 2
2: timerToInvalidateFailedLookupResolutions
3: timerToUpdateProgram
Before running Timeout callback:: count: 1
1: timerToUpdateProgram

Host is moving to new time
After running Timeout callback:: count: 0
Expand Down Expand Up @@ -340,10 +333,10 @@ export class C


Timeout callback:: count: 1
4: timerToUpdateProgram *new*
2: timerToUpdateProgram *new*

Before running Timeout callback:: count: 1
4: timerToUpdateProgram
2: timerToUpdateProgram

Host is moving to new time
After running Timeout callback:: count: 0
Expand Down Expand Up @@ -472,10 +465,10 @@ export class C


Timeout callback:: count: 1
5: timerToUpdateProgram *new*
3: timerToUpdateProgram *new*

Before running Timeout callback:: count: 1
5: timerToUpdateProgram
3: timerToUpdateProgram

Host is moving to new time
After running Timeout callback:: count: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ PolledWatches::
FsWatches::
/home/src/tslibs/TS/Lib/lib.d.ts: *new*
{}
/user/username/projects/myproject: *new*
{}
/user/username/projects/myproject/a.ts: *new*
{}
/user/username/projects/myproject/b.d.ts: *new*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,6 @@ PolledWatches::
FsWatches::
/home/src/tslibs/TS/Lib/lib.d.ts: *new*
{}
/user/username/projects/myproject: *new*
{}
/user/username/projects/myproject/a.ts: *new*
{}
/user/username/projects/myproject/b.d.ts: *new*
Expand All @@ -147,9 +145,6 @@ FsWatchesRecursive::
/user/username/projects/myproject: *new*
{}

Timeout callback:: count: 1
2: timerToInvalidateFailedLookupResolutions *new*

Program root files: [
"/user/username/projects/myproject/a.ts",
"/user/username/projects/myproject/b.d.ts",
Expand Down Expand Up @@ -191,13 +186,11 @@ export class C
}


Timeout callback:: count: 2
2: timerToInvalidateFailedLookupResolutions
3: timerToUpdateProgram *new*
Timeout callback:: count: 1
1: timerToUpdateProgram *new*

Before running Timeout callback:: count: 2
2: timerToInvalidateFailedLookupResolutions
3: timerToUpdateProgram
Before running Timeout callback:: count: 1
1: timerToUpdateProgram

Host is moving to new time
After running Timeout callback:: count: 0
Expand Down Expand Up @@ -337,10 +330,10 @@ export class C


Timeout callback:: count: 1
4: timerToUpdateProgram *new*
2: timerToUpdateProgram *new*

Before running Timeout callback:: count: 1
4: timerToUpdateProgram
2: timerToUpdateProgram

Host is moving to new time
After running Timeout callback:: count: 0
Expand Down Expand Up @@ -461,10 +454,10 @@ export class C


Timeout callback:: count: 1
5: timerToUpdateProgram *new*
3: timerToUpdateProgram *new*

Before running Timeout callback:: count: 1
5: timerToUpdateProgram
3: timerToUpdateProgram

Host is moving to new time
After running Timeout callback:: count: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ PolledWatches::
FsWatches::
/home/src/tslibs/TS/Lib/lib.d.ts: *new*
{}
/user/username/projects/myproject: *new*
{}
/user/username/projects/myproject/a.ts: *new*
{}
/user/username/projects/myproject/b.d.ts: *new*
Expand Down
Loading
Loading