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: typecheck panic, internal compiler error: panic: runtime error: index out of range [0] with length 0 #50598

Closed
zhuah opened this issue Jan 13, 2022 · 2 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@zhuah
Copy link

zhuah commented Jan 13, 2022

What version of Go are you using (go version)?

$ go version
go version devel go1.18-24239120bf Thu Jan 13 00:53:53 2022 +0000 darwin/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env

What did you do?

My another program panicked with the latest commit,
i have uploaded the reproduce demo to https://go.dev/play/p/-NG-TpesDJO?v=gotip,

-- go.mod --
module test
-- p0/p.go --
package p0

type Builder[T any] struct{}

func (r Builder[T]) New1() T {
	var v T
	return v
}

func (r Builder[T]) New2() T {
	var v T
	return v
}

type IntBuilder struct{}

func (b IntBuilder) New() int {
	return Builder[int]{}.New2()
}
-- p1/p.go --
package p1

import "test/p0"

func New() int {
	return p0.IntBuilder{}.New()
}
-- p2/p.go --
package p2

import "test/p0"

func New() int {
	return p0.Builder[int]{}.New1()
}
-- main.go --
package main

import (
	"test/p1"
	"test/p2"
)

func New() int {
	return p1.New() + p2.New()
}

func main() {
	println(New())
}

and the error logs is here:

# test
./main.go:9:26: internal compiler error: panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
runtime/debug.Stack()
	/usr/local/Cellar/gotip/src/runtime/debug/stack.go:24 +0x65
cmd/compile/internal/base.FatalfAt({0x640798?, 0xc0?}, {0x191a094, 0x9}, {0xc0006407a0, 0x1, 0x1})
	/usr/local/Cellar/gotip/src/cmd/compile/internal/base/print.go:227 +0x1ca
cmd/compile/internal/base.Fatalf(...)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/base/print.go:196
cmd/compile/internal/gc.handlePanic()
	/usr/local/Cellar/gotip/src/cmd/compile/internal/gc/main.go:49 +0x85
panic({0x18e1a60, 0xc000632108})
	/usr/local/Cellar/gotip/src/runtime/panic.go:838 +0x207
cmd/compile/internal/typecheck.(*importReader).readFuncDcls.func1(...)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/typecheck/iimport.go:1174
cmd/compile/internal/typecheck.(*importReader).readFuncDcls(0x4?, 0xc000630580)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/typecheck/iimport.go:1185 +0x23c
cmd/compile/internal/typecheck.(*importReader).funcBody(0xc000615c20, 0xc000630580)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/typecheck/iimport.go:1125 +0x65
cmd/compile/internal/typecheck.(*importReader).doInline(0x1?, 0xc000630580)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/typecheck/iimport.go:1092 +0x99
cmd/compile/internal/typecheck.ImportBody(0xc000630580)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/typecheck/iimport.go:80 +0x206
cmd/compile/internal/typecheck.ImportedBody(0xc000630580)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/typecheck/func.go:174 +0xad
cmd/compile/internal/inline.oldInline(0xc000615b00, 0xc000630580, 0x4)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/inline/inl.go:801 +0x53
cmd/compile/internal/inline.mkinlcall(0xc000615b00, 0xc000630580, 0x420190?, 0xc00061c000, 0x203000?)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/inline/inl.go:753 +0xcc5
cmd/compile/internal/inline.inlnode({0x1a90ab8, 0xc000615b00}, 0x641160?, 0x58?, 0xc000641228?)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/inline/inl.go:589 +0x535
cmd/compile/internal/inline.InlineCalls.func1({0x1a90ab8?, 0xc000615b00?})
	/usr/local/Cellar/gotip/src/cmd/compile/internal/inline/inl.go:508 +0x31
cmd/compile/internal/ir.editNodes(...)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/ir/node_gen.go:1521
cmd/compile/internal/ir.(*AssignListStmt).editChildren(0xc0006126c0, 0xc00061e000)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/ir/node_gen.go:108 +0xc2
cmd/compile/internal/ir.EditChildren(...)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/ir/visit.go:185
cmd/compile/internal/inline.inlnode({0x1a90540, 0xc0006126c0}, 0x64c0d0?, 0x203000?, 0xc000646fc0?)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/inline/inl.go:568 +0x39a
cmd/compile/internal/inline.InlineCalls.func1({0x1a90540?, 0xc0006126c0?})
	/usr/local/Cellar/gotip/src/cmd/compile/internal/inline/inl.go:508 +0x31
cmd/compile/internal/ir.editNodes(...)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/ir/node_gen.go:1521
cmd/compile/internal/ir.(*BlockStmt).editChildren(0x1a90928?, 0xc00061e000)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/ir/node_gen.go:229 +0xa2
cmd/compile/internal/ir.EditChildren(...)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/ir/visit.go:185
cmd/compile/internal/inline.inlnode({0x1a90928, 0xc00061a740}, 0x6413f8?, 0x58?, 0xc0006414c0?)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/inline/inl.go:568 +0x39a
cmd/compile/internal/inline.InlineCalls.func1({0x1a90928?, 0xc00061a740?})
	/usr/local/Cellar/gotip/src/cmd/compile/internal/inline/inl.go:508 +0x31
cmd/compile/internal/ir.editNodes(...)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/ir/node_gen.go:1521
cmd/compile/internal/ir.(*InlinedCallExpr).editChildren(0xc000646fc0, 0xc00061e000)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/ir/node_gen.go:724 +0x182
cmd/compile/internal/ir.EditChildren(...)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/ir/visit.go:185
cmd/compile/internal/inline.mkinlcall(0xc000178bd0, 0xc0004111e0, 0x4205a0?, 0xc00061c000, 0x0?)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/inline/inl.go:762 +0xcda
cmd/compile/internal/inline.inlnode({0x1a90ab8, 0xc000178bd0}, 0x6413f8?, 0x58?, 0xc000641808?)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/inline/inl.go:589 +0x535
cmd/compile/internal/inline.InlineCalls.func1({0x1a90ab8?, 0xc000178bd0?})
	/usr/local/Cellar/gotip/src/cmd/compile/internal/inline/inl.go:508 +0x31
cmd/compile/internal/ir.(*BinaryExpr).editChildren(0xc000424240, 0xc00061e000)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/ir/node_gen.go:207 +0xc8
cmd/compile/internal/ir.EditChildren(...)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/ir/visit.go:185
cmd/compile/internal/inline.inlnode({0x1a90860, 0xc000424240}, 0x30?, 0x255ffff?, 0xc000413930?)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/inline/inl.go:568 +0x39a
cmd/compile/internal/inline.InlineCalls.func1({0x1a90860?, 0xc000424240?})
	/usr/local/Cellar/gotip/src/cmd/compile/internal/inline/inl.go:508 +0x31
cmd/compile/internal/ir.editNodes(...)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/ir/node_gen.go:1521
cmd/compile/internal/ir.(*ReturnStmt).editChildren(0x1a92610?, 0xc00061e000)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/ir/node_gen.go:1056 +0xa2
cmd/compile/internal/ir.EditChildren(...)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/ir/visit.go:185
cmd/compile/internal/inline.inlnode({0x1a92610, 0xc000420910}, 0x9882e40?, 0x20?, 0x2200f18?)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/inline/inl.go:568 +0x39a
cmd/compile/internal/inline.InlineCalls.func1({0x1a92610?, 0xc000420910?})
	/usr/local/Cellar/gotip/src/cmd/compile/internal/inline/inl.go:508 +0x31
cmd/compile/internal/ir.editNodes(...)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/ir/node_gen.go:1521
cmd/compile/internal/ir.(*Func).editChildren(0xc000413aa8?, 0xc00061e000?)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/ir/func.go:153 +0x74
cmd/compile/internal/ir.EditChildren(...)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/ir/visit.go:185
cmd/compile/internal/inline.InlineCalls(0xc000410dc0)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/inline/inl.go:510 +0xf2
cmd/compile/internal/inline.InlinePackage.func1({0xc00000e550, 0x1, 0xc000410dc0?}, 0x0)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/inline/inl.go:71 +0x6e
cmd/compile/internal/ir.(*bottomUpVisitor).visit(0xc0003dbe00, 0xc000410dc0)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/ir/scc.go:127 +0x2f0
cmd/compile/internal/ir.VisitFuncsBottomUp({0xc0004262e0, 0x2, 0xb?}, 0x1949c78)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/ir/scc.go:60 +0x105
cmd/compile/internal/inline.InlinePackage()
	/usr/local/Cellar/gotip/src/cmd/compile/internal/inline/inl.go:58 +0x33
cmd/compile/internal/gc.Main(0x1949b30)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/gc/main.go:247 +0xd34
main.main()
	/usr/local/Cellar/gotip/src/cmd/compile/main.go:55 +0xdd

What did you expect to see?

What did you see instead?

@ALTree ALTree added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jan 13, 2022
@ALTree ALTree added this to the Go1.18 milestone Jan 13, 2022
@danscales danscales self-assigned this Jan 13, 2022
@gopherbot
Copy link
Contributor

Change https://golang.org/cl/378494 mentions this issue: cmd/compile: add call to ImportedBody() when exporting shape inst body

@danscales
Copy link
Contributor

@zhuah Thanks for filing the issue and giving what looks like a minimized test case! It's a nice addition to our set of tests. Please keep filing issues if you have any further problems!

jproberts pushed a commit to jproberts/go that referenced this issue Jun 21, 2022
When we export a shape instantiation, because a particular
fully-instantiated type is needed by an inlineable function, we possibly
export the body of the instantiation, if it is inlineable. In this case,
we should have been calling ImportedBody() to make sure that the
function body had already been read in (if it is actually imported from
another package).

Fixes golang#50598

Change-Id: I512d2bcc745faa6ff3a97e25bc8f46e2c2643d23
Reviewed-on: https://go-review.googlesource.com/c/go/+/378494
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Keith Randall <khr@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 NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants