Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/tools/gopls: incorrect size computation in fieldalignment analyzer #51016

Open
hyangah opened this issue Feb 4, 2022 · 1 comment
Open

x/tools/gopls: incorrect size computation in fieldalignment analyzer #51016

hyangah opened this issue Feb 4, 2022 · 1 comment
Labels
gopls/analysis gopls Tools
Milestone

Comments

@hyangah
Copy link
Contributor

@hyangah hyangah commented Feb 4, 2022

gopls version

v0.7.5 compiled with go1.18beta2

go version

go version go1.18beta2 darwin/amd64

What did you do?

gopls with fieldalignment analyzer enabled "ui.diagnostic.analyses": { "fieldalignment": true }

type X struct {
	a time.Time
	b byte
	c int32
	e byte
}

What did you expect to see?

fieldalignment diagnostic message with correct struct size (40 according to unsafe.Sizeof).

What did you see instead?

diagnostic message with incorrect size info

	"owner": "_generated_diagnostic_collection_name_#1",
	"severity": 4,
	"message": "struct of size 12 could be 8",
	"source": "fieldalignment",
@gopherbot gopherbot added Tools gopls labels Feb 4, 2022
@gopherbot gopherbot added this to the Unreleased milestone Feb 4, 2022
@findleyr
Copy link
Contributor

@findleyr findleyr commented Feb 4, 2022

This is a consequence of AST trimming that gopls does to reduce memory. There are other similar issues (for example #50196).

IIRC AST trimming provides modest but not major benefit to most users (~25% memory reduction). I am not sure that is worth the loss in precision. I would like to remove our AST trimming in favor of teaching gopls to load fewer packages, but have hesitated to simply remove it before we have offsetting optimizations. Maybe we should.

@findleyr findleyr removed this from the Unreleased milestone Feb 7, 2022
@findleyr findleyr added this to the gopls/on-deck milestone Feb 7, 2022
@findleyr findleyr added the gopls/analysis label Apr 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls/analysis gopls Tools
Projects
None yet
Development

No branches or pull requests

3 participants