Replace unsafe.Pointer for seen symbol tables with unique ID#2712
Open
jakebailey wants to merge 1 commit intomainfrom
Open
Replace unsafe.Pointer for seen symbol tables with unique ID#2712jakebailey wants to merge 1 commit intomainfrom
jakebailey wants to merge 1 commit intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR removes the last unsafe/reflect usage in the checker’s symbol accessibility logic by replacing map reference-identity checks for “seen” symbol tables with a compact, comparable symbolTableID derived from a NodeId/SymbolId plus a small kind tag.
Changes:
- Removed
reflect.ValueOf(m).UnsafePointer()andunsafe.Pointerusage for symbol-table visited tracking. - Introduced
symbolTableID(kind-tag + source id) and threaded it throughsomeSymbolTableInScopeand related callbacks. - Simplified global symbol table detection by passing an
isGlobalsflag instead of comparing map identities.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We use
reflect.ValueOf(m).UnsafePointer()in the checker in order to have maps as map keys themselves. This is the only place we use unsafe in the checker, and theoretically going through reflect has a high cost (see https://godbolt.org/z/3jMcxY49T).Instead of doing this, we can instead note that we always get a symbol table from some other value that has an ID; a
Nodeor aSymbol. If we use that ID (or a sentinel value) plus some metadata, we can avoid reflect and unsafe, swapping for a simple load+OR.This seems to achieve the same goal. All tests pass.