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

cmd/go: list confuses imports #66218

Closed
rsc opened this issue Mar 9, 2024 · 12 comments
Closed

cmd/go: list confuses imports #66218

rsc opened this issue Mar 9, 2024 · 12 comments
Assignees
Labels
GoCommand cmd/go NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Milestone

Comments

@rsc
Copy link
Contributor

rsc commented Mar 9, 2024

go list std cmd should show information about the standard math/rand package, but it seems to only show information for math/rand compiled for cmd/compile, or at least with dependencies compiled for cmd/compile.

This bug appears to have been introduced between Go 1.20 and Go 1.21.0. I have not bisected further.

% go list -f '{{.Dir}} {{.Imports}}' std |grep /src/math/rand
/Users/rsc/go/src/math/rand [internal/godebug math sync sync/atomic unsafe]
/Users/rsc/go/src/math/rand/v2 [errors internal/chacha8rand math math/bits unsafe]
% go list -f '{{.Dir}} {{.Imports}}' std cmd |grep /src/math/rand 
/Users/rsc/go/src/math/rand [internal/godebug [cmd/compile] math [cmd/compile] sync [cmd/compile] sync/atomic [cmd/compile] unsafe [cmd/compile]]
/Users/rsc/go/src/math/rand/v2 [errors internal/chacha8rand math math/bits unsafe]
% 
@rsc rsc added NeedsFix The path to resolution is known, but the work has not been done. release-blocker labels Mar 9, 2024
@rsc rsc added this to the Go1.23 milestone Mar 9, 2024
@adonovan
Copy link
Member

@findleyr I wonder whether this is the source of a number of the metadata inconsistency problems we've been seeing in gopls.

@timothy-king
Copy link
Contributor

I also wonder whether this is related to the various ssa panics that go away when compiling with 1.22 (#65608). That could be explained by a go list inconsistency for a package.

@findleyr
Copy link
Contributor

findleyr commented Mar 11, 2024

@adonovan while it does look like there's a bug in cmd/go, I believe for this specific case we won't encounter that bug in go/packages as we disabled PGO in go list in https://go.dev/issue/60456.

@bcmills bcmills added the GoCommand cmd/go label Mar 11, 2024
@aclements
Copy link
Member

It does seem quite likely this is related to PGO.

@aclements
Copy link
Member

git checkout go1.21.0 && git qbisect --from go1.20 --setup ./make.bash zsh -c "go list -f '{{.Dir}} {{.Imports}}' std cmd |grep /src/math/rand | grep 'math sync'" says 45b74d2, which confirms PGO, but otherwise isn't very helpful.

@thanm
Copy link
Contributor

thanm commented Mar 27, 2024

Wondering what is happening with this bug (during weekly release checkin meeting). Any updates?

@matloob matloob self-assigned this Apr 29, 2024
@dmitshur
Copy link
Contributor

@matloob Are there updates on this? This is currently a blocker for Go 1.23 RC 1. Is this important enough to be considered a release blocker for Go 1.23?

@matloob
Copy link
Contributor

matloob commented May 15, 2024

No updates yet. I plan to look at this next week.

@cagedmantis
Copy link
Contributor

@matloob Is there is status update on this issue? This came up in the release meeting.

@matloob
Copy link
Contributor

matloob commented May 22, 2024

Not yet. I plan to start looking tomorrow.

@matloob
Copy link
Contributor

matloob commented May 24, 2024

So it looks like what's happening is that while when we split off the pgo variant of a package, while we clone the Internal.Imports slice so that the actual import links between packages are different, we don't do the same thing for the (non-internal) Imports field. See

p1.Internal.Imports = slices.Clone(p.Internal.Imports)
for where the split is done.

The split code is does the following

	p1 := new(Package)
	*p1 = *p
	p1.Internal.Imports = slices.Clone(p.Internal.Imports)
	p1.Internal.ForMain = pmain.ImportPath

where p is the original package. So the slices point to the same arrays and other pointers in p at the time of the split are shared.

So the pgo and non pgo variants share the same (PackagePublic) Imports slice. When the list code updates the package public Imports, it then ends up modifying the original too.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/588275 mentions this issue: cmd/go/internal/load: clone pgo variant's PackagePublic.Imports in split

@dmitshur dmitshur added the FixPending Issues that have a fix which has not yet been reviewed or submitted. label May 24, 2024
@matloob matloob removed NeedsFix The path to resolution is known, but the work has not been done. FixPending Issues that have a fix which has not yet been reviewed or submitted. labels May 28, 2024
@dmitshur dmitshur added the NeedsFix The path to resolution is known, but the work has not been done. label May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand cmd/go NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Projects
None yet
Development

No branches or pull requests