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 failing for generic code #50841

Closed
randall77 opened this issue Jan 26, 2022 · 2 comments
Closed

cmd/compile: compiler failing for generic code #50841

randall77 opened this issue Jan 26, 2022 · 2 comments
Milestone

Comments

@randall77
Copy link
Contributor

@randall77 randall77 commented Jan 26, 2022

package a

func Marshal[foobar any]() {
	_ = NewEncoder[foobar]()
}

func NewEncoder[foobar any]() *Encoder[foobar] {
	return nil
}

type Encoder[foobar any] struct {
}

func (e *Encoder[foobar]) EncodeToken(t Token[foobar]) {

}

type Token[foobar any] any
package b

import "a"

func F() {
	a.Marshal[int]()
}

The compiler fails when compiling b with:

$GOROOT/test/typeparam/issueXXXX.dir/a.go:18:6: internal compiler error: failed to find type loop for: a.Token[int]

goroutine 1 [running]:
runtime/debug.Stack()
	/Users/khr/sandbox/ro/src/runtime/debug/stack.go:24 +0x65
cmd/compile/internal/base.FatalfAt({0x1?, 0x0?}, {0x193390a, 0x20}, {0xc0003ead00, 0x1, 0x1})
	/Users/khr/sandbox/ro/src/cmd/compile/internal/base/print.go:227 +0x1d7
cmd/compile/internal/base.Fatalf(...)
	/Users/khr/sandbox/ro/src/cmd/compile/internal/base/print.go:196
cmd/compile/internal/types.reportTypeLoop(0xc0003ed880)
	/Users/khr/sandbox/ro/src/cmd/compile/internal/types/size.go:312 +0xbf
cmd/compile/internal/types.CalcSize(0xc0003ed880)
	/Users/khr/sandbox/ro/src/cmd/compile/internal/types/size.go:477 +0x68d
cmd/compile/internal/types.calcStructOffset(0xc0003ed960, 0xc0003edab0, 0x8, 0x8)
	/Users/khr/sandbox/ro/src/cmd/compile/internal/types/size.go:191 +0xd3
cmd/compile/internal/types.CalcSize(0xc0003edb90)
	/Users/khr/sandbox/ro/src/cmd/compile/internal/types/size.go:532 +0x90e
cmd/compile/internal/types.ResumeCheckSize()
	/Users/khr/sandbox/ro/src/cmd/compile/internal/types/size.go:633 +0x4e
cmd/compile/internal/typecheck.(*Tsubster).Typ(0x1f95aa0?, 0xc0003e0340?)
	/Users/khr/sandbox/ro/src/cmd/compile/internal/typecheck/subr.go:1051 +0x2f
cmd/compile/internal/noder.(*genInst).getDictionarySym(0x1f95aa0, 0xc0003e0340, {0xc0000ba518, 0x1, 0x1}, 0x0)
	/Users/khr/sandbox/ro/src/cmd/compile/internal/noder/stencil.go:1565 +0x437
cmd/compile/internal/noder.(*genInst).getDictionaryValue(0x0?, {0xba4f0?, 0xc0?}, 0xc0000ba618?, {0xc0000ba518?, 0xc0003d7600?, 0xc0000abd70?}, 0xc0?)
	/Users/khr/sandbox/ro/src/cmd/compile/internal/noder/stencil.go:1764 +0x39
cmd/compile/internal/noder.(*genInst).getDictOrSubdict(0x1f95aa0?, 0xc0003e0340?, {0x1a94718?, 0xc0003207e0?}, 0xc0000d53a8?, {0xc0000ba518, 0x1, 0x1}, 0x0?)
	/Users/khr/sandbox/ro/src/cmd/compile/internal/noder/stencil.go:601 +0xdc
cmd/compile/internal/noder.(*genInst).scanForGenCalls.func1({0x1a94718, 0xc0003207e0?})
	/Users/khr/sandbox/ro/src/cmd/compile/internal/noder/stencil.go:152 +0x32f
cmd/compile/internal/ir.Visit.func1({0x1a94718, 0xc0003207e0})
	/Users/khr/sandbox/ro/src/cmd/compile/internal/ir/visit.go:105 +0x30
cmd/compile/internal/ir.doNodes(...)
	/Users/khr/sandbox/ro/src/cmd/compile/internal/ir/node_gen.go:1512
cmd/compile/internal/ir.(*Func).doChildren(0x1a95078?, 0xc0000abad0?)
	/Users/khr/sandbox/ro/src/cmd/compile/internal/ir/func.go:152 +0x6e
cmd/compile/internal/ir.DoChildren(...)
	/Users/khr/sandbox/ro/src/cmd/compile/internal/ir/visit.go:94
cmd/compile/internal/ir.Visit.func1({0x1a95078, 0xc0003d7080})
	/Users/khr/sandbox/ro/src/cmd/compile/internal/ir/visit.go:106 +0x57
cmd/compile/internal/ir.Visit({0x1a95078, 0xc0003d7080}, 0xc0000bfbc0)
	/Users/khr/sandbox/ro/src/cmd/compile/internal/ir/visit.go:108 +0xb8
cmd/compile/internal/noder.(*genInst).scanForGenCalls(0x1f95aa0, {0x1a95078, 0xc0003d7080})
	/Users/khr/sandbox/ro/src/cmd/compile/internal/noder/stencil.go:133 +0x1f0
cmd/compile/internal/noder.(*genInst).buildInstantiations(0x1f95aa0)
	/Users/khr/sandbox/ro/src/cmd/compile/internal/noder/stencil.go:60 +0x69
cmd/compile/internal/noder.BuildInstantiations(...)
	/Users/khr/sandbox/ro/src/cmd/compile/internal/noder/stencil.go:44
cmd/compile/internal/noder.(*irgen).generate(0xc0002f6240, {0xc0000ba428, 0x1, 0x203000?})
	/Users/khr/sandbox/ro/src/cmd/compile/internal/noder/irgen.go:331 +0x3d1
cmd/compile/internal/noder.check2({0xc0000ba428, 0x1, 0x1})
	/Users/khr/sandbox/ro/src/cmd/compile/internal/noder/irgen.go:92 +0x16d
cmd/compile/internal/noder.LoadPackage({0xc0000c4070, 0x1, 0x0?})
	/Users/khr/sandbox/ro/src/cmd/compile/internal/noder/noder.go:90 +0x335
cmd/compile/internal/gc.Main(0x194d1c8)
	/Users/khr/sandbox/ro/src/cmd/compile/internal/gc/main.go:191 +0xb13
main.main()
	/Users/khr/sandbox/ro/src/cmd/compile/main.go:55 +0xdd

The error "failed to find type loop" isn't really the bug, as that just means it was trying to print an error and couldn't find out why it was trying to print the error. The real problem is why CalcSize is calling reportTypeLoop at all, as there shouldn't be an error. Something about stenciling/instantiating is making types that look incomplete when they shouldn't look that way.

@danscales

@gopherbot
Copy link

@gopherbot gopherbot commented Jan 26, 2022

Change https://golang.org/cl/381154 mentions this issue: cmd/compile: test for issue 50841

@danscales danscales self-assigned this Jan 27, 2022
@gopherbot
Copy link

@gopherbot gopherbot commented Jan 27, 2022

Change https://golang.org/cl/381175 mentions this issue: cmd/compile: add missing shape check in (*Tsubster).tinter

@danscales danscales added this to the Go1.18 milestone Jan 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants