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: Unified IR failed to compile recursive generic type #54722

Closed
cuonglm opened this issue Aug 28, 2022 · 3 comments
Closed

cmd/compile: Unified IR failed to compile recursive generic type #54722

cuonglm opened this issue Aug 28, 2022 · 3 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. generics Issue is related to generics NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@cuonglm
Copy link
Member

cuonglm commented Aug 28, 2022

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

$ go version
go version devel go1.20-bcd1ac7120 Fri Aug 26 18:01:35 2022 +0000 linux/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

What did you do?

https://go.dev/play/p/O5Vk0mY-3n9?v=gotip

What did you expect to see?

Compile successfully.

What did you see instead?

# go.dev.play
./p/p.go:3:6: internal compiler error: p.G[go.shape.int] is missing its underlying type

goroutine 1 [running]:
runtime/debug.Stack()
	/usr/local/go/src/runtime/debug/stack.go:24 +0x65
cmd/compile/internal/base.FatalfAt({0x8?, 0x0?}, {0xd8a255, 0x21}, {0xc0003d4d40, 0x1, 0x1})
	/usr/local/go/src/cmd/compile/internal/base/print.go:227 +0x1d7
cmd/compile/internal/base.Fatalf(...)
	/usr/local/go/src/cmd/compile/internal/base/print.go:196
cmd/compile/internal/base.Assertf(...)
	/usr/local/go/src/cmd/compile/internal/base/print.go:246
cmd/compile/internal/noder.shapify(0xc000396f50?, 0x1?)
	/usr/local/go/src/cmd/compile/internal/noder/reader.go:820 +0x8a
cmd/compile/internal/noder.(*pkgReader).objDictIdx(0xc00009f930, 0xc0003a5a00, 0x2?, {0xc000012080, 0x1, 0x1}, {0xc000012098, 0x1, 0xc19024?}, 0x0)
	/usr/local/go/src/cmd/compile/internal/noder/reader.go:903 +0x63f
cmd/compile/internal/noder.(*pkgReader).objIdx(0xc00009f930, 0x2, {0xc000012080?, 0x1, 0x1}, {0xc000012098?, 0x1, 0x1}, 0x0?)
	/usr/local/go/src/cmd/compile/internal/noder/reader.go:668 +0x399
cmd/compile/internal/noder.(*pkgReader).objInstIdx(0xc0000a9980?, {0x1?, {0xc000024220?, 0xb659a8?, 0xc0000a9980?}}, 0xc00009e820, 0x80?)
	/usr/local/go/src/cmd/compile/internal/noder/reader.go:645 +0x90
cmd/compile/internal/noder.(*reader).obj(0xc0000a9980)
	/usr/local/go/src/cmd/compile/internal/noder/reader.go:617 +0x4c
cmd/compile/internal/noder.(*reader).doTyp(0xc0000a9980)
	/usr/local/go/src/cmd/compile/internal/noder/reader.go:489 +0x73
cmd/compile/internal/noder.(*pkgReader).typIdx(0xc00009f930, {0xc17b3b?, 0x0?}, 0xc00009e820, 0x1)
	/usr/local/go/src/cmd/compile/internal/noder/reader.go:418 +0x1ab
cmd/compile/internal/noder.(*reader).typWrapped(0xc0000a9800, 0x30?)
	/usr/local/go/src/cmd/compile/internal/noder/reader.go:377 +0x45
cmd/compile/internal/noder.(*reader).typ(...)
	/usr/local/go/src/cmd/compile/internal/noder/reader.go:371
cmd/compile/internal/noder.(*reader).structType(0xc0000a9800)
	/usr/local/go/src/cmd/compile/internal/noder/reader.go:563 +0xb7
cmd/compile/internal/noder.(*reader).doTyp(0xc0000a9800)
	/usr/local/go/src/cmd/compile/internal/noder/reader.go:511 +0x1d9
cmd/compile/internal/noder.(*pkgReader).typIdx(0xc00009f930, {0xffffffff?, 0xff?}, 0xc00009e820, 0x0)
	/usr/local/go/src/cmd/compile/internal/noder/reader.go:418 +0x1ab
cmd/compile/internal/noder.(*reader).typWrapped(0xc0000a9500, 0x0?)
	/usr/local/go/src/cmd/compile/internal/noder/reader.go:377 +0x45
cmd/compile/internal/noder.(*pkgReader).objIdx(0xc00009f930, 0x0, {0x0?, 0x0, 0x0}, {0xc000012028?, 0x1, 0x1}, 0xa8?)
	/usr/local/go/src/cmd/compile/internal/noder/reader.go:756 +0x71c
cmd/compile/internal/noder.(*pkgReader).objIdx.func3()
	/usr/local/go/src/cmd/compile/internal/noder/reader.go:761 +0x4b
cmd/compile/internal/noder.readBodies(0xc0002ea0c0)
	/usr/local/go/src/cmd/compile/internal/noder/unified.go:139 +0x227
cmd/compile/internal/noder.unified({0xc0000aa448?, 0x0?, 0x2?})
	/usr/local/go/src/cmd/compile/internal/noder/unified.go:103 +0x3d6
cmd/compile/internal/noder.LoadPackage({0xc0000ae100, 0x1, 0x2})
	/usr/local/go/src/cmd/compile/internal/noder/noder.go:77 +0x467
cmd/compile/internal/gc.Main(0xda36e8)
	/usr/local/go/src/cmd/compile/internal/gc/main.go:184 +0xbbd
main.main()
	/usr/local/go/src/cmd/compile/main.go:57 +0xdd


Go build failed.
@cuonglm cuonglm added NeedsFix The path to resolution is known, but the work has not been done. generics Issue is related to generics labels Aug 28, 2022
@cuonglm cuonglm added this to the Go1.20 milestone Aug 28, 2022
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Aug 28, 2022
@gopherbot
Copy link

gopherbot commented Aug 29, 2022

Change https://go.dev/cl/426335 mentions this issue: cmd/compile: fix unified IR shapifying recursive instantiated types

@mdempsky
Copy link
Member

mdempsky commented Aug 29, 2022

Thanks Cuong. Did you discover this on your own, or is it minimized from existing code?

I can imagine someone wanting to implement a concurrent tree data structure with

type Node[T any] struct {
  elem T
  left, right atomic.Pointer[Node[T]]
}

so it seems plausible and worth fixing either way.

This is a tricky code pattern to support. CL 426335 may be a reasonable interim workaround.

@cuonglm
Copy link
Member Author

cuonglm commented Aug 29, 2022

Thanks Cuong. Did you discover this on your own, or is it minimized from existing code?

It minimized from https://github.com/alphadose/haxmap, specifically, I discover in this commit alphadose/haxmap@add8109

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. generics Issue is related to generics NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

3 participants