- Notifications
You must be signed in to change notification settings - Fork664
Replace GetSymbolTable and derivatives with GetOrInit method#240
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
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 {
Uh oh!
There was an error while loading.Please reload this page.
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.
Uh oh!
There was an error while loading.Please reload this page.
A new method:
Operates on theaddress 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 amutating 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 checkerseemed 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.