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/go/packages: Unexpected package creation during export data loading (load generic package) #51629

Closed
tsh96 opened this issue Mar 12, 2022 · 8 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@tsh96
Copy link

tsh96 commented Mar 12, 2022

What version of Go are you using (go version)?

$ go version
go version go1.18 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/vscode/.cache/go-build"
GOENV="/home/vscode/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.18"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/workspace/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2277327549=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Load type and type info from a generic package.

github repo: https://github.com/tsh96/reproducing-go-generic-load-packages-error

main.go

package main

import (
	_ "github.com/tsh96/reproducing-go-generic-load-packages-error/g"

	"golang.org/x/tools/go/packages"
)

func main() {
	mode := packages.NeedTypes | packages.NeedTypesInfo
	packages.Load(&packages.Config{Mode: mode}, ".")
}

g/util.go

package g

type A[T any] struct{}

func NewA[T any]() *A[T] { return new(A[T]) }

func NewIntA() *A[int] { return NewA[int]() } // <-- This line is triggering the issue

go.mod

module github.com/tsh96/reproducing-go-generic-load-packages-error

go 1.18

require golang.org/x/tools v0.1.11-0.20220325212234-e693fb417253

require (
	golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect
	golang.org/x/sys v0.0.0-20220325203850-36772127a21f // indirect
	golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
)

What did you expect to see?

Nothing, success.

What did you see instead?

$ go run .
2022/03/26 02:31:45 golang.org/x/tools/go/packages: unexpected new packages during load of github.com/tsh96/reproducing-go-generic-load-packages-error/g
panic: golang.org/x/tools/go/packages: unexpected new packages during load of github.com/tsh96/reproducing-go-generic-load-packages-error/g

goroutine 21 [running]:
log.Panicf({0x63e7ca?, 0x3d?}, {0xc00005dbb0?, 0xc0000773b0?, 0xc0000b6200?})
        /usr/local/go/src/log/log.go:392 +0x67
golang.org/x/tools/go/packages.(*loader).loadFromExportData(0xc00013c000, 0xc0000b1f60)
        /workspace/vendor/golang.org/x/tools/go/packages/packages.go:1240 +0x4f7
golang.org/x/tools/go/packages.(*loader).loadPackage(0xc00013c000, 0xc0000b1f60)
        /workspace/vendor/golang.org/x/tools/go/packages/packages.go:864 +0x3aa
golang.org/x/tools/go/packages.(*loader).loadRecursive.func1()
        /workspace/vendor/golang.org/x/tools/go/packages/packages.go:829 +0x1a9
sync.(*Once).doSlow(0xc0001527a8?, 0x1?)
        /usr/local/go/src/sync/once.go:68 +0xc2
sync.(*Once).Do(...)
        /usr/local/go/src/sync/once.go:59
golang.org/x/tools/go/packages.(*loader).loadRecursive(0x43c085?, 0x0?)
        /workspace/vendor/golang.org/x/tools/go/packages/packages.go:817 +0x52
golang.org/x/tools/go/packages.(*loader).loadRecursive.func1.1(0x0?)
        /workspace/vendor/golang.org/x/tools/go/packages/packages.go:824 +0x2c
created by golang.org/x/tools/go/packages.(*loader).loadRecursive.func1
        /workspace/vendor/golang.org/x/tools/go/packages/packages.go:823 +0x8f
exit status 2

An unexpected package package named go.shape is added to the view after following line of code:
https://github.com/golang/tools/blob/198cae37294c48f180c54b9f66617d821e185fdc/go/packages/packages.go#L1209

@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Mar 12, 2022
@gopherbot gopherbot added this to the Unreleased milestone Mar 12, 2022
@heschi
Copy link
Contributor

heschi commented Mar 14, 2022

cc @matloob

@AlekSi
Copy link
Contributor

AlekSi commented Mar 17, 2022

Might be related to #45218.

danderson added a commit to tailscale/tailscale that referenced this issue Mar 17, 2022
Updates #4194

Signed-off-by: David Anderson <danderson@tailscale.com>
danderson added a commit to tailscale/tailscale that referenced this issue Mar 17, 2022
honk
Updates #4194

Signed-off-by: David Anderson <danderson@tailscale.com>
danderson added a commit to tailscale/tailscale that referenced this issue Mar 17, 2022
Updates #4194

Signed-off-by: David Anderson <danderson@tailscale.com>
danderson added a commit to tailscale/tailscale that referenced this issue Mar 17, 2022
Updates #4194

Signed-off-by: David Anderson <danderson@tailscale.com>
danderson added a commit to tailscale/tailscale that referenced this issue Mar 17, 2022
Incidentally, simplify the go generate CI workflow, by
marking the dnsfallback update non-hermetic (so CI will
skip it) rather than manually filter it out of `go list`.

Updates #4194

Signed-off-by: David Anderson <danderson@tailscale.com>
danderson added a commit to tailscale/tailscale that referenced this issue Mar 17, 2022
Incidentally, simplify the go generate CI workflow, by
marking the dnsfallback update non-hermetic (so CI will
skip it) rather than manually filter it out of `go list`.

Updates #4194

Signed-off-by: David Anderson <danderson@tailscale.com>
danderson added a commit to tailscale/tailscale that referenced this issue Mar 17, 2022
Incidentally, simplify the go generate CI workflow, by
marking the dnsfallback update non-hermetic (so CI will
skip it) rather than manually filter it out of `go list`.

Updates #4194

Signed-off-by: David Anderson <danderson@tailscale.com>
danderson added a commit to tailscale/tailscale that referenced this issue Mar 17, 2022
Incidentally, simplify the go generate CI workflow, by
marking the dnsfallback update non-hermetic (so CI will
skip it) rather than manually filter it out of `go list`.

Updates #4194

Signed-off-by: David Anderson <danderson@tailscale.com>
danderson added a commit to tailscale/tailscale that referenced this issue Mar 18, 2022
Incidentally, simplify the go generate CI workflow, by
marking the dnsfallback update non-hermetic (so CI will
skip it) rather than manually filter it out of `go list`.

Updates #4194

Signed-off-by: David Anderson <danderson@tailscale.com>
@cschneider4711
Copy link

cschneider4711 commented Mar 26, 2022

Had a similar panic when running gosec action during GitHub workflow on a 1.18 project:

2022/03/26 16:52:29 Unexpected package creation during export data loading

@powerman
Copy link

Same issue when using //go:generate stringer ... in package which uses generics.

@powerman
Copy link

Same issue when using //go:generate stringer ... in package which uses generics.

I've found workaround for this issue: reillywatson/tools@50e5cab
If applied to latest master of golang.org/x/tools it fixes issue with stringer.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/400034 mentions this issue: go/packages: make loadFromExportData ignore go.shape

bradfitz added a commit to tailscale/tailscale that referenced this issue Apr 13, 2022
bradfitz added a commit to tailscale/tailscale that referenced this issue Apr 13, 2022
This reverts commit 2a412ac.

Updates #4194

Change-Id: I0098b66b71d20bea301ca79058c1cdd201237dd0
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
bradfitz added a commit to tailscale/tailscale that referenced this issue Apr 13, 2022
This reverts commit 2a412ac.

Updates #4194

Change-Id: I0098b66b71d20bea301ca79058c1cdd201237dd0
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
@oliverdain
Copy link

It looks like this has been fixed which is why this is marked closed. However, there isn't yet a release with this fix. Can we expect a new release tag soon so we don't have to build our own stringer to get things working?

cruickshankpg pushed a commit to cruickshankpg/mockery that referenced this issue May 4, 2022
cruickshankpg pushed a commit to cruickshankpg/mockery that referenced this issue May 13, 2022
cruickshankpg pushed a commit to cruickshankpg/mockery that referenced this issue May 17, 2022
LandonTClipp pushed a commit to cruickshankpg/mockery that referenced this issue May 24, 2022
tgorham4 added a commit to convictional/gosec that referenced this issue May 24, 2022
tgorham4 added a commit to convictional/gosec that referenced this issue May 24, 2022
ccojocar pushed a commit to securego/gosec that referenced this issue May 29, 2022
dstrelau added a commit to dstrelau/go-ruleguard that referenced this issue Jul 29, 2022
quasilyte pushed a commit to quasilyte/go-ruleguard that referenced this issue Jul 30, 2022
@gurkanguray
Copy link

gurkanguray commented Jan 24, 2023

This issue has been closed, but still facing the same issue when using //go:generate stringer with the latest release golang.org/x/tools v0.5.0

@golang golang locked and limited conversation to collaborators Jan 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

8 participants