Fix difference between checker and binder resolvers#3118
Draft
jakebailey wants to merge 1 commit intomainfrom
Draft
Fix difference between checker and binder resolvers#3118jakebailey wants to merge 1 commit intomainfrom
jakebailey wants to merge 1 commit intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR re-aligns emit-time symbol resolution behavior between the checker and binder reference resolvers to eliminate a remaining divergence (notably affecting elidedJSImport2) introduced by prior emit-focused symbol-lookup changes.
Changes:
- Remove the non-diagnostic per-node resolved symbol cache field (
resolvedSymbolNoDiagnostics) from checker node links. - Switch the emit resolver’s binder
ReferenceResolverhook fromgetResolvedSymbolNoDiagnosticstogetResolvedSymbolOrNil. - Restore an emit-specific import-reference path by adding
getReferencedValueOrAliasSymboland using it inEmitResolver.GetReferencedImportDeclaration.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| internal/checker/types.go | Removes resolvedSymbolNoDiagnostics from SymbolNodeLinks, simplifying node link state. |
| internal/checker/emitresolver.go | Updates binder reference resolver hook and customizes import reference resolution in emit. |
| internal/checker/checker.go | Deletes getResolvedSymbolNoDiagnostics and introduces getReferencedValueOrAliasSymbol for emit import reference queries. |
You can also share your feedback on Copilot code review. Take the survey.
Comment on lines
+13389
to
13395
| func (c *Checker) getReferencedValueOrAliasSymbol(reference *ast.Node) *ast.Symbol { | ||
| resolvedSymbol := c.symbolNodeLinks.Get(reference).resolvedSymbol | ||
| if resolvedSymbol != nil && resolvedSymbol != c.unknownSymbol { | ||
| return resolvedSymbol | ||
| } | ||
| return links.resolvedSymbolNoDiagnostics | ||
| return c.resolveName(reference, reference.Text(), ast.SymbolFlagsValue|ast.SymbolFlagsExportValue|ast.SymbolFlagsAlias, nil, true /*isUse*/, false /*excludeGlobals*/) | ||
| } |
Comment on lines
827
to
832
| func (r *EmitResolver) getReferenceResolver() binder.ReferenceResolver { | ||
| if r.referenceResolver == nil { | ||
| r.referenceResolver = binder.NewReferenceResolver(r.checker.compilerOptions, binder.ReferenceResolverHooks{ | ||
| ResolveName: r.checker.resolveName, | ||
| GetResolvedSymbol: r.checker.getResolvedSymbolNoDiagnostics, | ||
| GetResolvedSymbol: r.checker.getResolvedSymbolOrNil, | ||
| GetMergedSymbol: r.checker.getMergedSymbol, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I was playing around with
getScriptTransformersand tested to see what would happen if the checker's emit resolver was always used.There was one broken test,
TestSubmodule/elidedJSImport2.ts_module=commonjs/output.It turns out there is a single divergence due to #2396.
Re-aligning things against Strada by restoring
getReferencedValueOrAliasSymbolfixes that difference. It also reveals that we can get rid ofgetResolvedSymbolNoDiagnosticsin favor ofgetResolvedSymbolOrNil, which is actually what Strada used to give its emit resolver! It just wasn't a named func before.Perhaps this implies we should have a mode which forces the emit checker to verify it always works, but I don't know how critical that is.