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

go/types, types2: missing diagnosis for structs that contain themselves through type parameters #65711

Closed
dawidl022 opened this issue Feb 14, 2024 · 7 comments
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

@dawidl022
Copy link

dawidl022 commented Feb 14, 2024

What did you do?

While working on formal methods (in the style of Featherweight Go) and a prototype type checker and interpreter for #65555, I stumbled across an example program that crashes the Go compiler (try it out in the playground):

package main

type Foo[T any] struct {
	baz T
}

type Bar[T any] struct {
	foo Foo[T]
}

type Baz struct {
	bar Bar[Baz]
}

func main() {
}

(note: this program looks silly because it is part of my interpreter's testing suite, explicitly meant to test various edge cases in the type checker)

This program causes a stack overflow in the Go compiler. The expected outcome is that the compiler rejects such a program, due to an indirectly self-referential struct type via type parameters.

This bug also occurs for array type declarations, using the same setup (playground):

package main

type Foo[T any] [2]T

type Bar[T any] [2]Foo[T]

type Baz [2]Bar[Baz]

func main() {
}

The interesting thing is that this bug only seems to trigger in certain permutations of the type declarations (i.e. order of the declarations matters). E.g. if we place Baz before Bar or before Foo, then the compiler correctly rejects the program (i.e. without crashing).

E.g. the following program is correctly rejected by the compiler (playground):

package main

type Baz [2]Bar[Baz]

type Foo[T any] [2]T

type Bar[T any] [2]Foo[T]

func main() {
}

Related issues

#60817 reports deadlocks with recursive generic types.

What did you see happen?

The output of go build:

# github.com/dawidl022/go-generic-array-sizes/interpreters/fgg/typecheck/testdata/self_ref/self_ref_indirect
runtime: goroutine stack exceeds 1000000000-byte limit
runtime: sp=0x140204603b0 stack=[0x14020460000, 0x14040460000]
fatal error: stack overflow

runtime stack:
runtime.throw({0x104fd31f4?, 0x20000001?})
	runtime/panic.go:1023 +0x40 fp=0x16b68a840 sp=0x16b68a810 pc=0x1047b8390
runtime.newstack()
	runtime/stack.go:1103 +0x5e0 fp=0x16b68aa40 sp=0x16b68a840 pc=0x1047d64f0
runtime.morestack()
	runtime/asm_arm64.s:341 +0x70 fp=0x16b68aa40 sp=0x16b68aa40 pc=0x1047f40d0

goroutine 1 gp=0x140000021c0 m=0 mp=0x1057c8900 [running]:
cmd/compile/internal/types2.(*Named).resolve(0x140000b5960)
	cmd/compile/internal/types2/named.go:157 +0x43c fp=0x140204603b0 sp=0x140204603b0 pc=0x104f12bdc
cmd/compile/internal/types2.(*Named).Underlying(0x10521c8a8?)
	cmd/compile/internal/types2/named.go:457 +0x1c fp=0x14020460400 sp=0x140204603b0 pc=0x104f13e8c
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5960?})
	cmd/compile/internal/noder/helpers.go:124 +0xdc fp=0x14020460440 sp=0x14020460400 pc=0x104f51d0c
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b58f0?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x14020460480 sp=0x14020460440 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5b90?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x140204604c0 sp=0x14020460480 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5960?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x14020460500 sp=0x140204604c0 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b58f0?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x14020460540 sp=0x14020460500 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5b90?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x14020460580 sp=0x14020460540 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5960?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x140204605c0 sp=0x14020460580 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b58f0?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x14020460600 sp=0x140204605c0 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5b90?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x14020460640 sp=0x14020460600 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5960?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x14020460680 sp=0x14020460640 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b58f0?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x140204606c0 sp=0x14020460680 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5b90?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x14020460700 sp=0x140204606c0 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5960?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x14020460740 sp=0x14020460700 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b58f0?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x14020460780 sp=0x14020460740 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5b90?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x140204607c0 sp=0x14020460780 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5960?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x14020460800 sp=0x140204607c0 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b58f0?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x14020460840 sp=0x14020460800 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5b90?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x14020460880 sp=0x14020460840 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5960?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x140204608c0 sp=0x14020460880 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b58f0?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x14020460900 sp=0x140204608c0 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5b90?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x14020460940 sp=0x14020460900 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5960?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x14020460980 sp=0x14020460940 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b58f0?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x140204609c0 sp=0x14020460980 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5b90?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x14020460a00 sp=0x140204609c0 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5960?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x14020460a40 sp=0x14020460a00 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b58f0?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x14020460a80 sp=0x14020460a40 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5b90?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x14020460ac0 sp=0x14020460a80 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5960?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x14020460b00 sp=0x14020460ac0 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b58f0?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x14020460b40 sp=0x14020460b00 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5b90?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x14020460b80 sp=0x14020460b40 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5960?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x14020460bc0 sp=0x14020460b80 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b58f0?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x14020460c00 sp=0x14020460bc0 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5b90?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x14020460c40 sp=0x14020460c00 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5960?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x14020460c80 sp=0x14020460c40 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b58f0?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x14020460cc0 sp=0x14020460c80 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5b90?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x14020460d00 sp=0x14020460cc0 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5960?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x14020460d40 sp=0x14020460d00 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b58f0?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x14020460d80 sp=0x14020460d40 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5b90?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x14020460dc0 sp=0x14020460d80 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5960?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x14020460e00 sp=0x14020460dc0 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b58f0?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x14020460e40 sp=0x14020460e00 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5b90?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x14020460e80 sp=0x14020460e40 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5960?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x14020460ec0 sp=0x14020460e80 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b58f0?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x14020460f00 sp=0x14020460ec0 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5b90?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x14020460f40 sp=0x14020460f00 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5960?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x14020460f80 sp=0x14020460f40 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b58f0?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x14020460fc0 sp=0x14020460f80 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5b90?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x14020461000 sp=0x14020460fc0 pc=0x104f51dc8
...8388443 frames elided...
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5b90?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x1404045e700 sp=0x1404045e6c0 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5960?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x1404045e740 sp=0x1404045e700 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b58f0?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x1404045e780 sp=0x1404045e740 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5b90?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x1404045e7c0 sp=0x1404045e780 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5960?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x1404045e800 sp=0x1404045e7c0 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b58f0?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x1404045e840 sp=0x1404045e800 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5b90?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x1404045e880 sp=0x1404045e840 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5960?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x1404045e8c0 sp=0x1404045e880 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b58f0?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x1404045e900 sp=0x1404045e8c0 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5b90?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x1404045e940 sp=0x1404045e900 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5960?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x1404045e980 sp=0x1404045e940 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b58f0?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x1404045e9c0 sp=0x1404045e980 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5b90?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x1404045ea00 sp=0x1404045e9c0 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5960?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x1404045ea40 sp=0x1404045ea00 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b58f0?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x1404045ea80 sp=0x1404045ea40 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5b90?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x1404045eac0 sp=0x1404045ea80 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5960?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x1404045eb00 sp=0x1404045eac0 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b58f0?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x1404045eb40 sp=0x1404045eb00 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5b90?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x1404045eb80 sp=0x1404045eb40 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5960?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x1404045ebc0 sp=0x1404045eb80 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b58f0?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x1404045ec00 sp=0x1404045ebc0 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5b90?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x1404045ec40 sp=0x1404045ec00 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5960?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x1404045ec80 sp=0x1404045ec40 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b58f0?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x1404045ecc0 sp=0x1404045ec80 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5b90?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x1404045ed00 sp=0x1404045ecc0 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5960?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x1404045ed40 sp=0x1404045ed00 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b58f0?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x1404045ed80 sp=0x1404045ed40 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5b90?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x1404045edc0 sp=0x1404045ed80 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5960?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x1404045ee00 sp=0x1404045edc0 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b58f0?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x1404045ee40 sp=0x1404045ee00 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5b90?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x1404045ee80 sp=0x1404045ee40 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5960?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x1404045eec0 sp=0x1404045ee80 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b58f0?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x1404045ef00 sp=0x1404045eec0 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5b90?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x1404045ef40 sp=0x1404045ef00 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5960?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x1404045ef80 sp=0x1404045ef40 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b58f0?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x1404045efc0 sp=0x1404045ef80 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5b90?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x1404045f000 sp=0x1404045efc0 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5960?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x1404045f040 sp=0x1404045f000 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b58f0?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x1404045f080 sp=0x1404045f040 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5b90?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x1404045f0c0 sp=0x1404045f080 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b5960?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x1404045f100 sp=0x1404045f0c0 pc=0x104f51dc8
cmd/compile/internal/noder.isNotInHeap({0x10521c8a8?, 0x140000b58f0?})
	cmd/compile/internal/noder/helpers.go:132 +0x198 fp=0x1404045f140 sp=0x1404045f100 pc=0x104f51dc8
