Skip to content

Replace unsafe.Pointer for seen symbol tables with unique ID#2712

Open
jakebailey wants to merge 1 commit intomainfrom
jabaile/symbol-table-id-no-unsafe
Open

Replace unsafe.Pointer for seen symbol tables with unique ID#2712
jakebailey wants to merge 1 commit intomainfrom
jabaile/symbol-table-id-no-unsafe

Conversation

@jakebailey
Copy link
Member

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 Node or a Symbol. 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.

Copilot AI review requested due to automatic review settings February 9, 2026 04:31
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() and unsafe.Pointer usage for symbol-table visited tracking.
  • Introduced symbolTableID (kind-tag + source id) and threaded it through someSymbolTableInScope and related callbacks.
  • Simplified global symbol table detection by passing an isGlobals flag instead of comparing map identities.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant