-
Notifications
You must be signed in to change notification settings - Fork 877
Remove nondeterminism in container generation #3213
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -136,26 +136,26 @@ func (c *Checker) getWithAlternativeContainers(container *ast.Symbol, symbol *as | |
| } | ||
| // we potentially have a symbol which is a member of the instance side of something - look for a variable in scope with the container's type | ||
| // which may be acting like a namespace (eg, `Symbol` acts like a namespace when looking up `Symbol.toStringTag`) | ||
| var firstVariableMatch *ast.Symbol | ||
| var variableMatches []*ast.Symbol | ||
| if (meaning == ast.SymbolFlagsValue && | ||
| container.Flags&leftMeaning == 0) && | ||
| container.Flags&ast.SymbolFlagsType != 0 && | ||
| c.getDeclaredTypeOfSymbol(container).flags&TypeFlagsObject != 0 { | ||
| c.someSymbolTableInScope(enclosingDeclaration, func(t ast.SymbolTable, _ symbolTableID, _ bool, _ bool, _ *ast.Node) bool { | ||
| found := false | ||
| for _, s := range t { | ||
| if s.Flags&leftMeaning != 0 && c.getTypeOfSymbol(s) == c.getDeclaredTypeOfSymbol(container) { | ||
| firstVariableMatch = s | ||
| return true | ||
| variableMatches = append(variableMatches, s) | ||
| found = true | ||
| } | ||
| } | ||
| return false | ||
| return found | ||
| }) | ||
| c.sortSymbols(variableMatches) | ||
| } | ||
|
Comment on lines
+139
to
155
|
||
|
|
||
| var res []*ast.Symbol | ||
| if firstVariableMatch != nil { | ||
| res = append(res, firstVariableMatch) | ||
| } | ||
| res = append(res, variableMatches...) | ||
| res = append(res, additionalContainers...) | ||
| res = append(res, container) | ||
| if objectLiteralContainer != nil { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inside the symbol-table scan,
c.getDeclaredTypeOfSymbol(container)is invoked repeatedly (both in the outer condition and again for every entry in the loop). Since this callback may end up traversing large tables (including globals), please hoist the container's declared type into a local variable once and reuse it within the closure to avoid unnecessary work.