cmd/compile/internal/noder.checkFiles({0x0, {0x0, 0x0}}, {0x14000066538, 0x1, 0x0?})
	cmd/compile/internal/noder/irgen.go:125 +0x7ec fp=0x1404045f3b0 sp=0x1404045f140 pc=0x104f5433c
cmd/compile/internal/noder.writePkgStub({0x0?, {0x0?, 0x0?}}, {0x14000066538, 0x1, 0x1})
	cmd/compile/internal/noder/unified.go:296 +0x48 fp=0x1404045f6f0 sp=0x1404045f3b0 pc=0x104f74b88
cmd/compile/internal/noder.unified({0x0?, {0x0?, 0x0?}}, {0x14000066538?, 0x1051662c0?, 0x0?})
	cmd/compile/internal/noder/unified.go:172 +0x98 fp=0x1404045f8c0 sp=0x1404045f6f0 pc=0x104f74258
cmd/compile/internal/noder.LoadPackage({0x1400001e630, 0x1, 0x1})
	cmd/compile/internal/noder/noder.go:77 +0x398 fp=0x1404045fa00 sp=0x1404045f8c0 pc=0x104f58628
cmd/compile/internal/gc.Main(0x1052173c0)
	cmd/compile/internal/gc/main.go:197 +0xb08 fp=0x1404045fee0 sp=0x1404045fa00 pc=0x104f9df68
main.main()
	cmd/compile/main.go:57 +0x110 fp=0x1404045ff40 sp=0x1404045fee0 pc=0x104fc31e0
runtime.main()
	runtime/proc.go:271 +0x28c fp=0x1404045ffd0 sp=0x1404045ff40 pc=0x1047bacbc
runtime.goexit({})
	runtime/asm_arm64.s:1222 +0x4 fp=0x1404045ffd0 sp=0x1404045ffd0 pc=0x1047f6344

goroutine 2 gp=0x14000002700 m=nil [force gc (idle)]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
	runtime/proc.go:402 +0xc8 fp=0x14000062f90 sp=0x14000062f70 pc=0x1047bb118
runtime.goparkunlock(...)
	runtime/proc.go:408
runtime.forcegchelper()
	runtime/proc.go:326 +0xb8 fp=0x14000062fd0 sp=0x14000062f90 pc=0x1047baf78
runtime.goexit({})
	runtime/asm_arm64.s:1222 +0x4 fp=0x14000062fd0 sp=0x14000062fd0 pc=0x1047f6344
created by runtime.init.6 in goroutine 1
	runtime/proc.go:314 +0x24

goroutine 3 gp=0x14000002c40 m=nil [GC sweep wait]:
runtime.gopark(0x14000030070?, 0x10512eda8?, 0x0?, 0x0?, 0x0?)
	runtime/proc.go:402 +0xc8 fp=0x14000063720 sp=0x14000063700 pc=0x1047bb118
runtime.goparkunlock(...)
	runtime/proc.go:408
runtime.bgsweep(0x14000030070)
	runtime/mgcsweep.go:278 +0xa4 fp=0x140000637b0 sp=0x14000063720 pc=0x1047a2d74
runtime.gcenable.gowrap1()
	runtime/mgc.go:203 +0x28 fp=0x140000637d0 sp=0x140000637b0 pc=0x104795f38
runtime.goexit({})
	runtime/asm_arm64.s:1222 +0x4 fp=0x140000637d0 sp=0x140000637d0 pc=0x1047f6344
created by runtime.gcenable in goroutine 1
	runtime/mgc.go:203 +0x6c

goroutine 4 gp=0x14000002e00 m=nil [GC scavenge wait]:
runtime.gopark(0x140000300c8?, 0x0?, 0xe0?, 0xc9?, 0x14000030070?)
	runtime/proc.go:402 +0xc8 fp=0x14000063f60 sp=0x14000063f40 pc=0x1047bb118
runtime.goparkunlock(...)
	runtime/proc.go:408
runtime.(*scavengerState).park(0x1057c5ac0)
	runtime/mgcscavenge.go:425 +0x5c fp=0x14000063f90 sp=0x14000063f60 pc=0x10479feac
runtime.bgscavenge(0x14000030070)
	runtime/mgcscavenge.go:653 +0x44 fp=0x14000063fb0 sp=0x14000063f90 pc=0x1047a0404
runtime.gcenable.gowrap2()
	runtime/mgc.go:204 +0x28 fp=0x14000063fd0 sp=0x14000063fb0 pc=0x104795ed8
runtime.goexit({})
	runtime/asm_arm64.s:1222 +0x4 fp=0x14000063fd0 sp=0x14000063fd0 pc=0x1047f6344
created by runtime.gcenable in goroutine 1
	runtime/mgc.go:204 +0xac

goroutine 5 gp=0x14000003340 m=nil [finalizer wait]:
runtime.gopark(0x0?, 0x1047bb1b8?, 0xb8?, 0x25?, 0x33?)
	runtime/proc.go:402 +0xc8 fp=0x14000062580 sp=0x14000062560 pc=0x1047bb118
runtime.runfinq()
	runtime/mfinal.go:194 +0x108 fp=0x140000627d0 sp=0x14000062580 pc=0x104794e88
runtime.goexit({})
	runtime/asm_arm64.s:1222 +0x4 fp=0x140000627d0 sp=0x140000627d0 pc=0x1047f6344
created by runtime.createfing in goroutine 1
	runtime/mfinal.go:164 +0x80

What did you expect to see?

The type checker consistently reporting a type error due to a self-referential type, regardless of the type declaration order, without the compiler crashing.

Expected output (modulo line numbers):

# github.com/dawidl022/go-generic-array-sizes/interpreters/fgg/typecheck/testdata/self_ref/self_ref_indirect
./self_ref_indirect.go:6:6: invalid recursive type Baz
	./self_ref_indirect.go:6:6: Baz refers to
	./self_ref_indirect.go:7:6: Bar refers to
	./self_ref_indirect.go:15:6: Foo refers to
	./self_ref_indirect.go:6:6: Baz

Go version

go version go1.22.0 darwin/arm64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/dawidl022/Library/Caches/go-build'
GOENV='/Users/dawidl022/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/dawidl022/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/dawidl022/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.22.0'
GCCGO='gccgo'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK='/Users/dawidl022/Learning/Uni/ECS635U-project/work/projects/go-generic-array-sizes/go.work'
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 -ffile-prefix-map=/var/folders/70/xq_w4nkj0fg4n8g8sc4y3g080000gn/T/go-build2827072922=/tmp/go-build -gno-record-gcc-switches -fno-common'
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Feb 14, 2024
@randall77
Copy link
Contributor

@griesemer

If I understand correctly, this should be rejected by the typechecker and not reach types2, right?

@thanm thanm added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Feb 15, 2024
@thanm
Copy link
Contributor

thanm commented Feb 15, 2024

@golang/compiler

@mknyszek mknyszek added this to the Backlog milestone Feb 28, 2024
@mdempsky
Copy link
Member

If I understand correctly, this should be rejected by the typechecker and not reach types2, right?

I agree, I think this is a typechecker issue: Baz contains a field of type Bar[Baz], which contains a field of type Foo[Baz], which contains a field of type Baz.

This analogous non-generic code is correctly rejected:

type (
	FooBaz struct{ baz Baz }
	BarBaz struct{ foo FooBaz }
	Baz    struct{ bar BarBaz }
)

Retitling as a go/types + types2 issue.

@mdempsky mdempsky changed the title cmd/compile: stack overflow when typechecking self-referential types go/types, types2: missing diagnosis for structs that contain themselves through type parameters Feb 28, 2024
@mdempsky mdempsky assigned griesemer and findleyr and unassigned mdempsky Feb 28, 2024
@griesemer griesemer modified the milestones: Backlog, Go1.23 Feb 28, 2024
@griesemer
Copy link
Contributor

Definitely a bug. The optimization in validtype.go (exit early for *Named types) is incorrect (caches break things).

@gopherbot
Copy link

Change https://go.dev/cl/567975 mentions this issue: go/types, types2: add tracing to Checker.validType

@gopherbot
Copy link

Change https://go.dev/cl/567976 mentions this issue: go/types, types2: disable incorrect optimization in type validity check

@gopherbot
Copy link

Change https://go.dev/cl/567916 mentions this issue: go/types, types2: better error position for invalid (infinite) types

gopherbot pushed a commit that referenced this issue Feb 29, 2024
Debugging support.

For #65711.

Change-Id: I2b8b03d2c6e02d32a4f9272313e852f17da35b3e
Reviewed-on: https://go-review.googlesource.com/c/go/+/567975
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
gopherbot pushed a commit that referenced this issue Feb 29, 2024
Provide an explicit start position to Checker.cycleError for better
control over the reported error.

For #65711.

Change-Id: Ie3016523442d75f348a033c1b944db493943f433
Reviewed-on: https://go-review.googlesource.com/c/go/+/567916
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Griesemer <gri@google.com>
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
Development

No branches or pull requests

8 participants