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: internal compiler error: assertion failed #47710

Closed
4ad opened this issue Aug 15, 2021 · 3 comments
Closed

cmd/compile: internal compiler error: assertion failed #47710

4ad opened this issue Aug 15, 2021 · 3 comments
Assignees
Milestone

Comments

@4ad
Copy link
Member

@4ad 4ad commented Aug 15, 2021

On 48dfddb.

Repro:

package main

import "fmt"

type Foo[t any] interface {
	Foo(Bar[t])
}
type Bar[t any] interface {
	Int(Int[t]) Foo[int]
}

type Int[t any] int

func (n Int[t]) Foo(v Bar[t])   { v.Int(n) }
func (n Int[_]) String() string { return fmt.Sprintf("(int %d)", n) }

func main() {
	fmt.Println("hello")
}

with -gcflags='-G=3' this fails with

go run -gcflags='-G=3' e.go
# command-line-arguments
<unknown line number>: internal compiler error: assertion failed

goroutine 1 [running]:
runtime/debug.Stack()
	/Users/aram/go/src/runtime/debug/stack.go:24 +0x65
cmd/compile/internal/base.FatalfAt({0xab6c0, 0xc0}, {0x18ef5c4, 0x10}, {0x0, 0x0, 0x0})
	/Users/aram/go/src/cmd/compile/internal/base/print.go:227 +0x154
cmd/compile/internal/base.Fatalf(...)
	/Users/aram/go/src/cmd/compile/internal/base/print.go:196
cmd/compile/internal/base.Assert(...)
	/Users/aram/go/src/cmd/compile/internal/base/print.go:239
cmd/compile/internal/typecheck.assert(...)
	/Users/aram/go/src/cmd/compile/internal/typecheck/subr.go:976
cmd/compile/internal/typecheck.(*Tsubster).Typ(0xc0000e83d8, 0xc0000aae70)
	/Users/aram/go/src/cmd/compile/internal/typecheck/subr.go:1065 +0x1325
cmd/compile/internal/typecheck.(*Tsubster).tstruct(0xc0000e83d8, 0xc0000ab180, 0x0)
	/Users/aram/go/src/cmd/compile/internal/typecheck/subr.go:1266 +0x15c
cmd/compile/internal/typecheck.(*Tsubster).Typ(0xc0000e83d8, 0xc0000ab030)
	/Users/aram/go/src/cmd/compile/internal/typecheck/subr.go:1111 +0x185
cmd/compile/internal/noder.(*irgen).fillinMethods(0xc0000ec000, 0xc0000caaa0, 0xc0000ab570)
	/Users/aram/go/src/cmd/compile/internal/noder/types.go:317 +0x645
cmd/compile/internal/noder.(*irgen).typ0(0xc0000ec000, {0x1a47090, 0xc0000caaa0})
	/Users/aram/go/src/cmd/compile/internal/noder/types.go:151 +0x1295
cmd/compile/internal/noder.(*irgen).typ1(0xc0000ec000, {0x1a47090, 0xc0000caaa0})
	/Users/aram/go/src/cmd/compile/internal/noder/types.go:61 +0x65
cmd/compile/internal/noder.(*irgen).typ(0xc0000d0780, {0x1a47090, 0xc0000caaa0})
	/Users/aram/go/src/cmd/compile/internal/noder/types.go:33 +0x27
cmd/compile/internal/noder.(*irgen).obj(0xc0000ec000, {0x1a58158, 0xc0000d0780})
	/Users/aram/go/src/cmd/compile/internal/noder/object.go:100 +0x7cf
cmd/compile/internal/noder.(*irgen).fillinMethods(0xc0000ec000, 0xc0000cac80, 0xc0000aafc0)
	/Users/aram/go/src/cmd/compile/internal/noder/types.go:286 +0x1ff
cmd/compile/internal/noder.(*irgen).typ0(0xc0000ec000, {0x1a47090, 0xc0000cac80})
	/Users/aram/go/src/cmd/compile/internal/noder/types.go:151 +0x1295
cmd/compile/internal/noder.(*irgen).typ1(0xc0000ec000, {0x1a47090, 0xc0000cac80})
	/Users/aram/go/src/cmd/compile/internal/noder/types.go:61 +0x65
cmd/compile/internal/noder.(*irgen).param(0xc0000ec000, 0xc0000d1620)
	/Users/aram/go/src/cmd/compile/internal/noder/types.go:362 +0x74
cmd/compile/internal/noder.(*irgen).signature.func1(0xc0000989f0)
	/Users/aram/go/src/cmd/compile/internal/noder/types.go:348 +0xa5
cmd/compile/internal/noder.(*irgen).signature(0xc0000ec000, 0x0, 0xc0000a3400)
	/Users/aram/go/src/cmd/compile/internal/noder/types.go:352 +0x233
cmd/compile/internal/noder.(*irgen).typ0(0xc0000ec000, {0x1a47040, 0xc0000ccc30})
	/Users/aram/go/src/cmd/compile/internal/noder/types.go:205 +0xefc
cmd/compile/internal/noder.(*irgen).typ1(0xc0000ec000, {0x1a47040, 0xc0000ccc30})
	/Users/aram/go/src/cmd/compile/internal/noder/types.go:61 +0x65
cmd/compile/internal/noder.(*irgen).typ0(0xc0000ec000, {0x1a47090, 0xc0000cab40})
	/Users/aram/go/src/cmd/compile/internal/noder/types.go:150 +0x1268
cmd/compile/internal/noder.(*irgen).typ1(0xc0000ec000, {0x1a47090, 0xc0000cab40})
	/Users/aram/go/src/cmd/compile/internal/noder/types.go:61 +0x65
cmd/compile/internal/noder.(*irgen).param(0xc0000ec000, 0xc0000d16e0)
	/Users/aram/go/src/cmd/compile/internal/noder/types.go:362 +0x74
cmd/compile/internal/noder.(*irgen).signature.func1(0xc000098a08)
	/Users/aram/go/src/cmd/compile/internal/noder/types.go:348 +0xa5
cmd/compile/internal/noder.(*irgen).signature(0xc0000ec000, 0x2c, 0xc0000a3440)
	/Users/aram/go/src/cmd/compile/internal/noder/types.go:352 +0x233
cmd/compile/internal/noder.(*irgen).typ0(0xc0000ec000, {0x1a47040, 0xc0000ccc80})
	/Users/aram/go/src/cmd/compile/internal/noder/types.go:205 +0xefc
cmd/compile/internal/noder.(*irgen).typ1(0xc0000ec000, {0x1a47040, 0xc0000ccc80})
	/Users/aram/go/src/cmd/compile/internal/noder/types.go:61 +0x65
cmd/compile/internal/noder.(*irgen).typ0(0xc0000ec000, {0x1a47090, 0xc0000ca820})
	/Users/aram/go/src/cmd/compile/internal/noder/types.go:150 +0x1268
cmd/compile/internal/noder.(*irgen).typ1(0xc0000ec000, {0x1a47090, 0xc0000ca820})
	/Users/aram/go/src/cmd/compile/internal/noder/types.go:61 +0x65
cmd/compile/internal/noder.(*irgen).param(0xc0000ec000, 0xc0000d0cc0)
	/Users/aram/go/src/cmd/compile/internal/noder/types.go:362 +0x74
cmd/compile/internal/noder.(*irgen).signature.func1(0xc0000988d0)
	/Users/aram/go/src/cmd/compile/internal/noder/types.go:348 +0xa5
cmd/compile/internal/noder.(*irgen).signature(0xc0000ec000, 0x10ce30a, 0xc0000a3580)
	/Users/aram/go/src/cmd/compile/internal/noder/types.go:353 +0x269
cmd/compile/internal/noder.(*irgen).typ0(0xc0000ec000, {0x1a47040, 0xc0000cccd0})
	/Users/aram/go/src/cmd/compile/internal/noder/types.go:205 +0xefc
cmd/compile/internal/noder.(*irgen).typ1(0xc0000ec000, {0x1a47040, 0xc0000cccd0})
	/Users/aram/go/src/cmd/compile/internal/noder/types.go:61 +0x65
cmd/compile/internal/noder.(*irgen).typ0(0xc0000ec000, {0x1a47090, 0xc0000caa00})
	/Users/aram/go/src/cmd/compile/internal/noder/types.go:150 +0x1268
cmd/compile/internal/noder.(*irgen).typ1(0xc0000ec000, {0x1a47090, 0xc0000caa00})
	/Users/aram/go/src/cmd/compile/internal/noder/types.go:61 +0x65
cmd/compile/internal/noder.(*irgen).param(0xc0000ec000, 0xc0000d1200)
	/Users/aram/go/src/cmd/compile/internal/noder/types.go:362 +0x74
cmd/compile/internal/noder.(*irgen).signature.func1(0xc000098948)
	/Users/aram/go/src/cmd/compile/internal/noder/types.go:348 +0xa5
cmd/compile/internal/noder.(*irgen).signature(0xc0000ec000, 0xc0000d10e0, 0xc0000a3000)
	/Users/aram/go/src/cmd/compile/internal/noder/types.go:352 +0x233
cmd/compile/internal/noder.(*irgen).obj(0xc0000ec000, {0x1a58158, 0xc0000d06c0})
	/Users/aram/go/src/cmd/compile/internal/noder/object.go:102 +0x805
cmd/compile/internal/noder.(*irgen).fillinMethods(0xc0000ec000, 0xc0000ca960, 0xc0000aad90)
	/Users/aram/go/src/cmd/compile/internal/noder/types.go:286 +0x1ff
cmd/compile/internal/noder.(*irgen).typ0(0xc0000ec000, {0x1a47090, 0xc0000ca960})
	/Users/aram/go/src/cmd/compile/internal/noder/types.go:151 +0x1295
cmd/compile/internal/noder.(*irgen).typ1(0xc0000ec000, {0x1a47090, 0xc0000ca960})
	/Users/aram/go/src/cmd/compile/internal/noder/types.go:61 +0x65
cmd/compile/internal/noder.(*irgen).typ(0xc0000d06c0, {0x1a47090, 0xc0000ca960})
	/Users/aram/go/src/cmd/compile/internal/noder/types.go:33 +0x27
cmd/compile/internal/noder.(*irgen).obj(0xc0000ec000, {0x1a58158, 0xc0000d06c0})
	/Users/aram/go/src/cmd/compile/internal/noder/object.go:100 +0x7cf
cmd/compile/internal/noder.(*irgen).fillinMethods(0xc0000ec000, 0xc0000cabe0, 0xc0000aad20)
	/Users/aram/go/src/cmd/compile/internal/noder/types.go:286 +0x1ff
cmd/compile/internal/noder.(*irgen).typ0(0xc0000ec000, {0x1a47090, 0xc0000cabe0})
	/Users/aram/go/src/cmd/compile/internal/noder/types.go:151 +0x1295
cmd/compile/internal/noder.(*irgen).typ1(0xc0000ec000, {0x1a47090, 0xc0000cabe0})
	/Users/aram/go/src/cmd/compile/internal/noder/types.go:61 +0x65
cmd/compile/internal/noder.(*irgen).param(0xc0000ec000, 0xc0000d1500)
	/Users/aram/go/src/cmd/compile/internal/noder/types.go:362 +0x74
cmd/compile/internal/noder.(*irgen).signature.func1(0xc0000989a8)
	/Users/aram/go/src/cmd/compile/internal/noder/types.go:348 +0xa5
cmd/compile/internal/noder.(*irgen).signature(0xc0000ec000, 0x1a47040, 0xc0000a33c0)
	/Users/aram/go/src/cmd/compile/internal/noder/types.go:352 +0x233
cmd/compile/internal/noder.(*irgen).typ0(0xc0000ec000, {0x1a47040, 0xc0000ccbe0})
	/Users/aram/go/src/cmd/compile/internal/noder/types.go:205 +0xefc
cmd/compile/internal/noder.(*irgen).typ1(0xc0000ec000, {0x1a47040, 0xc0000ccbe0})
	/Users/aram/go/src/cmd/compile/internal/noder/types.go:61 +0x65
cmd/compile/internal/noder.(*irgen).typ0(0xc0000ec000, {0x1a47090, 0xc0000ca8c0})
	/Users/aram/go/src/cmd/compile/internal/noder/types.go:150 +0x1268
cmd/compile/internal/noder.(*irgen).typ1(0xc0000ec000, {0x1a47090, 0xc0000ca8c0})
	/Users/aram/go/src/cmd/compile/internal/noder/types.go:61 +0x65
cmd/compile/internal/noder.(*irgen).param(0xc0000ec000, 0xc0000d0ea0)
	/Users/aram/go/src/cmd/compile/internal/noder/types.go:362 +0x74
cmd/compile/internal/noder.(*irgen).signature.func1(0xc000098900)
	/Users/aram/go/src/cmd/compile/internal/noder/types.go:348 +0xa5
cmd/compile/internal/noder.(*irgen).signature(0xc0000ec000, 0x120, 0xc0000a2d40)
	/Users/aram/go/src/cmd/compile/internal/noder/types.go:352 +0x233
cmd/compile/internal/noder.(*irgen).typ0(0xc0000ec000, {0x1a47040, 0xc0000ccb40})
	/Users/aram/go/src/cmd/compile/internal/noder/types.go:205 +0xefc
cmd/compile/internal/noder.(*irgen).typ1(0xc0000ec000, {0x1a47040, 0xc0000ccb40})
	/Users/aram/go/src/cmd/compile/internal/noder/types.go:61 +0x65
cmd/compile/internal/noder.(*irgen).typ(0x1871200, {0x1a47040, 0xc0000ccb40})
	/Users/aram/go/src/cmd/compile/internal/noder/types.go:33 +0x27
cmd/compile/internal/noder.(*irgen).expr(0xc0000ec000, {0x1a48048, 0xc00008c090})
	/Users/aram/go/src/cmd/compile/internal/noder/expr.go:46 +0x90a
cmd/compile/internal/noder.(*irgen).typeExpr(0xc0000ec000, {0x1a48048, 0xc00008c090})
	/Users/aram/go/src/cmd/compile/internal/noder/expr.go:483 +0x31
cmd/compile/internal/noder.(*irgen).typeDecl(0xc0000ec000, 0xc0001381b0, 0xc000092060)
	/Users/aram/go/src/cmd/compile/internal/noder/decl.go:171 +0x10f
cmd/compile/internal/noder.(*irgen).generate(0xc0000ec000, {0xc000064b70, 0x2, 0x203000})
	/Users/aram/go/src/cmd/compile/internal/noder/irgen.go:228 +0x729
cmd/compile/internal/noder.check2({0xc000064b70, 0x2, 0x2})
	/Users/aram/go/src/cmd/compile/internal/noder/irgen.go:92 +0x16d
cmd/compile/internal/noder.LoadPackage({0xc00001e260, 0x2, 0x0})
	/Users/aram/go/src/cmd/compile/internal/noder/noder.go:90 +0x365
cmd/compile/internal/gc.Main(0x1916550)
	/Users/aram/go/src/cmd/compile/internal/gc/main.go:190 +0xaf3
main.main()
	/Users/aram/go/src/cmd/compile/main.go:55 +0xdd

Works on go2go playground: https://go2goplay.golang.org/p/kPeQ-34axPT

Removing either one of Int's methods makes the compiler happy.

@4ad 4ad added this to the Go1.18 milestone Aug 15, 2021
@griesemer
Copy link
Contributor

@griesemer griesemer commented Aug 16, 2021

Slightly simpler reproducer:

package p

type Foo[t any] interface {
	Foo(Bar[t])
}
type Bar[t any] interface {
	Int(Int[t]) Foo[int]
}

type Int[t any] int

func (n Int[t]) Foo(Bar[t]) {}
func (n Int[_]) String()    {}

Looks like an issue with types2 to types(1) translation.
cc: @danscales

Loading

@danscales danscales self-assigned this Aug 18, 2021
@danscales
Copy link

@danscales danscales commented Aug 18, 2021

Yes, this is a types2-to-types1 translation problem. I'll take this one. Adding Type to the end of the type names to be clearer, we have FooType's definition depends on BarType, BarType's definition depends on IntType and FooType, and IntType's methods depend on BarType. I think we may just need a "delay" queue to call fillinMethods on types that have been translated recursively after the top-level (possibly mutually recursive) types have been translated.

Loading

@gopherbot
Copy link

@gopherbot gopherbot commented Aug 25, 2021

Change https://golang.org/cl/345149 mentions this issue: cmd/compile: delay fillinMethods to deal with mutually-recursive types

Loading

@gopherbot gopherbot closed this in d7e2e2e Aug 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants