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 compiler error: cannot call SetType(go.shape.int) on v (type int) #59378

Closed
abursavich opened this issue Apr 2, 2023 · 6 comments
Assignees
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@abursavich
Copy link

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

$ go version
go version go1.20.2 darwin/arm64

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="arm64"
GOBIN=""
GOCACHE="/Users/REDACTED/Library/Caches/go-build"
GOENV="/Users/REDACTED/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/REDACTED/go/pkg/mod"
GONOPROXY="REDACTED"
GONOSUMDB="REDACTED"
GOOS="darwin"
GOPATH="/Users/REDACTED/go"
GOPRIVATE="REDACTED"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.20.2"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="REDACTED"
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 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/p4/t2ydl1qj10s99sfykmbnp6cc0000gq/T/go-build2434621046=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I was working on a package that uses generics. I changed a call from slices.ContainsFunc to slices.IndexFunc and it stopped compiling. The actual code was fairly complicated, but I've reduced it down to this nonsensical repro:

https://go.dev/play/p/-3mq-tXI8lI

package main

import "golang.org/x/exp/slices"

func main() {
	compilerError([]int{}, func(int) bool { return true })
}

func compilerError[S []E, E any](a S, fn func(E) bool) {
	for _, v := range a {
		// The error doesn't occur with slices.ContainsFunc
		slices.IndexFunc(a, func(e E) bool { return fn(v) })
	}
}
go: finding module for package golang.org/x/exp/slices
go: downloading golang.org/x/exp v0.0.0-20230321023759-10a507213a29
go: found golang.org/x/exp/slices in golang.org/x/exp v0.0.0-20230321023759-10a507213a29
# play
./prog.go:10:9: internal compiler error: cannot call SetType(go.shape.int) on v (type int)

Please file a bug report including a short program that triggers the error.
https://go.dev/issue/new

What did you expect to see?

I expected the code to keep compiling.

What did you see instead?

REDACTED:393:9: internal compiler error: cannot call SetType(go.shape.int) on v (type int)

Please file a bug report including a short program that triggers the error.
https://go.dev/issue/new
FAIL    REDACTED [build failed]
FAIL
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Apr 2, 2023
@cuonglm cuonglm self-assigned this Apr 3, 2023
@cuonglm cuonglm added the NeedsFix The path to resolution is known, but the work has not been done. label Apr 3, 2023
@cuonglm cuonglm added this to the Go1.21 milestone Apr 3, 2023
@gopherbot
Copy link

Change https://go.dev/cl/481555 mentions this issue: cmd/compile: fix re-shaping for non-pointer types

@cuonglm
Copy link
Member

cuonglm commented Apr 3, 2023

@mdempsky Should we backport this?

go1.20 users can workaround by using GOEXPERIMENT=nounified. The fix seems to be safe for backport IMHO, though.

@abursavich
Copy link
Author

abursavich commented Apr 3, 2023

Change https://go.dev/cl/481555 mentions this issue: cmd/compile: fix re-shaping for non-pointer types

@cuonglm, not sure if this is helpful, but i also get a similar error when using a pointer type.

./prog.go:10:9: internal compiler error: cannot call SetType(go.shape.*uint8) on v (type *int)

@mdempsky
Copy link
Member

mdempsky commented Apr 3, 2023

The issue here is we're shaping the type argument []int into go.shape.[]int, so the range statement is producing a variable of type int. But because the parameter is constrained to []E, where E is itself another type parameter, we should probably shape into go.shape.[]go.shape.int instead.

@cuonglm
Copy link
Member

cuonglm commented Apr 5, 2023

@gopherbot please backport this issue to go1.20, this causes code that use standard package slices stop compiling with no workaround.

@gopherbot
Copy link

Backport issue(s) opened: #59450 (for 1.20).

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants