Skip to content

Go1.18: runtime: goroutine stack exceeds 1000000000-byte limit with generic function #50275

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

Closed
nikgalushko opened this issue Dec 20, 2021 · 1 comment

Comments

@nikgalushko
Copy link

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

$ go version
go version go1.18beta1 darwin/amd64

Does this issue reproduce with the latest release?

No.

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN="/Users/nikita.galushko/go/bin"
GOCACHE="/Users/nikita.galushko/Library/Caches/go-build"
GOENV="/Users/nikita.galushko/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/nikita.galushko/go/pkg/mod"
GONOPROXY=""
GONOSUMDB="stash.lamoda.*"
GOOS="darwin"
GOPATH="/Users/nikita.galushko/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.18beta1"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/nikita.galushko/Documents/GitHub/fx/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 -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/qw/1tqq14qj6zl92hzqm3mk0vdwzh7_yw/T/go-build3942344120=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I'm trying Golang generics and catch a strange behavior: stack overflow with simple code. If I write the same code with a specific type, it will work as expected. You can check it on playground.
The minimal code is:

func test[A ~[]T, T comparable](arr ...A) A {
	var ret A

	switch len(arr) {
	case 0, 1, 2:
		return ret
	default:
		return test(arr[2:]...)
	}
}

What did you expect to see?

no fatal error

What did you see instead?

runtime: goroutine stack exceeds 1000000000-byte limit
runtime: sp=0xc020460468 stack=[0xc020460000, 0xc040460000]
fatal error: stack overflow

runtime stack:
runtime.throw({0xd21d63?, 0x12eb300?})
	/usr/local/go/src/runtime/panic.go:992 +0x71
runtime.newstack()
	/usr/local/go/src/runtime/stack.go:1101 +0x5cc
runtime.morestack()
	/usr/local/go/src/runtime/asm_amd64.s:547 +0x8b

goroutine 1 [running]:
cmd/compile/internal/types2.(*unifier).nify(0xc00016e630, {0xe8e7c0?, 0xc0003cfcb0?}, {0xe8e748?, 0xc00002d130?}, 0x0)
	/usr/local/go/src/cmd/compile/internal/types2/unify.go:239 +0x11c5 fp=0xc020460478 sp=0xc020460470 pc=0xba1505
cmd/compile/internal/types2.(*unifier).nifyEq(0x0?, {0xe8e7c0?, 0xc0003cfcb0?}, {0xe8e748?, 0xc00002d130?}, 0x0?)
	/usr/local/go/src/cmd/compile/internal/types2/unify.go:232 +0x96 fp=0xc0204604d8 sp=0xc020460478 pc=0xba02d6
cmd/compile/internal/types2.(*unifier).nify(0xc00016e630, {0xe8e7c0?, 0xc0003cfcb0?}, {0xe8e748?, 0xc00002d130?}, 0x0)
	/usr/local/go/src/cmd/compile/internal/types2/unify.go:266 +0x314 fp=0xc020460678 sp=0xc0204604d8 pc=0xba0654
cmd/compile/internal/types2.(*unifier).nifyEq(0x0?, {0xe8e7c0?, 0xc0003cfcb0?}, {0xe8e748?, 0xc00002d130?}, 0x0?)
	/usr/local/go/src/cmd/compile/internal/types2/unify.go:232 +0x96 fp=0xc0204606d8 sp=0xc020460678 pc=0xba02d6
cmd/compile/internal/types2.(*unifier).nify(0xc00016e630, {0xe8e7c0?, 0xc0003cfcb0?}, {0xe8e748?, 0xc00002d130?}, 0x0)
	/usr/local/go/src/cmd/compile/internal/types2/unify.go:266 +0x314 fp=0xc020460878 sp=0xc0204606d8 pc=0xba0654
...additional frames elided...

Go build failed.
About the Playground

The Go Playground is a web service that runs on go.dev's servers. The service receives a Go program, vets, compiles, links, and runs the program inside a sandbox, then returns the output.
@nikgalushko nikgalushko changed the title Go1.18: stack overflow with generic function Go1.18: runtime: goroutine stack exceeds 1000000000-byte limit with generic function Dec 20, 2021
@seankhliao
Copy link
Member

Duplicate of #48619

@seankhliao seankhliao marked this as a duplicate of #48619 Dec 20, 2021
@golang golang locked and limited conversation to collaborators Dec 20, 2022
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