Skip to content

Resolution cache defensive checks #19053

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

Merged
merged 5 commits into from
Oct 11, 2017
Merged

Conversation

sheetalkamat
Copy link
Member

@sheetalkamat sheetalkamat commented Oct 9, 2017

Handle the case when finishCachingPerDirectoryResolution is not called because of exception
Fixes #18975

Assert if the script info that is attached to closed project is present. This also releases external project files that get attached to the project when project is closed
Handle project close to release all the script infos held by the project. Above assert revealed that if the project update was pending and project is closed, the files added as root but not yet in program (because the project's update graph was pending/delayed) wont be released and hence those script infos holding onto the closed project.
Fixes #19003 and #18928

@sheetalkamat
Copy link
Member Author

@mhegazy or @Andy-MS can you please take a look.

@@ -141,7 +141,10 @@ namespace ts {
resolvedModuleNames.clear();
resolvedTypeReferenceDirectives.clear();
allFilesHaveInvalidatedResolution = false;
Debug.assert(perDirectoryResolvedModuleNames.size === 0 && perDirectoryResolvedTypeReferenceDirectives.size === 0);
// perDirectoryResolvedModuleNames and perDirectoryResolvedTypeReferenceDirectives could be non empty if there was exception during program update
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could just call startCachingPerDirectoryResolution from here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should an exception during program update be recoverable? Might it be more useful to crash tsserver if we throw during program update and don't catch until the event loop?

@@ -322,21 +322,21 @@ namespace ts {

if (hasChangedCompilerOptions) {
newLine = getNewLineCharacter(compilerOptions, system);
if (changesAffectModuleResolution(program && program.getCompilerOptions(), compilerOptions)) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Would prefer program && changesAffectModuleResolution(program.getCompilerOptions(), compilerOptions) since if !program, changesAffectModuleResolution has nothing it can do.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@@ -7145,6 +7145,7 @@ declare namespace ts.server {
getExternalFiles(): SortedReadonlyArray<string>;
getSourceFile(path: Path): SourceFile;
close(): void;
private detachScriptInfoIfNotRoot(uncheckedFilename);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to have #8306 so we didn't need to include this..

@ghost
Copy link

ghost commented Oct 10, 2017

Fixes #19077 too?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants