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, interface conversion: types.Object is nil, not *ir.Name #50552

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

Comments

@zhuah
Copy link

zhuah commented Jan 11, 2022

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

$ go version
go version devel go1.18-6df0957060 Mon Jan 10 04:23:42 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?

After updated to latest tip commit, my package failed to compile:
It seems due to this commit 931e84a

I have made a reproduce demo based on #50121 and 5b9207f

-- go.mod --
module test

-- pkg/pkg.go --
package pkg

type Builder[T any] struct{}

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

func (r Builder[T]) New2() T {
	return r.New()
}

func BuildInt() int {
	return Builder[int]{}.New()
}

-- main.go --
package main

import (
	"fmt"

	"test/pkg"
)

func BuildInt() int {
	return pkg.BuildInt()
}

func main() {
	fmt.Println(BuildInt())
}

the difference with #50121 is the func (r Builder[T]) New2() T method.
and the error logs is here:

# test
panic: interface conversion: types.Object is nil, not *ir.Name

goroutine 1 [running]:
cmd/compile/internal/typecheck.(*crawler).markInlBody.func1({0x1a8fee0, 0xc0000b4300?})
	/usr/local/Cellar/gotip/src/cmd/compile/internal/typecheck/crawler.go:257 +0x60e
cmd/compile/internal/ir.Visit.func1({0x1a8fee0, 0xc0000b4300})
	/usr/local/Cellar/gotip/src/cmd/compile/internal/ir/visit.go:105 +0x30
cmd/compile/internal/ir.doNodes(...)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/ir/node_gen.go:1512
cmd/compile/internal/ir.(*CallExpr).doChildren(0xc0000a0a20, 0xc00011bec0)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/ir/node_gen.go:263 +0x132
cmd/compile/internal/ir.DoChildren(...)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/ir/visit.go:94
cmd/compile/internal/ir.Visit.func1({0x1a8faf8, 0xc0000a0a20})
	/usr/local/Cellar/gotip/src/cmd/compile/internal/ir/visit.go:106 +0x57
cmd/compile/internal/ir.doNodes(...)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/ir/node_gen.go:1512
cmd/compile/internal/ir.(*ReturnStmt).doChildren(0x1a91650?, 0xc00011bec0)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/ir/node_gen.go:1049 +0x8c
cmd/compile/internal/ir.DoChildren(...)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/ir/visit.go:94
cmd/compile/internal/ir.Visit.func1({0x1a91650, 0xc000092f00})
	/usr/local/Cellar/gotip/src/cmd/compile/internal/ir/visit.go:106 +0x57
cmd/compile/internal/ir.Visit({0x1a91650, 0xc000092f00}, 0xc00011bea8)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/ir/visit.go:108 +0xb8
cmd/compile/internal/ir.VisitList(...)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/ir/visit.go:114
cmd/compile/internal/typecheck.(*crawler).markInlBody(0xc00011be60, 0x1886720?)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/typecheck/crawler.go:327 +0x2f4
cmd/compile/internal/typecheck.(*crawler).markInlBody.func1({0x1a910d8, 0xc000455790?})
	/usr/local/Cellar/gotip/src/cmd/compile/internal/typecheck/crawler.go:305 +0x225
cmd/compile/internal/ir.Visit.func1({0x1a910d8, 0xc000455790})
	/usr/local/Cellar/gotip/src/cmd/compile/internal/ir/visit.go:105 +0x30
cmd/compile/internal/ir.(*CallExpr).doChildren(0xc000390ea0, 0xc00011be90)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/ir/node_gen.go:260 +0x56
cmd/compile/internal/ir.DoChildren(...)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/ir/visit.go:94
cmd/compile/internal/ir.Visit.func1({0x1a8faf8, 0xc000390ea0})
	/usr/local/Cellar/gotip/src/cmd/compile/internal/ir/visit.go:106 +0x57
cmd/compile/internal/ir.doNodes(...)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/ir/node_gen.go:1512
cmd/compile/internal/ir.(*ReturnStmt).doChildren(0x1a91650?, 0xc00011be90)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/ir/node_gen.go:1049 +0x8c
cmd/compile/internal/ir.DoChildren(...)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/ir/visit.go:94
cmd/compile/internal/ir.Visit.func1({0x1a91650, 0xc0004764b0})
	/usr/local/Cellar/gotip/src/cmd/compile/internal/ir/visit.go:106 +0x57
