Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Open
jakebailey wants to merge13 commits intomain
base:main
Choose a base branch
Loading
fromjabaile/symbol-tweaks

Conversation

jakebailey
Copy link
Member

@jakebaileyjakebailey commentedJan 20, 2025
edited
Loading

A new method:

func (s*SymbolTable)GetOrInit()SymbolTable {if*s==nil {*s=make(SymbolTable)}return*s}

Operates on theaddress of a symbol table; when calling it on aSymbolTable, 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 toSymbolTable 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 onSymbolTable fields on types, which are also local to a checker.

Copy link
Contributor

@CopilotCopilotAI left a 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 {

Copy link
Contributor

@CopilotCopilotAI left a 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.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

Copilot code reviewCopilotCopilot left review comments

@gabrielluizsfgabrielluizsfgabrielluizsf approved these changes

@ahejlsbergahejlsbergAwaiting requested review from ahejlsberg

At least 1 approving review is required to merge this pull request.

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@jakebailey@gabrielluizsf

[8]ページ先頭

©2009-2025 Movatter.jp