You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
cmd/compile: generics + constant cycle causes panic in type checker #52748
$ go version
go version go1.18.1 darwin/arm64
$ cat b.go
package main
import "unsafe"type S[T any] struct{}
const c = unsafe.Sizeof(S[[c]byte]{})
$ go tool compile b.go
<unknown line number>: internal compiler error: panic: unimplemented basic: invalid type (kind 0)
Please file a bug report including a short program that triggers the error.
https://go.dev/issue/new
Huh, this reports an initialization cycle when type-checking. For example, after copying the above into cmd/compile/internal/types2/testdata/manual.go:
> go test -run=TestManual
--- FAIL: TestManual (0.00s)
check_test.go:161: testdata/manual.go:14:7: initialization cycle for c
testdata/manual.go:14:7: c refers to
testdata/manual.go:14:7: c
This is a compiler bug: The compiler supplies its own size computation function to the type checker, and this size computation function assumes that a type cannot be invalid, which it is in this case. In contrast, the types2 size computation function has a catch-all for cases like these.
We just need to decide if a catch-all or adding the invalid case (adding an entry basicSizes in noder/sizes.go) to is the better solution.
Activity
findleyr commentedon May 7, 2022
Huh, this reports an initialization cycle when type-checking. For example, after copying the above into
cmd/compile/internal/types2/testdata/manual.go:How does it get past type-checking?
findleyr commentedon May 7, 2022
Aha, full stack is below. It's getting to
noder.gcSizes.Sizeof, despite the cycle error. Probably this is actually a types2 bug.griesemer commentedon May 7, 2022
This is a compiler bug: The compiler supplies its own size computation function to the type checker, and this size computation function assumes that a type cannot be invalid, which it is in this case. In contrast, the types2 size computation function has a catch-all for cases like these.
We just need to decide if a catch-all or adding the invalid case (adding an entry basicSizes in noder/sizes.go) to is the better solution.
gopherbot commentedon May 7, 2022
Change https://go.dev/cl/404894 mentions this issue:
cmd/compile: don't crash in size computation for invalid typecmd/compile: don't crash in size computation for invalid type