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/compile/internal/types: types.Type.LinkString has collisions for anonymous struct types with blank fields #47087

Closed
OneOfOne opened this issue Jul 7, 2021 · 9 comments

Comments

@OneOfOne
Copy link
Contributor

OneOfOne commented Jul 7, 2021

I know the branch is under heavy development, but I've been using it with GOEXPERIMENT=unified for multiple projects and it works fine.

Today I was working on an old (massive) code base and I got this error, there are no generics involved.

Unsetting GOEXPERIMENT fixes the issue.

Tagging @mdempsky since I know IR is his baby, I'll try to work on a reproducer, as far as I can tell it's related to google.golang.org/genproto/googleapis/cloud/asset/v1 but I still can't have a small repro.

❯ go test -v
# xxx [xxx.test]
<unknown line number>: internal compiler error: collision: types struct { _ struct {} "type:\"structure\"" } and struct { _ struct {} "type:\"structure\"" } have short string "struct { _ struct {} \"type:\\\"structure\\\"\" }"

goroutine 1 [running]:
runtime/debug.Stack()
        /usr/src/go1.18/src/runtime/debug/stack.go:24 +0x65
cmd/compile/internal/base.FatalfAt({0x52117a0, 0xc0}, {0xcfe46d, 0x2f}, {0xc001fc56a8, 0x3, 0x3})
        /usr/src/go1.18/src/cmd/compile/internal/base/print.go:227 +0x154
cmd/compile/internal/base.Fatalf(...)
        /usr/src/go1.18/src/cmd/compile/internal/base/print.go:196
cmd/compile/internal/noder.(*reader).wrapTypes(0xc000bc1d40, 0xc0000cd320)
        /usr/src/go1.18/src/cmd/compile/internal/noder/reader.go:2081 +0x208
cmd/compile/internal/noder.unified({0xc000423b60, 0x0, 0x2})
        /usr/src/go1.18/src/cmd/compile/internal/noder/unified.go:143 +0x63c
cmd/compile/internal/noder.LoadPackage({0xc00001e270, 0x4, 0x0})
        /usr/src/go1.18/src/cmd/compile/internal/noder/noder.go:84 +0x38d
cmd/compile/internal/gc.Main(0xd0c198)
        /usr/src/go1.18/src/cmd/compile/internal/gc/main.go:193 +0xb13
main.main()
        /usr/src/go1.18/src/cmd/compile/main.go:55 +0xdd

FAIL    github.com/alpineiq/api/internal/domgr [build failed]
❯ go version; go env
go version devel go1.18-501725032c 2021-07-07 17:40:11 +0000 linux/amd64
GO111MODULE="auto"
GOARCH="amd64"
GOBIN="/home/oneofone/code/go/bin"
GOCACHE="/home/oneofone/.cache/go-build"
GOENV="/home/oneofone/.config/go/env"
GOEXE=""
GOEXPERIMENT="unified"
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/oneofone/code/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/oneofone/code/go"
GOPRIVATE=""
GOPROXY="direct"
GOROOT="/usr/src/go1.18"
GOSUMDB="off"
GOTMPDIR=""
GOTOOLDIR="/usr/src/go1.18/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="devel go1.18-501725032c 2021-07-07 17:40:11 +0000"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="xxx/go.mod"
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-build3950980313=/tmp/go-build -gno-record-gcc-switches"
@mdempsky mdempsky self-assigned this Jul 7, 2021
@mdempsky
Copy link
Member

mdempsky commented Jul 7, 2021

Thanks. I think I know how to repro and fix this. If you're able to provide instructions for me to repro your exact failure, that would be helpful. But otherwise, I might ask you to test a CL.

@OneOfOne
Copy link
Contributor Author

OneOfOne commented Jul 7, 2021

I'm swamped right now so I can't really work on the repro, but i'll gladly test the CL.

@mdempsky
Copy link
Member

mdempsky commented Jul 7, 2021

This is a pre-existing issue that types.Type.LinkString fails to package-qualify blank field names, leading to collisions in the linker names: https://play.golang.org/p/kdbwivysffs (should run successfully without panicking)

It manifested in GOEXPERIMENT=unified because I included an assertion to check that it's consistent with types.Identical, which it should be but is evidently not.

@mdempsky mdempsky changed the title cmd/compile: (dev.typeparams) <unknown line number>: internal compiler error: collision cmd/compile/internal/types: types.Type.LinkString has collisions for anonymous struct types with blank fields Jul 7, 2021
@gopherbot
Copy link

Change https://golang.org/cl/333162 mentions this issue: cmd/compile: optimize types.sconv

@gopherbot
Copy link

Change https://golang.org/cl/333161 mentions this issue: cmd/compile: extract pkgqual from symfmt

@gopherbot
Copy link

Change https://golang.org/cl/333163 mentions this issue: cmd/compile: remove special-casing of blank in types.sconv{,2}

gopherbot pushed a commit that referenced this issue Jul 7, 2021
The logic in symfmt for deciding how to package-qualify an identifier
is easily refactored into a separate function, loosely similar to
go/types.Qualifier's API.

Passes toolstash -cmp.

Updates #47087.

Change-Id: Ib3e7cc35a6577dc28df8eca79ba3457c48168e86
Reviewed-on: https://go-review.googlesource.com/c/go/+/333161
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
@mdempsky
Copy link
Member

mdempsky commented Jul 7, 2021

@OneOfOne I think https://go-review.googlesource.com/c/go/+/333166 should fix the issue. I'd appreciate if you could confirm that for me, thanks.

gopherbot pushed a commit that referenced this issue Jul 7, 2021
Now that symfmt is simpler, we can simply manually inline it into
sconv. Importantly, this allows us to avoid allocating a buffer +
writing a string + re-interning it when we don't need to qualify the
identifier.

Passes toolstash -cmp.

Updates #47087.

Change-Id: I47b57aef22301ba242556a645346f478f0c1a7d1
Reviewed-on: https://go-review.googlesource.com/c/go/+/333162
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
@OneOfOne
Copy link
Contributor Author

OneOfOne commented Jul 7, 2021

Yep, I can confirm that CL fixed it, thank you!

I feel like a kid waiting to open their christmas presents.

@mdempsky
Copy link
Member

mdempsky commented Jul 7, 2021

@OneOfOne Great, thank you for filing the issue and the quick test report.

@golang golang locked and limited conversation to collaborators Jun 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants