Repository navigation
cmd/compile: record method indices before encoding a named type - #192
Merged
Merged
Conversation
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)
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.
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)