cmd/compile/internal/ir.Visit({0x1a91650, 0xc0004764b0}, 0xc00011be78)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/ir/visit.go:108 +0xb8
cmd/compile/internal/ir.VisitList(...)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/ir/visit.go:114
cmd/compile/internal/typecheck.(*crawler).markInlBody(0xc00011be60, 0x18c5f20?)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/typecheck/crawler.go:327 +0x2f4
cmd/compile/internal/typecheck.(*crawler).markObject(0x10cd89e?, 0xc000455450)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/typecheck/crawler.go:50 +0x2f
cmd/compile/internal/typecheck.crawlExports({0xc00008d7a0, 0x2, 0x10d1d2c?})
	/usr/local/Cellar/gotip/src/cmd/compile/internal/typecheck/crawler.go:37 +0xbf
cmd/compile/internal/typecheck.WriteExports({0x1a89fa0, 0xc0005cb740}, 0x1)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/typecheck/iexport.go:305 +0x65
cmd/compile/internal/noder.WriteExports(0xc0005d4590)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/noder/export.go:40 +0x7a
cmd/compile/internal/gc.dumpCompilerObj(0xc0005d4590?)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/gc/obj.go:107 +0x28
cmd/compile/internal/gc.dumpobj1({0x7ffeefbff239, 0x50}, 0x3)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/gc/obj.go:63 +0x17b
cmd/compile/internal/gc.dumpobj()
	/usr/local/Cellar/gotip/src/cmd/compile/internal/gc/obj.go:44 +0x36
cmd/compile/internal/gc.Main(0x1948e30)
	/usr/local/Cellar/gotip/src/cmd/compile/internal/gc/main.go:330 +0x11bc
main.main()
	/usr/local/Cellar/gotip/src/cmd/compile/main.go:55 +0xdd

@ALTree
Copy link
Member

ALTree commented Jan 11, 2022

Another issue with the same error: #48094.

cc @danscales @randall77

@ALTree ALTree added this to the Go1.18 milestone Jan 11, 2022
@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 11, 2022
@danscales danscales self-assigned this Jan 11, 2022
@gopherbot
Copy link

Change https://golang.org/cl/377714 mentions this issue: cmd/compile: resolve dictionaries/shape methods in markInlBody, if needed

@danscales
Copy link
Contributor

@zhuah Thanks for the issue report and the simplified test case. It pointed out a problem with my recent change for generics and inlining, and also another nice test case in general.

@gopherbot
Copy link

Change https://go.dev/cl/390335 mentions this issue: cmd/compile: fix reentrancy issue in unified IR function body reading

gopherbot pushed a commit that referenced this issue Mar 7, 2022
We shouldn't need to read in function bodies for new functions found
during inlining, but something is expecting them to still be read
in. We should fix that code to not depend on them being read in, but
in the mean time reading them in anyway is at least correct, albeit
less efficient in time and space.

Fixes #49536.
Updates #50552.

Change-Id: I949ef45e7be09406e5a8149e251d78e015aca5fa
Reviewed-on: https://go-review.googlesource.com/c/go/+/390335
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Trust: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
@dmitshur dmitshur 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. labels Mar 8, 2022
jproberts pushed a commit to jproberts/go that referenced this issue Jun 21, 2022
…eded

Issue golang#50552 is due to a problem with my recent improvement in the
interaction between generics and inlining. In markInlBody(), we now mark
dictionaries and shape methods for export, so they will be available for
any package that inlines the current inlineable function. But we need to
make sure that the dictionary and method symbols have actually been
resolved into Nodes (looked up in the import data), if they are not
already defined, so we can then mark them for export.

Improved header comment on Resolve().

Fixes golang#50552

Change-Id: I89e52d39d3b9894591d2ad6eb3a8ed3bb5f1e0a0
Reviewed-on: https://go-review.googlesource.com/c/go/+/377714
Reviewed-by: Keith Randall <khr@golang.org>
Trust: Dan Scales <danscales@google.com>
@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

5 participants