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: impure type set used in value type #60117

Closed
kckrinke opened this issue May 10, 2023 · 4 comments
Closed
Assignees
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@kckrinke
Copy link

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

$ go version
go version go1.20.1 linux/arm64

Does this issue reproduce with the latest release?

Yes. Confirmed with v1.20.4.

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

go env Output
$ go env
GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/quo/local/enjenv/golang/cache"
GOENV="/quo/local/enjenv/golang/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS="-modcacherw"
GOHOSTARCH="arm64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/quo/local/enjenv/golang/modcache"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/quo"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/quo/local/enjenv/golang/go"
GOSUMDB="sum.golang.org"
GOTMPDIR="/quo/local/enjenv/golang/tmp"
GOTOOLDIR="/quo/local/enjenv/golang/go/pkg/tool/linux_arm64"
GOVCS=""
GOVERSION="go1.20.4"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/quo/src/poc/go-impure-value/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 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/quo/local/enjenv/golang/tmp/go-build2070028500=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Just experimenting with using generics to solve some design pattern conveniences and discovered that I apparently need to file this bug report, so that's what this bug report is about.

Here's a short program demonstrating the problem case.

What did you expect to see?

Dunno exactly, still wrapping my brain around the generics thing and this was simply exploration through experimentation. The short program was extracted from the work I'm doing on a much larger project, which means I must be confused about the rules of generics and need to scale things back a bit.

What did you see instead?

$ cat main.go
package main

import (
	"fmt"
)

type Number interface {
	uint64 | int64 | float64
}

type Variable interface {
	Number | []interface{} | interface{}
}

func main() {
	fmt.Printf("Hello World\n")
}
$ go build -v
go-impure-value
# go-impure-value
./main.go:7:6: internal compiler error: impure type set used in value type

Please file a bug report including a short program that triggers the error.
https://go.dev/issue/new
@seankhliao seankhliao changed the title affected/package: internal compiler error cmd/compile: internal compiler error: impure type set used in value type May 10, 2023
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label May 10, 2023
@seankhliao seankhliao added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label May 10, 2023
@seankhliao
Copy link
Member

cc @golang/compiler

tip comes with a stacktrace:

go build 
# go.seankhliao.com/testrepo0189
go.seankhliao.com/testrepo0189/main.go:7:6: internal compiler error: impure type set used in value type

goroutine 1 [running]:
runtime/debug.Stack()
	../../sdk/gotip/src/runtime/debug/stack.go:24 +0x5e
cmd/compile/internal/base.FatalfAt({0x4619e0?, 0xc0?}, {0xd089ce, 0x22}, {0x0, 0x0, 0x0})
	../../sdk/gotip/src/cmd/compile/internal/base/print.go:234 +0x1d7
cmd/compile/internal/base.Fatalf(...)
	../../sdk/gotip/src/cmd/compile/internal/base/print.go:203
cmd/compile/internal/noder.(*reader).unionType(0xc0004619e0)
	../../sdk/gotip/src/cmd/compile/internal/noder/reader.go:555 +0x9e
cmd/compile/internal/noder.(*reader).doTyp(0xc0004619e0)
	../../sdk/gotip/src/cmd/compile/internal/noder/reader.go:527 +0x1df
cmd/compile/internal/noder.(*pkgReader).typIdx(0xc0004442a0, {0x44e249?, 0x0?}, 0xc00047c0d0, 0x1)
	../../sdk/gotip/src/cmd/compile/internal/noder/reader.go:430 +0x18a
cmd/compile/internal/noder.(*reader).typWrapped(0xc000461d50, 0x1?)
	../../sdk/gotip/src/cmd/compile/internal/noder/reader.go:389 +0x3a
cmd/compile/internal/noder.(*reader).typ(...)
	../../sdk/gotip/src/cmd/compile/internal/noder/reader.go:383
cmd/compile/internal/noder.(*reader).interfaceType(0xc000461d50)
	../../sdk/gotip/src/cmd/compile/internal/noder/reader.go:576 +0x1ed
cmd/compile/internal/noder.(*reader).doTyp(0xc000461d50)
	../../sdk/gotip/src/cmd/compile/internal/noder/reader.go:525 +0x1cf
cmd/compile/internal/noder.(*pkgReader).typIdx(0xc0004442a0, {0x461ef8?, 0xc0?}, 0xc00047c0d0, 0x0)
	../../sdk/gotip/src/cmd/compile/internal/noder/reader.go:430 +0x18a
cmd/compile/internal/noder.(*reader).typWrapped(0xc000192480, 0xd0?)
	../../sdk/gotip/src/cmd/compile/internal/noder/reader.go:389 +0x3a
cmd/compile/internal/noder.(*pkgReader).objIdx(0xc0004442a0, 0x0, {0x0?, 0x0, 0x0}, {0x13b1b80?, 0x0, 0x0}, 0xe7?)
	../../sdk/gotip/src/cmd/compile/internal/noder/reader.go:783 +0x6e5
cmd/compile/internal/noder.(*pkgReader).objInstIdx(0xc0004625a0?, {0x4442a0?, {0x13b1b80?, 0xb064e5?, 0x1?}}, 0xc00047c000, 0xa0?)
	../../sdk/gotip/src/cmd/compile/internal/noder/reader.go:672 +0x87
cmd/compile/internal/noder.(*reader).obj(0xc0004625a0)
	../../sdk/gotip/src/cmd/compile/internal/noder/reader.go:644 +0x46
cmd/compile/internal/noder.(*reader).doTyp(0xc0004625a0)
	../../sdk/gotip/src/cmd/compile/internal/noder/reader.go:501 +0x6d
cmd/compile/internal/noder.(*pkgReader).typIdx(0xc0004442a0, {0x4628e0?, 0xc0?}, 0xc00047c000, 0x1)
	../../sdk/gotip/src/cmd/compile/internal/noder/reader.go:430 +0x18a
cmd/compile/internal/noder.(*reader).typWrapped(0xc0004628e0, 0x78?)
	../../sdk/gotip/src/cmd/compile/internal/noder/reader.go:389 +0x3a
cmd/compile/internal/noder.(*reader).typ(...)
	../../sdk/gotip/src/cmd/compile/internal/noder/reader.go:383
cmd/compile/internal/noder.(*reader).unionType(0xc0004628e0)
	../../sdk/gotip/src/cmd/compile/internal/noder/reader.go:549 +0x59
cmd/compile/internal/noder.(*reader).doTyp(0xc0004628e0)
	../../sdk/gotip/src/cmd/compile/internal/noder/reader.go:527 +0x1df
cmd/compile/internal/noder.(*pkgReader).typIdx(0xc0004442a0, {0x44e249?, 0x0?}, 0xc00047c000, 0x1)
	../../sdk/gotip/src/cmd/compile/internal/noder/reader.go:430 +0x18a
cmd/compile/internal/noder.(*reader).typWrapped(0xc000462c50, 0x1?)
	../../sdk/gotip/src/cmd/compile/internal/noder/reader.go:389 +0x3a
cmd/compile/internal/noder.(*reader).typ(...)
	../../sdk/gotip/src/cmd/compile/internal/noder/reader.go:383
cmd/compile/internal/noder.(*reader).interfaceType(0xc000462c50)
	../../sdk/gotip/src/cmd/compile/internal/noder/reader.go:576 +0x1ed
cmd/compile/internal/noder.(*reader).doTyp(0xc000462c50)
	../../sdk/gotip/src/cmd/compile/internal/noder/reader.go:525 +0x1cf
cmd/compile/internal/noder.(*pkgReader).typIdx(0xc0004442a0, {0x462df8?, 0xc0?}, 0xc00047c000, 0x0)
	../../sdk/gotip/src/cmd/compile/internal/noder/reader.go:430 +0x18a
cmd/compile/internal/noder.(*reader).typWrapped(0xc000192300, 0x20?)
	../../sdk/gotip/src/cmd/compile/internal/noder/reader.go:389 +0x3a
cmd/compile/internal/noder.(*pkgReader).objIdx(0xc0004442a0, 0x1, {0x0?, 0x0, 0x0}, {0x13b1b80?, 0x0, 0x0}, 0x0?)
	../../sdk/gotip/src/cmd/compile/internal/noder/reader.go:783 +0x6e5
cmd/compile/internal/noder.(*pkgReader).objInstIdx(0xc000463748?, {0x0?, {0x13b1b80?, 0x44e249?, 0x8?}}, 0x0, 0x1?)
	../../sdk/gotip/src/cmd/compile/internal/noder/reader.go:672 +0x87
cmd/compile/internal/noder.(*reader).obj(0xc000463748)
	../../sdk/gotip/src/cmd/compile/internal/noder/reader.go:644 +0x46
cmd/compile/internal/noder.(*reader).pkgObjs(0xc000463748, 0xc00018a0c0)
	../../sdk/gotip/src/cmd/compile/internal/noder/reader.go:3373 +0x9b
cmd/compile/internal/noder.(*reader).pkgDecls(0xc000463748, 0xc00018a0c0)
	../../sdk/gotip/src/cmd/compile/internal/noder/reader.go:3362 +0x1af
cmd/compile/internal/noder.(*reader).pkgInit(0xc000463748, 0xc00047a630?, 0xc00018a0c0)
	../../sdk/gotip/src/cmd/compile/internal/noder/reader.go:3301 +0xd6
cmd/compile/internal/noder.unified({0x0?, {0x0?, 0x0?}}, {0xc000134468?, 0xc3d860?, 0x6bbd36895316fcd?})
	../../sdk/gotip/src/cmd/compile/internal/noder/unified.go:92 +0x2cf
cmd/compile/internal/noder.LoadPackage({0xc000142100, 0x1, 0x2})
	../../sdk/gotip/src/cmd/compile/internal/noder/noder.go:77 +0x450
cmd/compile/internal/gc.Main(0xd24190)
	../../sdk/gotip/src/cmd/compile/internal/gc/main.go:198 +0xc17
main.main()
	../../sdk/gotip/src/cmd/compile/main.go:57 +0xf9

@mdempsky mdempsky self-assigned this May 10, 2023
@mdempsky
Copy link
Member

Thanks for the report. Your code is valid and should work. I'm sorry that it doesn't.

This is a little nuanced, but the issue here is that your defined type Variable is a "pure" interface, but it embeds a non-pure interface (Number). This should be allowed, but hits an unexpected code path today.

You can workaround this by simplifying Number | []any | any to just any, or removing that line altogether.

@kckrinke
Copy link
Author

You're welcome! Nice to know I was on track. That's basically what I ended up doing. thanks for the notes!

@cherrymui cherrymui added this to the Go1.21 milestone May 10, 2023
@mdempsky mdempsky 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 May 10, 2023
@gopherbot
Copy link

Change https://go.dev/cl/495455 mentions this issue: cmd/compile/internal/noder: suppress unionType consistency check

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

No branches or pull requests

5 participants