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

go/types, types2: panic: infinite recursion in unification with go1.21.0 #61879

Closed
LAShZ opened this issue Aug 9, 2023 · 27 comments
Closed

go/types, types2: panic: infinite recursion in unification with go1.21.0 #61879

LAShZ opened this issue Aug 9, 2023 · 27 comments
Assignees
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. NeedsFix The path to resolution is known, but the work has not been done. release-blocker Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@LAShZ
Copy link

LAShZ commented Aug 9, 2023

gopls version

golang.org/x/tools/gopls v0.13.1
    golang.org/x/tools/gopls@v0.13.1 h1:Q0cfPbEG1WVfgxcRZ9uKTA6/ckIRNXx6Ym7KgT/VFE4=

go env

GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/lavch/Library/Caches/go-build'
GOENV='/Users/lavch/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/lavch/go/pkg/mod'
GOOS='darwin'
GOPATH='/Users/lavch/go'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.google.cn'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.21.0'
GCCGO='gccgo'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='0'
GOMOD='/Users/lavch/repo/work/orm/base/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/6d/3ws4l1qx5jn9crwf_j_1x2hw0000gp/T/go-build531596626=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

Updagrade go version to 1.21.0,and upgrade gopls to v0.13.1

What did you expect to see?

gopls function normally

What did you see instead?

gopls panic

Editor and settings

VSCode

"gopls": {
        // "build.expandWorkspaceToModule": true,
        // "build.experimentalWorkspaceModule": true,
        "ui.semanticTokens": true
}

Logs

[Info  - 11:00:24] 
true
[Info  - 11:00:24] 2023/08/09 11:00:24 go info for /Users/lavch/repo/work/orm/base
(go dir /Users/lavch/repo/work/orm/base)
(go version go version go1.21.0 darwin/arm64)
(valid build configuration = true)
(build flags: [])
(selected go env: [GO111MODULE=, GOCACHE=/Users/lavch/Library/Caches/go-build, GOFLAGS=, GOMODCACHE=/Users/lavch/go/pkg/mod, GOPATH=/Users/lavch/go, GOPRIVATE=*.everphoto.cn,git.smartisan.com, GOROOT=/usr/local/go, GOWORK=])


[Info  - 11:00:25] 2023/08/09 11:00:25 go/packages.Load #1
	snapshot=0
	directory=file:///Users/lavch/repo/work/orm/base
	query=[/Users/lavch/repo/work/orm/base/... builtin]
	packages=216

[Info  - 11:00:25] 2023/08/09 11:00:25 go/packages.Load #1: updating metadata for 2307 packages

panic: unification reached recursion depth limit
	panic: unification reached recursion depth limit
	panic: unification reached recursion depth limit [recovered]
	panic: unification reached recursion depth limit

goroutine 19762 [running]:
go/types.(*Checker).handleBailout(0x14074a750e0, 0x1407ed3f568)
	/usr/local/go/src/go/types/check.go:336 +0x9c
panic({0x102e97de0?, 0x102ff3cb0?})
	/usr/local/go/src/runtime/panic.go:914 +0x218
go/types.(*unifier).nify(0x1407e89ca70, {0x102ff85c8, 0x1407e89fe40}, {0x102ff85c8, 0x1407e89e800}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:311 +0x1770
go/types.(*unifier).nify(0x1407e89ca70, {0x102ff8550, 0x140781bd500}, {0x102ff8550, 0x140781bd3b0}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:510 +0x1724
go/types.(*unifier).nify(0x1407e89ca70, {0x102ff8a50, 0x1407e3f3338}, {0x102ff8a50, 0x1407e3f3728}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:615 +0x1338
go/types.(*unifier).nify(0x1407e89ca70, {0x102ff85c8, 0x1407e89e880}, {0x102ff85c8, 0x1407e89fec0}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:633 +0xb5c
go/types.(*unifier).nify(0x1407e89ca70, {0x102ff8550, 0x140781bd3b0}, {0x102ff8550, 0x140781bd500}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:510 +0x1724
go/types.(*unifier).nify(0x1407e89ca70, {0x102ff8a50, 0x1407e3f3728}, {0x102ff8a50, 0x1407e3f3338}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:615 +0x1338
go/types.(*unifier).nify(0x1407e89ca70, {0x102ff85c8, 0x1407e89fec0}, {0x102ff85c8, 0x1407e89e880}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:633 +0xb5c
go/types.(*unifier).nify(0x1407e89ca70, {0x102ff8550, 0x140781bd500}, {0x102ff8550, 0x140781bd3b0}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:510 +0x1724
go/types.(*unifier).nify(0x1407e89ca70, {0x102ff8a50, 0x1407e3f3338}, {0x102ff8a50, 0x1407e3f3728}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:615 +0x1338
go/types.(*unifier).nify(0x1407e89ca70, {0x102ff85c8, 0x1407e89e880}, {0x102ff85c8, 0x1407e89fec0}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:633 +0xb5c
go/types.(*unifier).nify(0x1407e89ca70, {0x102ff8550, 0x140781bd3b0}, {0x102ff8550, 0x140781bd500}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:510 +0x1724
go/types.(*unifier).nify(0x1407e89ca70, {0x102ff8a50, 0x1407e3f3728}, {0x102ff8a50, 0x1407e3f3338}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:615 +0x1338
go/types.(*unifier).nify(0x1407e89ca70, {0x102ff85c8, 0x1407e89fec0}, {0x102ff85c8, 0x1407e89e880}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:633 +0xb5c
go/types.(*unifier).nify(0x1407e89ca70, {0x102ff8550, 0x140781bd500}, {0x102ff8550, 0x140781bd3b0}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:510 +0x1724
go/types.(*unifier).nify(0x1407e89ca70, {0x102ff8a50, 0x1407e3f3338}, {0x102ff8a50, 0x1407e3f3728}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:615 +0x1338
go/types.(*unifier).nify(0x1407e89ca70, {0x102ff85c8, 0x1407e89e880}, {0x102ff85c8, 0x1407e89fec0}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:633 +0xb5c
go/types.(*unifier).nify(0x1407e89ca70, {0x102ff8550, 0x140781bd3b0}, {0x102ff8550, 0x140781bd500}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:510 +0x1724
go/types.(*unifier).nify(0x1407e89ca70, {0x102ff8a50, 0x1407e3f3728}, {0x102ff8a50, 0x1407e3f3338}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:615 +0x1338
go/types.(*unifier).nify(0x1407e89ca70, {0x102ff85c8, 0x1407e89fec0}, {0x102ff85c8, 0x1407e89e880}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:633 +0xb5c
go/types.(*unifier).nify(0x1407e89ca70, {0x102ff8550, 0x140781bd500}, {0x102ff8550, 0x140781bd3b0}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:510 +0x1724
go/types.(*unifier).nify(0x1407e89ca70, {0x102ff8a50, 0x1407e3f3338}, {0x102ff8a50, 0x1407e3f3728}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:615 +0x1338
go/types.(*unifier).nify(0x1407e89ca70, {0x102ff85c8, 0x1407e89e880}, {0x102ff85c8, 0x1407e89fec0}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:633 +0xb5c
go/types.(*unifier).nify(0x1407e89ca70, {0x102ff8550, 0x140781bd3b0}, {0x102ff8550, 0x140781bd500}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:510 +0x1724
go/types.(*unifier).nify(0x1407e89ca70, {0x102ff8a50, 0x1407e3f3728}, {0x102ff8a50, 0x1407e3f3338}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:615 +0x1338
go/types.(*unifier).nify(0x1407e89ca70, {0x102ff85c8, 0x1407e89fec0}, {0x102ff85c8, 0x1407e89e880}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:633 +0xb5c
go/types.(*unifier).nify(0x1407e89ca70, {0x102ff8550, 0x140781bd500}, {0x102ff8550, 0x140781bd3b0}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:510 +0x1724
go/types.(*unifier).nify(0x1407e89ca70, {0x102ff8a50, 0x1407e3f3338}, {0x102ff8a50, 0x1407e3f3728}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:615 +0x1338
go/types.(*unifier).nify(0x1407e89ca70, {0x102ff85c8, 0x1407e89e880}, {0x102ff85c8, 0x1407e89fec0}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:633 +0xb5c
go/types.(*unifier).nify(0x1407e89ca70, {0x102ff8550, 0x140781bd3b0}, {0x102ff8550, 0x140781bd500}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:510 +0x1724
go/types.(*unifier).nify(0x1407e89ca70, {0x102ff8a50, 0x1407e3f3728}, {0x102ff8a50, 0x1407e3f3338}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:615 +0x1338
go/types.(*unifier).nify(0x1407e89ca70, {0x102ff85c8, 0x1407e89fec0}, {0x102ff85c8, 0x1407e89e880}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:633 +0xb5c
go/types.(*unifier).nify(0x1407e89ca70, {0x102ff8550, 0x140781bd500}, {0x102ff8550, 0x140781bd3b0}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:510 +0x1724
go/types.(*unifier).nify(0x1407e89ca70, {0x102ff8a50, 0x1407e3f3338}, {0x102ff8a50, 0x1407e3f3728}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:615 +0x1338
go/types.(*unifier).nify(0x1407e89ca70, {0x102ff85c8, 0x1407e89e880}, {0x102ff85c8, 0x1407e89fec0}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:633 +0xb5c
go/types.(*unifier).nify(0x1407e89ca70, {0x102ff8550, 0x140781bd3b0}, {0x102ff8550, 0x140781bd500}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:510 +0x1724
go/types.(*unifier).nify(0x1407e89ca70, {0x102ff8a50, 0x1407e3f3728}, {0x102ff8a50, 0x1407e3f3338}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:615 +0x1338
go/types.(*unifier).nify(0x1407e89ca70, {0x102ff85c8, 0x1407e89fec0}, {0x102ff85c8, 0x1407e89e880}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:633 +0xb5c
go/types.(*unifier).nify(0x1407e89ca70, {0x102ff8550, 0x140781bd500}, {0x102ff8550, 0x140781bd3b0}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:510 +0x1724
go/types.(*unifier).nify(0x1407e89ca70, {0x102ff8a50, 0x1407e3f3338}, {0x102ff8a50, 0x1407e3f3728}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:615 +0x1338
go/types.(*unifier).nify(0x1407e89ca70, {0x102ff85c8, 0x1407e89e880}, {0x102ff85c8, 0x1407e89fec0}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:633 +0xb5c
go/types.(*unifier).nify(0x1407e89ca70, {0x102ff8550, 0x140781bd3b0}, {0x102ff8550, 0x140781bd500}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:510 +0x1724
go/types.(*unifier).nify(0x1407e89ca70, {0x102ff8a50, 0x1407e3f3728}, {0x102ff8a50, 0x1407e3f3338}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:615 +0x1338
go/types.(*unifier).nify(0x1407e89ca70, {0x102ff85c8, 0x1407e89fec0}, {0x102ff85c8, 0x1407e89e880}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:633 +0xb5c
go/types.(*unifier).nify(0x1407e89ca70, {0x102ff8550, 0x140781bd500}, {0x102ff8550, 0x140781bd3b0}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:510 +0x1724
go/types.(*unifier).nify(0x1407e89ca70, {0x102ff8a50, 0x1407e3f3338}, {0x102ff8a50, 0x1407e3f3728}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:615 +0x1338
go/types.(*unifier).nify(0x1407e89ca70, {0x102ff85c8, 0x1407e89e880}, {0x102ff85c8, 0x1407e89fec0}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:633 +0xb5c
go/types.(*unifier).nify(0x1407e89ca70, {0x102ff8550, 0x140781bd3b0}, {0x102ff8550, 0x140781bd500}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:510 +0x1724
go/types.(*unifier).nify(0x1407e89ca70, {0x102ff8a50, 0x1407e3f3728}, {0x102ff8a50, 0x1407e3f3338}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:615 +0x1338
...112 frames elided...
go/types.(*unifier).nify(0x1407e89c730, {0x102ff85c8, 0x1407e89f5c0}, {0x102ff85c8, 0x1407e89e880}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:633 +0xb5c
go/types.(*unifier).nify(0x1407e89c730, {0x102ff8550, 0x140781bd420}, {0x102ff8550, 0x140781bd3b0}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:510 +0x1724
go/types.(*unifier).nify(0x1407e89c730, {0x102ff8a50, 0x1407e3f3338}, {0x102ff8a50, 0x1407e3f3548}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:615 +0x1338
go/types.(*unifier).nify(0x1407e89c730, {0x102ff85c8, 0x1407e89e880}, {0x102ff85c8, 0x1407e89f5c0}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:633 +0xb5c
go/types.(*unifier).nify(0x1407e89c730, {0x102ff8550, 0x140781bd3b0}, {0x102ff8550, 0x140781bd420}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:510 +0x1724
go/types.(*unifier).nify(0x1407e89c730, {0x102ff8a50, 0x1407e3f3548}, {0x102ff8a50, 0x1407e3f3338}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:615 +0x1338
go/types.(*unifier).nify(0x1407e89c730, {0x102ff85c8, 0x1407e89f5c0}, {0x102ff85c8, 0x1407e89e880}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:633 +0xb5c
go/types.(*unifier).nify(0x1407e89c730, {0x102ff8550, 0x140781bd420}, {0x102ff8550, 0x140781bd3b0}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:510 +0x1724
go/types.(*unifier).nify(0x1407e89c730, {0x102ff8a50, 0x1407e3f3338}, {0x102ff8a50, 0x1407e3f3548}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:615 +0x1338
go/types.(*unifier).nify(0x1407e89c730, {0x102ff85c8, 0x1407e89e880}, {0x102ff85c8, 0x1407e89f5c0}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:633 +0xb5c
go/types.(*unifier).nify(0x1407e89c730, {0x102ff8550, 0x140781bd3b0}, {0x102ff8550, 0x140781bd420}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:510 +0x1724
go/types.(*unifier).nify(0x1407e89c730, {0x102ff8a50, 0x1407e3f3548}, {0x102ff8a50, 0x1407e3f3338}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:615 +0x1338
go/types.(*unifier).nify(0x1407e89c730, {0x102ff85c8, 0x1407e89f5c0}, {0x102ff85c8, 0x1407e89e880}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:633 +0xb5c
go/types.(*unifier).nify(0x1407e89c730, {0x102ff8550, 0x140781bd420}, {0x102ff8550, 0x140781bd3b0}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:510 +0x1724
go/types.(*unifier).nify(0x1407e89c730, {0x102ff8a50, 0x1407e3f3338}, {0x102ff8a50, 0x1407e3f3548}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:615 +0x1338
go/types.(*unifier).nify(0x1407e89c730, {0x102ff85c8, 0x1407e89e880}, {0x102ff85c8, 0x1407e89f5c0}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:633 +0xb5c
go/types.(*unifier).nify(0x1407e89c730, {0x102ff8550, 0x140781bd3b0}, {0x102ff8550, 0x140781bd420}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:510 +0x1724
go/types.(*unifier).nify(0x1407e89c730, {0x102ff8a50, 0x1407e3f3548}, {0x102ff8a50, 0x1407e3f3338}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:615 +0x1338
go/types.(*unifier).nify(0x1407e89c730, {0x102ff85c8, 0x1407e89f5c0}, {0x102ff85c8, 0x1407e89e880}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:633 +0xb5c
go/types.(*unifier).nify(0x1407e89c730, {0x102ff8550, 0x140781bd420}, {0x102ff8550, 0x140781bd3b0}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:510 +0x1724
go/types.(*unifier).nify(0x1407e89c730, {0x102ff8bb8, 0x1407e3bd4c0}, {0x102ff8bb8, 0x1407e3bd5c0}, 0x0, 0x0)
	/usr/local/go/src/go/types/unify.go:701 +0xcf8
go/types.(*unifier).unify(...)
	/usr/local/go/src/go/types/unify.go:147
go/types.(*Checker).infer(0x14074a750e0, {0x102ff6468, 0x14075bd53c0}, {0x1407e3f34b8?, 0x3, 0x3}, {0x1407e89f380, 0x3, 0x4}, 0x1407e3f3518, ...)
	/usr/local/go/src/go/types/infer.go:235 +0x788
go/types.(*Checker).arguments(0x14074a750e0, 0x14075bd53c0, 0x1401536f800, {0x0, 0x0, 0x0}, {0x0, 0x0, 0x0}, {0x1407e89c620?, ...}, ...)
	/usr/local/go/src/go/types/call.go:606 +0xd68
go/types.(*Checker).callExpr(0x14074a750e0, 0x1407e89f240, 0x14075bd53c0)
	/usr/local/go/src/go/types/call.go:302 +0x6a4
go/types.(*Checker).exprInternal(0x14074a750e0, {0x0, 0x0}, 0x1407e89f240, {0x102ffb660, 0x14075bd53c0?}, {0x0?, 0x0?})
	/usr/local/go/src/go/types/expr.go:1359 +0x12dc
go/types.(*Checker).rawExpr(0x14074a750e0, {0x0, 0x0}, 0x1407e89f240, {0x102ffb660?, 0x14075bd53c0?}, {0x0?, 0x0?}, 0x0)
	/usr/local/go/src/go/types/expr.go:965 +0x134
go/types.(*Checker).multiExpr(0x14066ff8018?, {0x102ffb660?, 0x14075bd53c0}, 0x0)
	/usr/local/go/src/go/types/expr.go:1517 +0x68
go/types.(*Checker).initVars(0x0?, {0x1407e8aa108?, 0x1, 0x1}, {0x14075bcc940?, 0x1, 0x1}, {0x102ffb6f0, 0x14075bd7ac0})
	/usr/local/go/src/go/types/assignments.go:398 +0x100
go/types.(*Checker).stmt(0x14074a750e0, 0x0, {0x102ffb6f0?, 0x14075bd7ac0?})
	/usr/local/go/src/go/types/stmt.go:527 +0xfd8
go/types.(*Checker).stmtList(0x0?, 0x0, {0x14075bcc950?, 0x1025aa964?, 0x14066ff8fe8?})
	/usr/local/go/src/go/types/stmt.go:124 +0x88
go/types.(*Checker).funcBody(0x14074a750e0, 0x140387f48a0, {0x102ba6059?, 0x1400004acd0?}, 0x1407e89f040, 0x14075bd8660, {0x0, 0x0})
	/usr/local/go/src/go/types/stmt.go:44 +0x244
go/types.(*Checker).exprInternal.func1()
	/usr/local/go/src/go/types/expr.go:1073 +0x44
go/types.(*Checker).processDelayed(0x14074a750e0, 0xd8f)
	/usr/local/go/src/go/types/check.go:439 +0x12c
go/types.(*Checker).shortVarDecl(0x14074a750e0, {0x102ff6048, 0x1407e38f308}, {0x14075bcc900, 0x1, 0x102ff8870?}, {0x14075bcc980?, 0x1, 0x1})
	/usr/local/go/src/go/types/assignments.go:549 +0x8b8
go/types.(*Checker).stmt(0x14074a750e0, 0x0, {0x102ffb780?, 0x14075bd54c0?})
	/usr/local/go/src/go/types/stmt.go:476 +0xb70
go/types.(*Checker).simpleStmt(...)
	/usr/local/go/src/go/types/stmt.go:102
go/types.(*Checker).stmt(0x14074a750e0, 0x0, {0x102ffb630?, 0x14075bd55c0?})
	/usr/local/go/src/go/types/stmt.go:571 +0x12e4
go/types.(*Checker).stmtList(0x14038aba060?, 0x0, {0x140758b3200?, 0x0?, 0x8?})
	/usr/local/go/src/go/types/stmt.go:124 +0x88
go/types.(*Checker).funcBody(0x14074a750e0, 0x140387f48a0, {0x14075b98ee8?, 0x14020d9d090?}, 0x1407cec3700, 0x14075bd8840, {0x0, 0x0})
	/usr/local/go/src/go/types/stmt.go:44 +0x244
go/types.(*Checker).funcDecl.func1()
	/usr/local/go/src/go/types/decl.go:826 +0x44
go/types.(*Checker).processDelayed(0x14074a750e0, 0x0)
	/usr/local/go/src/go/types/check.go:439 +0x12c
go/types.(*Checker).checkFiles(0x14074a750e0, {0x1407aab0200, 0x17, 0x20})
	/usr/local/go/src/go/types/check.go:383 +0x1fc
go/types.(*Checker).Files(...)
	/usr/local/go/src/go/types/check.go:341
golang.org/x/tools/gopls/internal/lsp/cache.doTypeCheck({0x102ffccc8, 0x14075134780}, 0x1403fc47f80, {{0x14001c12540, 0x20}, {0x14001c12540, 0x20}, {0x14001bf4c3c, 0x4}, {0x140002c3380, ...}, ...})
	/Users/lavch/go/pkg/mod/golang.org/x/tools/gopls@v0.13.1/internal/lsp/cache/check.go:1559 +0x6d8
golang.org/x/tools/gopls/internal/lsp/cache.typeCheckImpl({0x102ffccc8, 0x14075134600}, 0x1023bc390?, {{0x14001c12540, 0x20}, {0x14001c12540, 0x20}, {0x14001bf4c3c, 0x4}, {0x140002c3380, ...}, ...})
	/Users/lavch/go/pkg/mod/golang.org/x/tools/gopls@v0.13.1/internal/lsp/cache/check.go:1420 +0x16c
golang.org/x/tools/gopls/internal/lsp/cache.(*typeCheckBatch).checkPackage(0x14041e9cec8?, {0x102ffccc8, 0x14017859b30}, 0x14041564900)
	/Users/lavch/go/pkg/mod/golang.org/x/tools/gopls@v0.13.1/internal/lsp/cache/check.go:674 +0x184
golang.org/x/tools/gopls/internal/lsp/cache.(*typeCheckBatch).handleSyntaxPackage(0x1403fc47f80, {0x102ffccc8, 0x14017859b30}, 0x0?, {0x14001c12540, 0x20})
	/Users/lavch/go/pkg/mod/golang.org/x/tools/gopls@v0.13.1/internal/lsp/cache/check.go:532 +0x3e0
golang.org/x/tools/gopls/internal/lsp/cache.(*snapshot).forEachPackageInternal.func2()
	/Users/lavch/go/pkg/mod/golang.org/x/tools/gopls@v0.13.1/internal/lsp/cache/check.go:394 +0x34
golang.org/x/sync/errgroup.(*Group).Go.func1()
	/Users/lavch/go/pkg/mod/golang.org/x/sync@v0.3.0/errgroup/errgroup.go:75 +0x58
created by golang.org/x/sync/errgroup.(*Group).Go in goroutine 9176
	/Users/lavch/go/pkg/mod/golang.org/x/sync@v0.3.0/errgroup/errgroup.go:72 +0x98
[Error - 11:00:26] Connection to server got closed. Server will not be restarted.
@LAShZ LAShZ added gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. labels Aug 9, 2023
@gopherbot gopherbot added this to the Unreleased milestone Aug 9, 2023
@LAShZ
Copy link
Author

LAShZ commented Aug 9, 2023

after downgrade to gopls

golang.org/x/tools/gopls v0.12.4
    golang.org/x/tools/gopls@v0.12.4 h1:nce5etAamR46d9oNGxop1aRK5rDQ0NqcY/SHIcyfEKY=

this panic still occured, maybe go1.21.0 is the cause

@LAShZ
Copy link
Author

LAShZ commented Aug 9, 2023

After tying

  • go1.21.0 with gopls v0.13.1: panic
  • go1.21.0 with gopls v0.12.4: panic
  • go1.20.6 with gopls v0.13.1: success
  • go1.20.6 with gopls v0.12.4: success

I have confirmed that go1.21.0 should be blamed for this panic

@findleyr findleyr changed the title x/tools/gopls: panic: unification reached recursion depth limit,after upgrade to go1.21.0 go/types,x/tools/gopls: panic: unification reached recursion depth limit,after upgrade to go1.21.0 Aug 9, 2023
@findleyr
Copy link
Member

findleyr commented Aug 9, 2023

CC @griesemer

Can you share anything about the code being edited? Is this an open-source project? Does compilation succeed?

@findleyr findleyr added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Aug 9, 2023
@LAShZ
Copy link
Author

LAShZ commented Aug 9, 2023

Can you share anything about the code being edited?

Sorry, but this is not an open-source project yet and the project is quite large, so I can not share code that can reproduce this panic (Actually, I have not edit anything, only upgrade go && gopls). However, I have tried on several projects we are working on and panic occurs every time. (But in some small code snippets, I write for fun, gopls and go function normally)

Does compilation succeed?

In fact, our project depends on some pkg that can only be built between go1.16~go1.20, so I cannot confirm if the project can be built with go 1.21.0. However, with go 1.20.6, compilation was successful as expected.

@findleyr
Copy link
Member

In fact, our project depends on some pkg that can only be built between go1.16~go1.20

If the package can't be built by go1.21, that is a bug in go1.21? Perhaps it is the same bug as you report here? The compiler's type checker and gopls's type checker are kept in sync, so I would expect them both to have the same unification problem.

It would be extremely helpful if we could narrow down a reproducer. Could you try compiling different packages to see which fail? I can also create a CL in the Go repo that would print more information in this panic, but that would require that you re-build Go.

@LAShZ
Copy link
Author

LAShZ commented Aug 10, 2023

The reason why the package I mentioned can not be built by go1.21 is because it uses some JIT tricks and has build tags like +build !go1.16 go1.21, and that package is frugal if you're interested. I'm not sure whether this is relevant to the panic.

I can also create a CL in the Go repo that would print more information in this panic, but that would require that you re-build Go.

It would be ok if you want me to use some customized go version to get more information.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/518259 mentions this issue: go/types: add more detail to unification panic

@ttys3
Copy link

ttys3 commented Aug 11, 2023

https://go.dev/cl/518259 forget to add debug code to src/cmd/compile/internal/types2/unify.go

@findleyr
Copy link
Member

@ttys3 gopls doesn't depend on types2; that's only used for the compiler.

@LAShZ can you try with this CL? The easiest way to install go with that CL is to use gotip.

go install golang.org/dl/gotip@latest
gotip download 518259
gotip install golang.org/x/tools/gopls@latest

Then the unification panic should contain more detail, that can help us narrow down a reproducer.

@LAShZ

This comment was marked as outdated.

@findleyr
Copy link
Member

@LAShZ that is not the new panic message. Perhaps the gopls used by your editor is still the old version.

Can you check gopls -v version? The build info should indicate a devel version of Go.

@LAShZ

This comment was marked as duplicate.

@LAShZ
Copy link
Author

LAShZ commented Aug 11, 2023

gopls -v version output like this:

Build info
----------
golang.org/x/tools/gopls v0.13.1
    golang.org/x/tools/gopls@v0.13.1 h1:Q0cfPbEG1WVfgxcRZ9uKTA6/ckIRNXx6Ym7KgT/VFE4=
    github.com/BurntSushi/toml@v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=
    github.com/google/go-cmp@v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
    github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
    golang.org/x/exp@v0.0.0-20220722155223-a9213eeb770e h1:+WEEuIdZHnUeJJmEUjyYC2gfUMj69yZXw17EnHg/otA=
    golang.org/x/exp/typeparams@v0.0.0-20221212164502-fae10dda9338 h1:2O2DON6y3XMJiQRAS1UWU+54aec2uopH3x7MAiqGW6Y=
    golang.org/x/mod@v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc=
    golang.org/x/sync@v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
    golang.org/x/sys@v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
    golang.org/x/text@v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4=
    golang.org/x/tools@v0.11.2-0.20230801165449-23c7f589706c h1:YilyjKn3EDn6X+x+kP+4REeEtG3WeM52dJAr7AWzVrQ=
    golang.org/x/vuln@v0.0.0-20230110180137-6ad3e3d07815 h1:A9kONVi4+AnuOr1dopsibH6hLi1Huy54cbeJxnq4vmU=
    honnef.co/go/tools@v0.4.2 h1:6qXr+R5w+ktL5UkwEbPp+fEvfyoMPche6GkOpGHZcLc=
    mvdan.cc/gofumpt@v0.4.0 h1:JVf4NN1mIpHogBj7ABpgOyZc65/UUOkKQFkoURsz4MM=
    mvdan.cc/xurls/v2@v2.4.0 h1:tzxjVAj+wSBmDcF6zBB7/myTy3gX9xvi8Tyr28AuQgc=
go: go1.21.0

@findleyr
Copy link
Member

Aha, that's not the correct gopls.

Can you ensure your editor uses the version in /Users/lavch/sdk/gotip/bin (perhaps by modifying PATH, or by copying that gopls somewhere)?

@LAShZ
Copy link
Author

LAShZ commented Aug 11, 2023

I got you, after using the new go version, the gopls -v version output is:

----------
golang.org/x/tools/gopls v0.13.1
    golang.org/x/tools/gopls@v0.13.1 h1:Q0cfPbEG1WVfgxcRZ9uKTA6/ckIRNXx6Ym7KgT/VFE4=
    github.com/BurntSushi/toml@v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=
    github.com/google/go-cmp@v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
    github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
    golang.org/x/exp@v0.0.0-20220722155223-a9213eeb770e h1:+WEEuIdZHnUeJJmEUjyYC2gfUMj69yZXw17EnHg/otA=
    golang.org/x/exp/typeparams@v0.0.0-20221212164502-fae10dda9338 h1:2O2DON6y3XMJiQRAS1UWU+54aec2uopH3x7MAiqGW6Y=
    golang.org/x/mod@v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc=
    golang.org/x/sync@v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
    golang.org/x/sys@v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
    golang.org/x/text@v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4=
    golang.org/x/tools@v0.11.2-0.20230801165449-23c7f589706c h1:YilyjKn3EDn6X+x+kP+4REeEtG3WeM52dJAr7AWzVrQ=
    golang.org/x/vuln@v0.0.0-20230110180137-6ad3e3d07815 h1:A9kONVi4+AnuOr1dopsibH6hLi1Huy54cbeJxnq4vmU=
    honnef.co/go/tools@v0.4.2 h1:6qXr+R5w+ktL5UkwEbPp+fEvfyoMPche6GkOpGHZcLc=
    mvdan.cc/gofumpt@v0.4.0 h1:JVf4NN1mIpHogBj7ABpgOyZc65/UUOkKQFkoURsz4MM=
    mvdan.cc/xurls/v2@v2.4.0 h1:tzxjVAj+wSBmDcF6zBB7/myTy3gX9xvi8Tyr28AuQgc=
go: devel go1.22-f2bb141725 Thu Aug 10 13:37:03 2023 -0400

And I will paste the full gopls (server) log in gist: https://gist.github.com/LAShZ/8d6376cf84def98855c250766f16891c

@findleyr
Copy link
Member

Thanks. Those server logs still appear to be using the old version. Are you sure your editor is finding the right one?

You may also be able to reproduce the panic by simply running gopls stats from the repo root, using the correct gopls version.

@LAShZ
Copy link
Author

LAShZ commented Aug 11, 2023

With the output (go version go version devel go1.22-f2bb141725 Thu Aug 10 13:37:03 2023 -0400 darwin/arm64) in the panic log, and with the status dock in vscode, I think the editor is using the right go version.
image

You may also be able to reproduce the panic by simply running gopls stats from the repo root, using the correct gopls version.

Sadly, I only got the output like this:

Initializing workspace...     done (1.4854365s)
Gathering bug reports...      done (133.487083ms)
Querying memstats...          done (29.07225ms)
Querying workspace stats...   done (7.432583ms)
Collecting directory info...  done (20.014458ms)
{
  "BugReports": [],
  "CacheDir": "/Users/lavch/Library/Caches/gopls/0be686af",
  "DirStats": {
    "Files": 4681,
    "TestdataFiles": 0,
    "GoFiles": 478,
    "ModFiles": 1,
    "Dirs": 443
  },
  "GOARCH": "arm64",
  "GOOS": "darwin",
  "GOPLSCACHE": "",
  "GoVersion": "devel go1.22-f2bb141725 Thu Aug 10 13:37:03 2023 -0400",
  "GoplsVersion": "v0.13.1",
  "InitialWorkspaceLoadDuration": "1.4854365s",
  "MemStats": {
    "HeapAlloc": 486279496,
    "HeapInUse": 549511168,
    "TotalAlloc": 712216496
  },
  "WorkspaceStats": {
    "Files": {
      "Total": 10000,
      "Largest": 8431686,
      "Errs": 0
    },
    "Views": [
      {
        "GoCommandVersion": "devel go1.22-f2bb141725",
        "AllPackages": {
          "Packages": 2611,
          "LargestPackage": 141,
          "CompiledGoFiles": 10180,
          "Modules": 495
        },
        "WorkspacePackages": {
          "Packages": 128,
          "LargestPackage": 34,
          "CompiledGoFiles": 661,
          "Modules": 1
        },
        "Diagnostics": 0
      }
    ]
  }
}

So the problem might be caused by some package I depend on.

@LAShZ
Copy link
Author

LAShZ commented Aug 11, 2023

I have located the package that caused the panic. Let me try to provide a reproducer.

@LAShZ
Copy link
Author

LAShZ commented Aug 11, 2023

@findleyr Here is the reproducer

type InterfaceA[T comparable] interface {
	setData(string) InterfaceA[T]
}

type ImplA[T comparable] struct {
	data        string
	args        []any
}

func NewInterfaceA[T comparable](args ...any) InterfaceA[T] {
	return &ImplA[T]{
		data:        fmt.Sprintf("%v", args...),
		args:        args,
	}
}

func (k *ImplA[T]) setData(data string) InterfaceA[T] {
	k.data = data
	return k
}

func Foo[M ~map[InterfaceA[T]]V, T comparable, V any](m M) {
	// DO SOMETHING HERE
	return 
}

func Bar() {
	keys := make([]InterfaceA[int], 0, 10)
	m := make(map[InterfaceA[int]]int)
	for i := 0; i < 10; i++ {
		keys = append(keys, NewInterfaceA[int](i))
		m[keys[i]] = i
	}

	Foo(m)	// panic here
}

And I've noticed that although [T comparable] is never used in this snippet, it's neccessary to reproduce this panic

@findleyr
Copy link
Member

@LAShZ amazing! That also reproduces via playground compilation:
https://go.dev/play/p/S2M6Qm_ExrI

Huge thanks. Tracking down a reproducer is critical to fixing the compiler.

@findleyr findleyr changed the title go/types,x/tools/gopls: panic: unification reached recursion depth limit,after upgrade to go1.21.0 go/types, types2: panic: infinite recursion in unification with go1.21.0 Aug 11, 2023
@findleyr findleyr modified the milestones: Unreleased, Go1.21.1 Aug 11, 2023
@findleyr
Copy link
Member

@griesemer and I will try to fix this for Go1.21.1.

@gopherbot please backport this to 1.21. It is a new panic during type checking.

@gopherbot
Copy link
Contributor

Backport issue(s) opened: #61959 (for 1.21).

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases.

@ttys3
Copy link

ttys3 commented Aug 11, 2023

@ttys3 gopls doesn't depend on types2; that's only used for the compiler.

@LAShZ can you try with this CL? The easiest way to install go with that CL is to use gotip.

go install golang.org/dl/gotip@latest
gotip download 518259
gotip install golang.org/x/tools/gopls@latest

Then the unification panic should contain more detail, that can help us narrow down a reproducer.

@findleyr yes. gopls doesn't depend on types2.

we got an ICE. while using go 1.21 compile our program.

but I think it maybe the same to the gopls issue.

I patched src/cmd/compile/internal/types2/unify.go and confirmed that, it's an ICE

@griesemer
Copy link
Contributor

Simpler reproducer:

package p

type Interface[T any] interface {
	m(Interface[T])
}

func f[S []Interface[T], T any](S) {}

func _() {
	var s []Interface[int]
	f(s) // panic here
}

@griesemer
Copy link
Contributor

Inference trace:

== infer : [S₄, T₅](S₄) ➞ [<nil>, <nil>]
== function parameters: (S₄)
-- function arguments : [s (variable of type []p.Interface[int])]
.  S₄ ≡ []p.Interface[int]      // assign
.  S₄ ➞ []p.Interface[int]
=> [S₄, T₅] ➞ [[]p.Interface[int], <nil>]

== type parameters: [S₄, T₅]
-- iteration 0
-- type parameter S₄ = []p.Interface[int]: core(S₄) = []p.Interface[T], single = true
.  []p.Interface[int] ≡ []p.Interface[T₅]       // inexact
.  .  p.Interface[int] ≡ p.Interface[T₅]        // inexact
.  .  p.Interface[T₅] ≡ p.Interface[int]        // swap
.  .  .  func(p.Interface[T₅]) ≡ func(p.Interface[int]) // inexact
.  .  .  .  (p.Interface[T₅]) ≡ (p.Interface[int])      // inexact
.  .  .  .  .  p.Interface[T₅] ≡ p.Interface[int]       // inexact
.  .  .  .  .  p.Interface[int] ≡ p.Interface[T₅]       // swap
.  .  .  .  .  .  func(p.Interface[int]) ≡ func(p.Interface[T₅])        // inexact
.  .  .  .  .  .  .  (p.Interface[int]) ≡ (p.Interface[T₅])     // inexact
.  .  .  .  .  .  .  .  p.Interface[int] ≡ p.Interface[T₅]      // inexact
.  .  .  .  .  .  .  .  p.Interface[T₅] ≡ p.Interface[int]      // swap
etc.

Inference should recognize that we're comparing the very same interface, once instantiated and once uninstantiated, and immediately infer the type parameter from the given type argument.
It doesn't do so because inference remains inexact throughout, which seems incorrect.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/519435 mentions this issue: go/types, types2: use exact unification when comparing interface methods

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/519455 mentions this issue: spec: fix unification rule for inexact interface unification

@findleyr findleyr modified the milestones: Go1.21.1, Go1.22 Aug 14, 2023
@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Aug 15, 2023
gopherbot pushed a commit that referenced this issue Aug 17, 2023
Irrespective of whether unification is exact or inexact, method
signatures of interfaces must always match exactly: a type never
satisfies/implements an interface if relevant method signatures
are different (i.e., not identical, possibly after substitution).

This change matches the fix https://go.dev/cl/519435.

For #61879.

Change-Id: I28b0a32d32626d85afd32e107efce141235a923d
Reviewed-on: https://go-review.googlesource.com/c/go/+/519455
TryBot-Bypass: Robert Griesemer <gri@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
@golang golang locked and limited conversation to collaborators Aug 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. NeedsFix The path to resolution is known, but the work has not been done. release-blocker Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

6 participants