-
Notifications
You must be signed in to change notification settings - Fork 577
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
Replace GetSymbolTable and derivatives with GetOrInit method #240
base: main
Are you sure you want to change the base?
Conversation
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.
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (3)
internal/binder/binder.go:356
- [nitpick] The name getMembers might be ambiguous. Consider renaming it to something more descriptive, such as getOrInitMembers.
func getMembers(symbol *ast.Symbol) ast.SymbolTable {
internal/binder/binder.go:360
- [nitpick] The name getExports might be ambiguous. Consider renaming it to something more descriptive, such as getOrInitExports.
func getExports(symbol *ast.Symbol) ast.SymbolTable {
internal/binder/binder.go:364
- [nitpick] The name getLocals might be ambiguous. Consider renaming it to something more descriptive, such as getOrInitLocals.
func getLocals(container *ast.Node) ast.SymbolTable {
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.
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
A new method:
Operates on the address of a symbol table; when calling it on a
SymbolTable
, usually on a struct field, Go will take the address of whateverSymbolTable
it's accessing, allowing this method to mutate it.This makes it clearer that this operation is a mutating one, unsafe for concurrent use; if you need to find all modifiers, you can just look for anyone assigning to
SymbolTable
or calling this method. (It also means you can find-references on them again.)In terms of performance, it inlines; godbolt pegs it as two instructions (it probably was before).
In adding this, I've vetted everything that used to use the old methods; the binder is of course fine. The checker seemed suspect when I was fixing races previously, but it's not, as the modifications are only on merged symbols (which are either clones or transient symbols local to a checker), or were being called on
SymbolTable
fields on types, which are also local to a checker.