Skip to content

cmd/compile: record method indices before encoding a named type - #192

Merged
bradfitz merged 1 commit into
tailscale.go1.27from
bradfitz/generic_method_index
Oct 9, 2026
Merged

bradfitz merged 1 commit into
tailscale.go1.27from
bradfitz/generic_method_index

Conversation

@bradfitz

@bradfitz bradfitz commented Oct 9, 2026

Copy link
Copy Markdown
Member

CL 826105 added explicit method indices to unified export data (V5)
so that importers can restore a named type's source method order.
But the encoder only recorded a type's method indices after encoding
its underlying type, and encoding the underlying type can encode one
of the type's own generic methods first: if a field's type has a
method whose body calls the generic method, encoding that body
encodes the generic method object, which then looks up its index
before it was recorded and gets 0. Importers then sort it among the
type's first methods, so objectpath again attributes analysis facts
to the wrong methods (crashing staticcheck as in golang#81188).

Record the indices before encoding anything else.

This is a cherry-pick of upstream CL 847627, ported to Go 1.27: the
test uses cmd/compile/internal/importer and go list -export instead
of master's cmd/compile/internal/testimporter, which go1.27 lacks.

Updates golang#81188
Updates golang#82105

Change-Id: Icc8cfdd5620bb6d50b1c0b296f325c7d99ee9cc5
(cherry picked from https://go-review.googlesource.com/c/go/+/847627)

CL 826105 added explicit method indices to unified export data (V5)
so that importers can restore a named type's source method order.
But the encoder only recorded a type's method indices after encoding
its underlying type, and encoding the underlying type can encode one
of the type's own generic methods first: if a field's type has a
method whose body calls the generic method, encoding that body
encodes the generic method object, which then looks up its index
before it was recorded and gets 0. Importers then sort it among the
type's first methods, so objectpath again attributes analysis facts
to the wrong methods (crashing staticcheck as in golang#81188).

Record the indices before encoding anything else.

This is a cherry-pick of upstream CL 847627, ported to Go 1.27: the
test uses cmd/compile/internal/importer and go list -export instead
of master's cmd/compile/internal/testimporter, which go1.27 lacks.

Updates golang#81188
Updates golang#82105

Change-Id: Icc8cfdd5620bb6d50b1c0b296f325c7d99ee9cc5
(cherry picked from https://go-review.googlesource.com/c/go/+/847627)
@bradfitz
bradfitz merged commit 186053a into tailscale.go1.27 Oct 9, 2026
5 checks passed
@bradfitz
bradfitz deleted the bradfitz/generic_method_index branch October 9, 2026 17:58
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