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: failed to compile some recursive generic type #54535

Closed
johejo opened this issue Aug 19, 2022 · 8 comments
Closed

cmd/compile: failed to compile some recursive generic type #54535

johejo opened this issue Aug 19, 2022 · 8 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

@johejo
Copy link

johejo commented Aug 19, 2022

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

$ go version
go version devel go1.20-a719a78c1b Fri Aug 19 00:29:18 2022 +0000 darwin/arm64

Does this issue reproduce with the latest release?

tip only

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

go env Output
$ go env
GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/mitsuoheijo/Library/Caches/go-build"
GOENV="/Users/mitsuoheijo/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/mitsuoheijo/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/mitsuoheijo/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/mitsuoheijo/ghq/github.com/golang/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/mitsuoheijo/ghq/github.com/golang/go/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="devel go1.20-a719a78c1b Fri Aug 19 00:29:18 2022 +0000"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/mitsuoheijo/ghq/github.com/johejo/sandbox/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 arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/bq/s3vkkxm17jq79lx5qy3856zh0000gn/T/go-build3085638013=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

package main

type node[T any] struct {
	items    items[T]
	children items[*node[T]]
}

func (n *node[T]) f(i int, j int) bool {
	if len(n.children[i].items) < j {
		return false
	}
	return true
}

type items[T any] []T

func main() {
	_ = node[int]{}
	println("hello")
}

What did you expect to see?

$ go run .
hello

What did you see instead?

$ gotip run .
# github.com/johejo/sandbox
./main.go:9:22: n.children[i].items undefined (type go.shape.*uint8 has no field or method items)

This might be some regression.
I found this problem while using google/btree.
https://github.com/google/btree

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Aug 19, 2022
@johejo johejo changed the title cmd/compile: failed to compile recursive generic type cmd/compile: failed to compile some recursive generic type Aug 19, 2022
@cuonglm
Copy link
Member

cuonglm commented Aug 19, 2022

It run ok on tip now: ee833ed

@hopehook
Copy link
Member

hopehook commented Aug 19, 2022

I can reproduce this problem too.

go version devel go1.20-ee833ed Fri Aug 19 01:34:22 2022 +0000 linux/amd64

# command-line-arguments
./main.go:9:22: n.children[i].items undefined (type go.shape.*uint8 has no field or method items)

@cuonglm
Copy link
Member

cuonglm commented Aug 19, 2022

@hopehook Oh right, I messed up my operation.

It runs ok in nounified:

GOEXPERIMENT=nounified go run r.go

cc @mdempsky

@cuonglm cuonglm added the NeedsFix The path to resolution is known, but the work has not been done. label Aug 19, 2022
@cuonglm cuonglm modified the milestones: Gccgo, Go1.20 Aug 19, 2022
@mdempsky mdempsky self-assigned this Aug 19, 2022
@mdempsky
Copy link
Member

Thanks for the report!

Further minimized test case:

package main

type s[T any] struct{ f T }

func f[T any]() {
	var x s[*struct{ g T }]
	_ = x.f.g
}

func main() {
	_ = f[int]
}

This is an issue with pointer shaping. The type items[*struct{g T}] gets pointer shaped to items[*byte], which means x.f has shape type *byte. We need to insert an implicit conversion back to *struct{g T} so that we can select the g field.

@hopehook
Copy link
Member

FYI: bisect shows bad at this CL: https://go-review.googlesource.com/c/go/+/422235.

@mdempsky
Copy link
Member

mdempsky commented Aug 19, 2022

@hopehook Thanks, that's not surprising. That CL simply switches the default from GOEXPERIMENT=nounified to GOEXPERIMENT=unified, and it was already reported above that the issue goes away when setting GOEXPERIMENT=nounified.

FWIW, more useful would be if you can force GOEXPERIMENT=unified while bisecting. But I'm pretty sure that will bisect to CL 424734.

@hopehook
Copy link
Member

@mdempsky Yes, you are right.

@gopherbot
Copy link

Change https://go.dev/cl/424936 mentions this issue: cmd/compile: fix unified IR regressions

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

5 participants