build: preserve main package identity for test builds - #2370
Conversation
LLGo baseline benchmarks
Program measurements
Core language and compiler benchmarks
Compared with |
There was a problem hiding this comment.
Review Summary
This PR reworks how //go:linkname resolves into test-compiled main packages. It replaces the previous approach (renaming the package to "main.test", which mutated the real package name) with a scope sentinel: an @ForTest marker constant is inserted into the package scope when a main package is built for test, and ssa/abi/abi.go PathOf() consults that marker to return the real import path instead of collapsing to "main".
The approach is sound and a genuine improvement over mutating Types.Name():
- The
@prefix is deliberately un-spellable as a Go identifier, so the sentinel cannot collide with, or be spoofed by, user code. No security issue. - The added
Scope().LookupinPathOfis O(1) and guarded byName() == "main"short-circuit, so it only runs formainpackages. No performance concern. - Removing the obsolete
main.testrename (and its test) is correct hygiene; the surviving.testsuffix checks operate onpkg.ID/pkg.PkgPath, not the removed rename, so they are unaffected.
Findings below are maintainability/robustness improvements, not blockers. The new test/linkname/ regression tests are a good addition.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
6cddd43 to
df97f44
Compare
Summary
Testing