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: compiler crash with circular (but valid) generic alias #50779

Closed
ianlancetaylor opened this issue Jan 24, 2022 · 2 comments
Closed
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@ianlancetaylor
Copy link
Contributor

Compiling this program with tip crashes the compiler.

package p

type AC interface {
	C
}

type ST []int

type R[S any, P any] struct {}

type SR = R[SS, ST]

type SS interface {
	NSR(any) *SR
}

type C interface {
	NSR(any) *SR
}
<autogenerated>:1: internal compiler error: panic: runtime error: invalid memory address or nil pointer dereference

goroutine 1 [running]:
runtime/debug.Stack()
	/home/iant/go/src/runtime/debug/stack.go:24 +0x65
cmd/compile/internal/base.FatalfAt({0x4?, 0x0?}, {0xd1f6c4, 0x9}, {0xc0000d6b08, 0x1, 0x1})
	/home/iant/go/src/cmd/compile/internal/base/print.go:227 +0x1ca
cmd/compile/internal/base.Fatalf(...)
	/home/iant/go/src/cmd/compile/internal/base/print.go:196
cmd/compile/internal/gc.handlePanic()
	/home/iant/go/src/cmd/compile/internal/gc/main.go:49 +0x85
panic({0xca9460, 0x130cdf0})
	/home/iant/go/src/runtime/panic.go:838 +0x207
cmd/compile/internal/types.PtrDataSize(0xe972b8?)
	/home/iant/go/src/cmd/compile/internal/types/size.go:646 +0x18
cmd/compile/internal/types.(*Type).HasPointers(...)
	/home/iant/go/src/cmd/compile/internal/types/type.go:1682
cmd/compile/internal/escape.(*escape).exprSkipInit(0xc0003dc4c0, {0xc000636bd0?, 0x6f3008?, 0x0?, 0x0?}, {0xe972b8, 0xc0003241b0?})
	/home/iant/go/src/cmd/compile/internal/escape/expr.go:33 +0x176
cmd/compile/internal/escape.(*escape).expr(0xc000636bd0?, {0xc000636bd0?, 0x0?, 0x0?, 0x10?}, {0xe972b8, 0xc0003241b0})
	/home/iant/go/src/cmd/compile/internal/escape/expr.go:20 +0xad
cmd/compile/internal/escape.(*escape).assignList(0xc0003dc4c0, {0xc0000a6500, 0x1, 0x0?}, {0xc0000a64b0, 0x1, 0x203000?}, {0xd1b025, 0x6}, {0xe98e10, ...})
	/home/iant/go/src/cmd/compile/internal/escape/assign.go:93 +0x3d6
cmd/compile/internal/escape.(*escape).stmt(0xc0003dc4c0, {0xe98e10, 0xc00007ca00?})
	/home/iant/go/src/cmd/compile/internal/escape/stmt.go:175 +0x1577
cmd/compile/internal/escape.(*escape).stmts(...)
	/home/iant/go/src/cmd/compile/internal/escape/stmt.go:190
cmd/compile/internal/escape.(*escape).block(0xc0003dc4c0?, {0xc0000a64c0?, 0x1?, 0xc000326480?})
	/home/iant/go/src/cmd/compile/internal/escape/stmt.go:197 +0x72
cmd/compile/internal/escape.(*batch).walkFunc(0xc000326480, 0xc0003d6c60)
	/home/iant/go/src/cmd/compile/internal/escape/escape.go:227 +0xe5
cmd/compile/internal/escape.Batch({0xc0000d76b0?, 0x1, 0x1}, 0xc8?)
	/home/iant/go/src/cmd/compile/internal/escape/escape.go:143 +0x228
cmd/compile/internal/reflectdata.methodWrapper(0xc0003b2d20, 0xc0003ec1e0, 0x88?)
	/home/iant/go/src/cmd/compile/internal/reflectdata/reflect.go:1974 +0x1871
cmd/compile/internal/reflectdata.imethods(0xc0003b2d20)
	/home/iant/go/src/cmd/compile/internal/reflectdata/reflect.go:395 +0x2d9
cmd/compile/internal/reflectdata.writeType(0xc0003b2d90?)
	/home/iant/go/src/cmd/compile/internal/reflectdata/reflect.go:1054 +0x5cd
cmd/compile/internal/reflectdata.WriteRuntimeTypes()
	/home/iant/go/src/cmd/compile/internal/reflectdata/reflect.go:1266 +0x3d8
cmd/compile/internal/gc.dumpdata()
	/home/iant/go/src/cmd/compile/internal/gc/obj.go:118 +0x6e
cmd/compile/internal/gc.Main(0xd4f728)
	/home/iant/go/src/cmd/compile/internal/gc/main.go:328 +0x11ab
main.main()
	/home/iant/go/src/cmd/compile/main.go:55 +0xdd

CC @randall77 @danscales

@ianlancetaylor ianlancetaylor added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker labels Jan 24, 2022
@ianlancetaylor ianlancetaylor added this to the Go1.18 milestone Jan 24, 2022
@griesemer
Copy link
Contributor

This will report an error with forthcoming CL 379916. Leaving open for now so I can add a test. Not a release blocker.

@griesemer griesemer self-assigned this Jan 24, 2022
@griesemer griesemer added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker labels Jan 24, 2022
@gopherbot
Copy link

Change https://golang.org/cl/379916 mentions this issue: go/types, types2: report an error when using a broken alias

jproberts pushed a commit to jproberts/go that referenced this issue Jun 21, 2022
The type checker doesn't have a general mechanism to "use" the type
of a type alias whose type depends on a recursive type declaration
which is not yet completely type-checked. In some cases, the type of
a type alias is needed before it is determined; the type is incorrect
(invalid) in that case but no error is reported. The type-checker is
happy with this (incorrect type), but the compiler may crash under
some circumstances.

A correct fix will likely require some form of forwarding type which
is a fairly pervasive change and may also affect the type checker API.

This CL introduces a simple side table, a map of broken type aliases,
which is consulted before the type associated with a type alias is
used. If the type alias is broken, an error is reported.

This is a stop-gap solution that prevents the compiler from crashing.
The reported error refers to the corresponding issue which suggests
a work-around that may be applicable in some cases.

Also fix a minor error related to type cycles: If we have a cycle
that doesn't start with a type, don't use a compiler error message
that explicitly mentions "type".

Fixes golang#50259.
Fixes golang#50276.
Fixes golang#50779.

For golang#50729.

Change-Id: Ie8e38f49ef724e742e8e78625e6d4f3d4014a52c
Reviewed-on: https://go-review.googlesource.com/c/go/+/379916
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
@golang golang locked and limited conversation to collaborators Jun 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge 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