Skip to content

Api cleanup for Module and Type Reference directive resolution#51546

Merged
sheetalkamat merged 14 commits into
mainfrom
moduleApiCleanup
Dec 5, 2022
Merged

Api cleanup for Module and Type Reference directive resolution#51546
sheetalkamat merged 14 commits into
mainfrom
moduleApiCleanup

Conversation

@sheetalkamat
Copy link
Copy Markdown
Member

@sheetalkamat sheetalkamat commented Nov 16, 2022

  • Added new API for module resolution and type reference resolution that returns resolutions with failed lookups and also handles the resolution mode, This change was across all hosts (CompilerHost, LanguageServiceHost and ProgramHost which is used by watch and tsc --build. ce8da01 12a16ce
  • Reusing module resolutions while constructing program reusing old program, now adds the diagnostics to file processing diagnostics so these diagnostics are not missed if program is reused. bbc4674 6a2ba6d
  • Removed the ResolutionInfo that was added as stop gap since those APis are anyways deprecated 16846c8

},
"failedLookupLocations": [],
"affectingLocations": [],
"resolutionDiagnostics": []
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I always assumed these were non-optional for V8 monomorphism reasons (though I would expect undefined instead of an empty array might be the best for performance?). @DanielRosenwasser @rbuckton is there a guiding principle for how to approach these things? Does it even make sense to try to make optimizations without looking at data from deoptigate?

Copy link
Copy Markdown
Member Author

@sheetalkamat sheetalkamat Dec 1, 2022

Choose a reason for hiding this comment

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

Made these optional because we want to handle properties as optional (from API perspective) We can always set these to empty array like before but thought of setting to undefined instead of empty array would better (since it is mutable empty array so always new array)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, I’m sure the new arrays is the worst of all the options. There might be some benefit to initializing to undefined but I’m not sure.

Comment thread src/compiler/types.ts
containingSourceFile: SourceFile,
reusedNames: readonly StringLiteralLike[] | undefined,
): readonly ResolvedModuleWithFailedLookupLocations[];
resolveTypeReferenceDirectiveReferences?<T extends FileReference | string>(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This name is a lot 😵‍💫

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

open to suggestions

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It at least makes sense, despite the repetition - you need actual references to type reference directives now, rather than strings (ideally). Related: Like the module name version, should we split the signature and attempt to deprecate the string-handling form?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, the thing that makes me dislike the name is that it still takes a string, so seems like a bit of a misnomer.

Comment thread src/compiler/program.ts
Copy link
Copy Markdown
Member

@andrewbranch andrewbranch left a comment

Choose a reason for hiding this comment

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

Looks good to me overall, but I think others should weigh in on the API changes. I also suspect we have some other infrastructure that might use sourceFile.resolvedModules even though it’s internal... @sandersn and/or I should check DefinitelyTyped-tools.

Copy link
Copy Markdown
Member

@weswigham weswigham left a comment

Choose a reason for hiding this comment

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

Better unifying the mechanisms for type reference directive loading and import loading is 👍

@andrewbranch
Copy link
Copy Markdown
Member

I checked some other repos for references to the changed internal APIs, and couldn’t find anything that will be an issue.

Comment thread src/services/types.ts Outdated
@sheetalkamat sheetalkamat merged commit 9e845d2 into main Dec 5, 2022
@sheetalkamat sheetalkamat deleted the moduleApiCleanup branch December 5, 2022 19:56
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Author: Team Breaking Change Would introduce errors in existing code For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

5 participants