Remove AssignmentDeclarationMembers and GlobalExports from Symbol#3189
Remove AssignmentDeclarationMembers and GlobalExports from Symbol#3189ahejlsberg wants to merge 2 commits intomainfrom
AssignmentDeclarationMembers and GlobalExports from Symbol#3189Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors internal symbol bookkeeping to reduce ast.Symbol size by removing AssignmentDeclarationMembers and GlobalExports, relocating that state to more targeted structures in the compiler/LS pipeline.
Changes:
- Move UMD namespace (“global exports”) tracking from
Symbol.GlobalExportstoSourceFile.GlobalExports. - Replace
Symbol.AssignmentDeclarationMemberswith an internal export entry keyed byast.InternalSymbolNameAssignmentDeclaration. - Update checker and language service logic to use the new storage locations.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| internal/ls/importTracker.go | Updates UMD-global availability detection to consult SourceFile.GlobalExports via the module symbol’s ValueDeclaration. |
| internal/ls/findallreferences.go | Adjusts symbol-scope logic for external modules/UMD globals, but introduces a scoping regression for ambient external modules. |
| internal/checker/checker.go | Switches UMD export merging to SourceFile.GlobalExports and updates late-bound assignment handling to read from the new internal export symbol. |
| internal/binder/binder.go | Writes namespace exports into SourceFile.GlobalExports and stores late-bound assignment declarations under an internal export symbol. |
| internal/ast/symbol.go | Removes the two fields from Symbol and introduces InternalSymbolNameAssignmentDeclaration. |
| internal/ast/ast.go | Adds GlobalExports SymbolTable to SourceFile. |
internal/ls/findallreferences.go
Outdated
| if exposedByParent && !(symbol.Parent.ValueDeclaration != nil && ast.IsSourceFile(symbol.Parent.ValueDeclaration) && symbol.Parent.ValueDeclaration.AsSourceFile().GlobalExports == nil) { | ||
| return nil |
There was a problem hiding this comment.
The new exposedByParent gate no longer checks whether symbol.Parent is an external module symbol; it only checks for a SourceFile value declaration. For ambient external modules (declare module "a" { ... }), the module symbol's ValueDeclaration is a ModuleDeclaration, so this condition will treat exports as globally visible and return nil scope, widening the reference search incorrectly. Consider restoring the external-module check (e.g. symbol.Parent.IsExternalModule() / checker.IsExternalModuleSymbol(symbol.Parent)) and then consulting GlobalExports only when the module symbol's ValueDeclaration is a SourceFile.
| if exposedByParent && !(symbol.Parent.ValueDeclaration != nil && ast.IsSourceFile(symbol.Parent.ValueDeclaration) && symbol.Parent.ValueDeclaration.AsSourceFile().GlobalExports == nil) { | |
| return nil | |
| if exposedByParent { | |
| // If the parent is not an external module symbol, the symbol is globally visible. | |
| if !checker.IsExternalModuleSymbol(symbol.Parent) { | |
| return nil | |
| } | |
| // For external modules, only treat exports as globally visible when the module | |
| // is a SourceFile with `export as namespace` (non-nil GlobalExports). | |
| if symbol.Parent.ValueDeclaration != nil && ast.IsSourceFile(symbol.Parent.ValueDeclaration) { | |
| sourceFile := symbol.Parent.ValueDeclaration.AsSourceFile() | |
| if sourceFile.GlobalExports != nil { | |
| return nil | |
| } | |
| } |
There was a problem hiding this comment.
If the symbol's ValueDeclaration is a source file, we know we have an external module, so no need for other checks.
There was a problem hiding this comment.
Even for declare module blocks?
There was a problem hiding this comment.
declare module blocks don't permit export as namespace declarations, so nothing to check there.
There was a problem hiding this comment.
Anyways, with the latest commit the code is now equivalent to what was there before.
internal/ls/importTracker.go
Outdated
| markSeenDirectImport := nodeSeenTracker() | ||
| markSeenIndirectUser := nodeSeenTracker() | ||
| isAvailableThroughGlobal := exportInfo.exportingModuleSymbol.GlobalExports != nil | ||
| isAvailableThroughGlobal := exportInfo.exportingModuleSymbol.ValueDeclaration != nil && |
There was a problem hiding this comment.
This func is the same as the one in findallreferences.go; worth pulling into a helper?
This PR removes the rarely used
AssignmentDeclarationMembersandGlobalExportsfields fromSymbol, shrinking it to the next size class down. Assignment declarations are now tracked in a symbol with an internal name and global exports (a.k.a. UMD namespace exports) are tracked in a map on theSourceFileobject (only symbols associated with external modules would ever use theGlobalExportsfield, so a huge waste to have it in every symbol).