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: is not shape-identical" crash #66663

Open
ipfreely-uk opened this issue Apr 3, 2024 · 3 comments
Open
Assignees
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@ipfreely-uk
Copy link

Go version

go version go1.22.1 linux/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/ipfreely/.cache/go-build'
GOENV='/home/ipfreely/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/ipfreely/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/ipfreely/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/go1.22.1'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/go1.22.1/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.22.1'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/ipfreely/projects/gobug/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 -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3230307039=/tmp/go-build -gno-record-gcc-switches'

What did you do?

Experimenting with limits of the generic type system. Error triggered by addition of Blocks() to Range interface.

// go.mod
module example.com/bug/v2

go 1.22.1
// bug.go
package gobug

type Iterator[A any] func() (bool, A)

type Set[A any] interface {
	Addresses() Iterator[A]
	Ranges() Iterator[Range[A]]
}

type Range[A any] interface {
	Set[A]
	// Problem line
	Blocks() Iterator[Block[A]]
}

type Block[A any] interface {
	Range[A]
}

type rangeImpl[A any] struct{}

func (r *rangeImpl[A]) Addresses() Iterator[A] {
	return func() (bool, A) {
		var a A
		return false, a
	}
}

func (r *rangeImpl[A]) Ranges() Iterator[Range[A]] {
	return func() (bool, Range[A]) {
		var a Range[A]
		return false, a
	}
}

func (r *rangeImpl[A]) Blocks() Iterator[Block[A]] {
	return func() (bool, Block[A]) {
		var a Block[A]
		return false, a
	}
}

func NewRange[A any]() Range[A] {
	return &rangeImpl[A]{}
}
// bug_test.go
package gobug_test

import (
	"testing"

	gobug "example.com/bug/v2"
)

func TestNetRange(t *testing.T) {
	type AddrImpl struct{}
	r := gobug.NewRange[AddrImpl]()
	if r == nil {
		t.Fail()
	}
}

What did you see happen?

Internal compile error running go test

$ go test example.com/bug/v2
# example.com/bug/v2_test [example.com/bug/v2.test]
./bug_test.go:11:31: internal compiler error: gobug.NewRange[go.shape.struct {}](&gobug..dict.NewRange[example.com/bug/v2_test.AddrImpl·1]) (type gobug.Range[go.shape.struct {}]) is not shape-identical to gobug.Range[example.com/bug/v2_test.AddrImpl·1]

Please file a bug report including a short program that triggers the error.
https://go.dev/issue/new
FAIL	example.com/bug/v2 [build failed]
FAIL

What did you expect to see?

Expected code to compile or compiler to emit error saying what is illegal about the code.

@ALTree ALTree changed the title go test: internal compiler error: gobug.NewRange[go.shape.struct {}](&gobug..dict.NewRange[example.com/bug/v2_test.AddrImpl·1]) (type gobug.Range[go.shape.struct {}]) is not shape-identical to gobug.Range[example.com/bug/v2_test.AddrImpl·1] cmd/compile: "internal compiler error: is not shape-identical" crash Apr 3, 2024
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Apr 3, 2024
@ALTree
Copy link
Member

ALTree commented Apr 3, 2024

Reproducible on tip too.

@ALTree ALTree added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Apr 3, 2024
@ALTree ALTree added this to the Go1.23 milestone Apr 3, 2024
@cuonglm
Copy link
Member

cuonglm commented Apr 3, 2024

Simpler reproducer:

package p

type Iterator[A any] func() (bool, A)

type Range[A any] interface {
	Blocks() Iterator[Block[A]]
}

type Block[A any] interface {
	Range[A]
}

type rangeImpl[A any] struct{}

func (r *rangeImpl[A]) Blocks() Iterator[Block[A]] {
	return func() (bool, Block[A]) {
		var a Block[A]
		return false, a
	}
}

func NewRange[A any]() Range[A] {
	return &rangeImpl[A]{}
}

type AddrImpl struct{}

var _ = NewRange[AddrImpl]()

I think this has the same underlying problem with #65362, https://go-review.googlesource.com/c/go/+/559656 would fix this.

@gopherbot
Copy link

Change https://go.dev/cl/559656 mentions this issue: cmd/compile: fix recursive generic interface instantiation

ipfreely-uk pushed a commit to ipfreely-uk/go that referenced this issue Apr 3, 2024
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. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
Status: All-But-Submitted
Development

No branches or pull requests

4 participants