Skip to content

[dev.typeparams] internal compiler error: cannot export = (22) node #47514

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

Closed
e-nikolov opened this issue Aug 3, 2021 · 16 comments
Closed

[dev.typeparams] internal compiler error: cannot export = (22) node #47514

e-nikolov opened this issue Aug 3, 2021 · 16 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@e-nikolov
Copy link

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

$ gotip version 
go version devel go1.18-1b193598b3a Tue Aug 3 02:42:15 2021 +0000 linux/amd64

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

go env Output
$ gotip env   
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/enikolov/.cache/go-build"
GOENV="/home/enikolov/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/enikolov/.asdf/installs/golang/1.16.6/packages/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/enikolov/.asdf/installs/golang/1.16.6/packages"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/enikolov/sdk/gotip"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/enikolov/sdk/gotip/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="devel go1.18-1b193598b3a Tue Aug 3 02:42:15 2021 +0000"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/enikolov/dev/golang-design/go2generics/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3230277771=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I tried to compile the following program

package main

func Do[T any]() {
	_ = func() string {
		return ""
	}
}

func main() {

}

using

gotip run -gcflags=all=-G=3 main.go

What did you expect to see?

I expected it to compile

What did you see instead?

# command-line-arguments
main.go:5:3: internal compiler error: cannot export = (22) node
        ==> please file an issue and assign to gri@

goroutine 1 [running]:
runtime/debug.Stack()
        /home/enikolov/sdk/gotip/src/runtime/debug/stack.go:24 +0x65
cmd/compile/internal/base.FatalfAt({0x4913b0, 0xc0}, {0xd0be24, 0x47}, {0xc000455418, 0x2, 0x2})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/base/print.go:227 +0x154
cmd/compile/internal/base.Fatalf(...)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/base/print.go:196
cmd/compile/internal/typecheck.(*exportWriter).expr(0xc00049d7a0, {0xe575f0, 0xc0004913b0})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/typecheck/iexport.go:2056 +0x19c5
cmd/compile/internal/typecheck.(*exportWriter).exprList(0xc00049d7a0, {0xc000488340, 0x1, 0x604639})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/typecheck/iexport.go:1618 +0x76
cmd/compile/internal/typecheck.(*exportWriter).stmt(0xc00049d7a0, {0xe59468, 0xc000490460})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/typecheck/iexport.go:1512 +0x83f
cmd/compile/internal/typecheck.(*exportWriter).node(0xc000455546, {0xe59468, 0xc000490460})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/typecheck/iexport.go:1438 +0x65
cmd/compile/internal/typecheck.(*exportWriter).stmtList(0xc00049d7a0, {0xc000488310, 0x1, 0xc000455596})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/typecheck/iexport.go:1431 +0x76
cmd/compile/internal/typecheck.(*exportWriter).expr(0xc00049d7a0, {0xe57c30, 0xc000490280})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/typecheck/iexport.go:1732 +0x1efa
cmd/compile/internal/typecheck.(*exportWriter).stmt(0xc00049d7a0, {0xe575f0, 0xc0004904b0})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/typecheck/iexport.go:1484 +0x22d
cmd/compile/internal/typecheck.(*exportWriter).node(0x30, {0xe575f0, 0xc0004904b0})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/typecheck/iexport.go:1438 +0x65
cmd/compile/internal/typecheck.(*exportWriter).stmtList(0xc00049d7a0, {0xc0004881a0, 0x1, 0xcb7140})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/typecheck/iexport.go:1431 +0x76
cmd/compile/internal/typecheck.(*exportWriter).funcBody(0xc00049d7a0, 0xc00048a2c0)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/typecheck/iexport.go:1426 +0x5b
cmd/compile/internal/typecheck.(*iexporter).doInline(0xc0003ac370, 0xc00049a5b0)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/typecheck/iexport.go:619 +0xc5
cmd/compile/internal/typecheck.(*exportWriter).funcExt(0xc00049cd20, 0xc00049a5b0)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/typecheck/iexport.go:1363 +0x1b6
cmd/compile/internal/typecheck.(*iexporter).doDecl(0xc0003ac370, 0xc00049a5b0)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/typecheck/iexport.go:503 +0x1d7
cmd/compile/internal/typecheck.WriteExports({0xe3f160, 0xc0000a7530}, 0x1)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/typecheck/iexport.go:300 +0x2eb
cmd/compile/internal/noder.WriteExports(0xc00007e330)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/noder/export.go:40 +0x7a
cmd/compile/internal/gc.dumpCompilerObj(0xc00007e330)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/gc/obj.go:107 +0x28
cmd/compile/internal/gc.dumpobj1({0x7ffd056a0007, 0x24}, 0x3)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/gc/obj.go:63 +0x185
cmd/compile/internal/gc.dumpobj()
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/gc/obj.go:44 +0x36
cmd/compile/internal/gc.Main(0xd13510)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/gc/main.go:321 +0x10d6
main.main()
        /home/enikolov/sdk/gotip/src/cmd/compile/main.go:55 +0xdd
@seankhliao
Copy link
Member

seankhliao commented Aug 3, 2021

cc @griesemer
or should we close these?

@seankhliao seankhliao added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Aug 3, 2021
@cuonglm
Copy link
Member

cuonglm commented Aug 3, 2021

cc @danscales @randall77

PS: Unified IR does not have this problem.

@griesemer griesemer added this to the Go1.18 milestone Aug 3, 2021
@danscales danscales self-assigned this Aug 4, 2021
@randall77
Copy link
Contributor

Looks like we're trying to export an expression, and come across an OAS. From here:

. RETURN tc(1) # issue47514.go:5:3
. RETURN-Results
. . AS tc(1) # issue47514.go:5:3
. . . NAME-main.~r0 tc(1) Class:PPARAMOUT Offset:0 OnStack string # issue47514.go:4:13
. . . LITERAL-"" tc(1) string # issue47514.go:5:10

But, this OAS is only generated during walk. We're then trying to export it, after walk, which doesn't seem right to me.

@cuonglm
Copy link
Member

cuonglm commented Aug 6, 2021

@randall77 Yeah, I think the problem is that in irgen.funcDecl, we set fn.Inl.Body = fn.Body. Thus later, fn.Body is changed during walk, cause fn.Inl.Body also changed.

I think irgen need to do something like unified IR exapandInline does.

@gopherbot
Copy link
Contributor

Change https://golang.org/cl/340258 mentions this issue: [dev.typeparams] cmd/compile: make sure closures inside generic funcs are not compiled

@e-nikolov
Copy link
Author

e-nikolov commented Aug 6, 2021

I can confirm that the original case works now, but I have another case that might be related:

package main

func Do[T any](do func() (T, T)) {
	_ = func() (T, T) {
		return do()
	}
}

func main() {
	Do[int](func() (int, int) {
		return 3, 3
	})
}

results in:

# command-line-arguments
panic: runtime error: index out of range [1] with length 1

goroutine 1 [running]:
cmd/compile/internal/noder.typecheckaste(0xd0, {0xe44468, 0xc0001397c0}, 0x0, 0x8, {0xc00011ee20, 0x1, 0xc00043bef0}, 0x1)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/noder/transform.go:511 +0x3d5
cmd/compile/internal/noder.(*irgen).stmt(0xc00015c300, {0xe448e8, 0xc0003ffcc0})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/noder/stmt.go:134 +0xd0b
cmd/compile/internal/noder.(*irgen).stmts(0xc000448d20, {0xc00011ebd0, 0x1, 0xbd3578})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/noder/stmt.go:18 +0xaf
cmd/compile/internal/noder.(*irgen).funcBody(0xc00015c300, 0xc000446dc0, 0xc00043be00, 0xc000139740, 0xc000139780)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/noder/func.go:46 +0x25e
cmd/compile/internal/noder.(*irgen).funcLit(0xc00015c300, {0xe43800, 0xc000139bc0}, 0xc0003ffca0)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/noder/expr.go:456 +0xe8
cmd/compile/internal/noder.(*irgen).expr0(0xc00015c300, {0xe43800, 0xc000139bc0}, {0xe44678, 0xc0003ffca0})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/noder/expr.go:108 +0x905
cmd/compile/internal/noder.(*irgen).expr(0xc00015c300, {0xe44678, 0xc0003ffca0})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/noder/expr.go:79 +0x5d4
cmd/compile/internal/noder.(*irgen).exprs(0x10, {0xc0004593a0, 0x1, 0x403829})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/noder/expr.go:412 +0x8e
cmd/compile/internal/noder.(*irgen).exprList(0x0, {0xe44678, 0xc0003ffca0})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/noder/expr.go:395 +0x85
cmd/compile/internal/noder.(*irgen).stmt(0xc00015c300, {0xe44378, 0xc000139800})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/noder/stmt.go:75 +0x3ab
cmd/compile/internal/noder.(*irgen).stmts(0xc000448a10, {0xc00011ebe0, 0x1, 0x7f3ac53bf768})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/noder/stmt.go:18 +0xaf
cmd/compile/internal/noder.(*irgen).funcBody(0xc00015c300, 0xc000446c60, 0x0, 0xc000139680, 0xc000139700)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/noder/func.go:46 +0x25e
cmd/compile/internal/noder.(*irgen).funcDecl(0xc00015c300, 0xc000459788, 0xc000137b60)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/noder/decl.go:108 +0x26f
cmd/compile/internal/noder.(*irgen).decls(0xc00015c300, {0xc0003ffea0, 0x2, 0xc00043bae0})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/noder/decl.go:28 +0x152
cmd/compile/internal/noder.(*irgen).generate(0xc00015c300, {0xc00011eb40, 0x2, 0x203000})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/noder/irgen.go:232 +0x4b9
cmd/compile/internal/noder.check2({0xc00011eb40, 0x2, 0x2})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/noder/irgen.go:92 +0x16d
cmd/compile/internal/noder.LoadPackage({0xc00013a120, 0x2, 0x0})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/noder/noder.go:90 +0x365
cmd/compile/internal/gc.Main(0xd135c0)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/gc/main.go:190 +0xaf3
main.main()
        /home/enikolov/sdk/gotip/src/cmd/compile/main.go:55 +0xdd

It seems to happen when there is a list of returned types, at least one of which is parameterized.

@danscales
Copy link
Contributor

Yes, thanks for the original case and the new case! I'm aware of the issue of the new case, which relates to the use of multiple return values in generic calls. The original case is mainly related to closures in generic functions, so they are largely unrelated. I'll leave the issue open for the second case, which I'm still working on the cleanest way to fix.

gopherbot pushed a commit that referenced this issue Aug 6, 2021
… are not compiled

Closures inside generic functions were being added to the g.target.Decls
list during noding, just like other closures. We remove generic
functions/methods from g.target.Decls, so they don't get compiled
(they're only available for export and stenciling). Most closures inside
generic functions/methods were similarly being removed from
g.target.Decls, because they have a generic parameter. But we need to
ensure no closures in generic function/methods are left remaining in
g.target.Decls, since we don't want them transformed and compiled.

So, we set a flag in (*irgen) that records when we are noding a
top-level generic function/method, and don't add any closures to
g.target.Decls when the flag is true.

Updates #47514

Change-Id: Id66b4c41d307ffa8f54cab6ce3646ade81606862
Reviewed-on: https://go-review.googlesource.com/c/go/+/340258
Trust: Dan Scales <[email protected]>
Reviewed-by: Keith Randall <[email protected]>
@gopherbot
Copy link
Contributor

Change https://golang.org/cl/340531 mentions this issue: [dev.typeparams] cmd/compile: call transformArgs before early typecheckaste in noder

@e-nikolov
Copy link
Author

Another case:

package main

func doFn(s string) {
	return
}

func Do[T any](do func(T)) {
	x := (interface{})(*new(T))
	do(x.(T))
}

func main() {
	Do(doFn)
}

# command-line-arguments
demo/bug3/main.go:9:6: internal compiler error: mayCall 
.   DYNAMICDOTTYPE tc(1) .shape.string # main.go:9:6 .shape.string
.   .   NAME-main.x esc(no) tc(1) Class:PAUTO Offset:0 OnStack INTER-interface {} # main.go:8:2
.   DYNAMICDOTTYPE-T
.   .   INDEX tc(1) Bounded PTR-*uint8 # main.go:9:6 PTR-*uint8
.   .   .   DEREF tc(1) ARRAY-[3]uintptr # main.go:9:6 ARRAY-[3]uintptr
.   .   .   .   CONVNOP tc(1) PTR-*[3]uintptr # main.go:9:6 PTR-*[3]uintptr
.   .   .   .   .   CONVNOP tc(1) UNSAFEPTR-unsafe.Pointer # main.go:9:6 UNSAFEPTR-unsafe.Pointer
.   .   .   .   .   .   NAME-main..dict esc(no) tc(1) Class:PPARAM Offset:0 OnStack uintptr # main.go:7:6
.   .   .   LITERAL-0 tc(1) uintptr # main.go:7:6

goroutine 1 [running]:
runtime/debug.Stack()
        /home/enikolov/sdk/gotip/src/runtime/debug/stack.go:24 +0x65
cmd/compile/internal/base.FatalfAt({0x11aea0, 0xc0}, {0xce665d, 0xb}, {0xc0000b7628, 0x1, 0x1})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/base/print.go:227 +0x154
cmd/compile/internal/walk.mayCall.func2({0xe56fc0, 0xc00011aea0})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/walk/walk.go:308 +0x3c9
cmd/compile/internal/ir.Any.func1({0xe56fc0, 0xc00011aea0})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/ir/visit.go:130 +0x30
cmd/compile/internal/ir.Any({0xe56fc0, 0xc00011aea0}, 0xc00011c280)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/ir/visit.go:132 +0xb8
cmd/compile/internal/walk.mayCall({0xe56fc0, 0xc00011aea0})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/walk/walk.go:299 +0x73
cmd/compile/internal/walk.walkCall1(0xc000140510, 0xc0000b7aa0)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/walk/expr.go:586 +0x2f8
cmd/compile/internal/walk.walkCall(0xc000140510, 0xe564d0)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/walk/expr.go:556 +0x6b2
cmd/compile/internal/walk.walkExpr1({0xe568b8, 0xc000140510}, 0xc000140510)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/walk/expr.go:176 +0x485
cmd/compile/internal/walk.walkExpr({0xe568b8, 0xc000140510}, 0xc0000b7aa0)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/walk/expr.go:55 +0x3a5
cmd/compile/internal/walk.walkStmt({0xe568b8, 0xc000140510})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/walk/stmt.go:57 +0x59d
cmd/compile/internal/walk.walkStmtList({0xc00015a700, 0x5, 0xc00011e6e0})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/walk/stmt.go:167 +0x5b
cmd/compile/internal/walk.Walk(0xc00011e6e0)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/walk/walk.go:43 +0xef
cmd/compile/internal/gc.prepareFunc(0xc00011e6e0)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/gc/compile.go:92 +0x6d
cmd/compile/internal/gc.enqueueFunc(0xc00011e6e0)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/gc/compile.go:66 +0x2f7
cmd/compile/internal/gc.Main(0xd126a0)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/gc/main.go:292 +0xe5f
main.main()
        /home/enikolov/sdk/gotip/src/cmd/compile/main.go:55 +0xdd

If I move the type assertion .(T) to the previous line, it works fine, so it seems that it only fails in case of type assertions in the argument of a function call

@e-nikolov
Copy link
Author

e-nikolov commented Aug 7, 2021

And another similar case but with a different error:

package main

func doFn(s string) {
	return
}

func Do[T any](do func(string)) {
	_ = (interface{})(*new(string)).(string)
}

func main() {
	Do[string](doFn)
}
# command-line-arguments
demo/bug3/main.go:12:13: internal compiler error: assertion failed

goroutine 1 [running]:
runtime/debug.Stack()
        /home/enikolov/sdk/gotip/src/runtime/debug/stack.go:24 +0x65
cmd/compile/internal/base.FatalfAt({0x12a8c0, 0xc0}, {0xceb5d4, 0x10}, {0x0, 0x0, 0x0})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/base/print.go:227 +0x154
cmd/compile/internal/base.Fatalf(...)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/base/print.go:196
cmd/compile/internal/base.Assert(...)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/base/print.go:239
cmd/compile/internal/noder.assert(...)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:27
cmd/compile/internal/noder.(*subster).node.func1({0xe58ca8, 0xc00011a8a0})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:1125 +0x8ad
cmd/compile/internal/ir.(*AssignStmt).editChildren(0xc0001256d0, 0xc000120258)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/ir/node_gen.go:163 +0xb5
cmd/compile/internal/ir.EditChildren(...)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/ir/visit.go:185
cmd/compile/internal/noder.(*subster).node.func1({0xe564d0, 0xc0001245f0})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:901 +0x416
cmd/compile/internal/noder.(*subster).node(0xc00013c080, {0xe564d0, 0xc0001245f0})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:1150 +0xa5
cmd/compile/internal/noder.(*subster).list(0x13af040, {0xc00011c220, 0x1, 0xc000094640})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:1233 +0x8e
cmd/compile/internal/noder.(*irgen).genericSubst(0xc00014e000, 0xc000125540, 0xc00012e9c0, {0xc000118178, 0x1, 0x1}, 0x0, 0xc00012a8c0)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:714 +0xcc6
cmd/compile/internal/noder.(*irgen).getInstantiation(0xc00014e000, 0xc00012e9c0, {0xc000118170, 0x1, 0x1}, 0x0)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:600 +0x33d
cmd/compile/internal/noder.(*irgen).stencil.func1({0xe568b8, 0xc0001521b0})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:109 +0x2df
cmd/compile/internal/ir.Visit.func1({0xe568b8, 0xc0001521b0})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/ir/visit.go:105 +0x30
cmd/compile/internal/ir.doNodes({0xc00011c260, 0x1, 0x0}, 0xc0001201f8)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/ir/node_gen.go:1484 +0x67
cmd/compile/internal/ir.(*Func).doChildren(0xe57150, 0xc00011e580)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/ir/func.go:152 +0x2e
cmd/compile/internal/ir.DoChildren(...)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/ir/visit.go:94
cmd/compile/internal/ir.Visit.func1({0xe57150, 0xc00011e580})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/ir/visit.go:106 +0x57
cmd/compile/internal/ir.Visit({0xe57150, 0xc00011e580}, 0xc00012a880)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/ir/visit.go:108 +0xb8
cmd/compile/internal/noder.(*irgen).stencil(0xc00014e000)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:91 +0x265
cmd/compile/internal/noder.(*irgen).generate(0xc00014e000, {0xc00007eb20, 0x2, 0x203000})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/noder/irgen.go:261 +0x259
cmd/compile/internal/noder.check2({0xc00007eb20, 0x2, 0x2})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/noder/irgen.go:92 +0x16d
cmd/compile/internal/noder.LoadPackage({0xc00001e260, 0x2, 0x0})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/noder/noder.go:90 +0x365
cmd/compile/internal/gc.Main(0xd126a0)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/gc/main.go:190 +0xaf3
main.main()
        /home/enikolov/sdk/gotip/src/cmd/compile/main.go:55 +0xdd

@e-nikolov
Copy link
Author

Let me know if listsing those cases here is fine, or if I should create separate issues.

@e-nikolov
Copy link
Author

And another one: https://github.com/e-nikolov/go-generics-issues/tree/master/issue5

// main.go

package main

import "github.com/e-nikolov/go-generics-issues/issue5/pkg"

func Do[T any](doer pkg.Doer[T]) {
	doer.Do()
}

func main() {
}

// pkg/doer.go

package pkg

type Doer[T any] interface {
	Do() T
}

results in:

# command-line-arguments
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x5f1f7b]

goroutine 1 [running]:
cmd/compile/internal/typecheck.(*crawler).checkGenericType(0xc00012f380, 0x0)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/typecheck/crawler.go:227 +0x3b
cmd/compile/internal/typecheck.(*crawler).markInlBody.func1({0xe59030, 0xc00012f380})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/typecheck/crawler.go:201 +0xb2
cmd/compile/internal/ir.Visit.func1({0xe59030, 0xc00012f380})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/ir/visit.go:105 +0x30
cmd/compile/internal/ir.(*SelectorExpr).doChildren(0xc00011acc0, 0xc00000c108)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/ir/node_gen.go:1067 +0x62
cmd/compile/internal/ir.DoChildren(...)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/ir/visit.go:94
cmd/compile/internal/ir.Visit.func1({0xe59738, 0xc00011acc0})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/ir/visit.go:106 +0x57
cmd/compile/internal/ir.(*CallExpr).doChildren(0xc000144510, 0xc00000c108)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/ir/node_gen.go:260 +0x64
cmd/compile/internal/ir.DoChildren(...)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/ir/visit.go:94
cmd/compile/internal/ir.Visit.func1({0xe57b18, 0xc000144510})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/ir/visit.go:106 +0x57
cmd/compile/internal/ir.Visit({0xe57b18, 0xc000144510}, 0xc00000c0f0)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/ir/visit.go:108 +0xb8
cmd/compile/internal/ir.VisitList({0xc00011c280, 0x1, 0xc000130700}, 0xc0001305b0)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/ir/visit.go:114 +0x65
cmd/compile/internal/typecheck.(*crawler).markInlBody(0xc00007e3e0, 0xc0001305b0)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/typecheck/crawler.go:217 +0x22d
cmd/compile/internal/typecheck.(*crawler).markObject(0xc00002a270, 0xc00012f2b0)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/typecheck/crawler.go:35 +0x2f
cmd/compile/internal/typecheck.crawlExports({0xc00058e020, 0x3, 0xc0005b9960})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/typecheck/crawler.go:23 +0x9f
cmd/compile/internal/typecheck.WriteExports({0xe3f3e0, 0xc0003eee70}, 0x1)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/typecheck/iexport.go:272 +0x65
cmd/compile/internal/noder.WriteExports(0xc00011c350)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/noder/export.go:40 +0x7a
cmd/compile/internal/gc.dumpCompilerObj(0xc00011c350)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/gc/obj.go:107 +0x28
cmd/compile/internal/gc.dumpobj1({0x7ffc528a6016, 0x24}, 0x3)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/gc/obj.go:63 +0x185
cmd/compile/internal/gc.dumpobj()
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/gc/obj.go:44 +0x36
cmd/compile/internal/gc.Main(0xd13700)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/gc/main.go:318 +0x10b6
main.main()
        /home/enikolov/sdk/gotip/src/cmd/compile/main.go:55 +0xdd

gopherbot pushed a commit that referenced this issue Aug 9, 2021
…ckaste in noder

In the cases where we do an early call to typecheckaste() in noder to
expose CONVIFACE nodes, we need a preceding call to transformArgs().
This is needed to allow typecheckaste() to run correctly, in the case of
f(g()), where g has multiple return values.

I also cleaned up the code a bit and commented the code in Call(), and
we do the call to typecheckaste() in several more cases.

In stencil.go:stencil(), I moved the transformCall earlier for the
OCALLMETH/ODOTMETH case, just as I did in my previous CL for
OCALL/OFUNCINST. By doing this, transformArgs no longer needs to deal
with the extra dictionary args. Therefore, I was able to simply
transformArgs() to look like typecheckargs() again, and make use of
RewriteMultiValue directly.

Updates #47514

Change-Id: I49eb82ac05707e50c2e2fb03e39458a70491d406
Reviewed-on: https://go-review.googlesource.com/c/go/+/340531
Trust: Dan Scales <[email protected]>
Run-TryBot: Dan Scales <[email protected]>
TryBot-Result: Go Bot <[email protected]>
Reviewed-by: Keith Randall <[email protected]>
@danscales
Copy link
Contributor

Thanks for the three new cases, @e-nikolov ! I'll update this issue as I have time to triage and/or fix each case.

@danscales
Copy link
Contributor

And another similar case but with a different error:

package main

func doFn(s string) {
	return
}

func Do[T any](do func(string)) {
	_ = (interface{})(*new(string)).(string)
}

func main() {
	Do[string](doFn)
}
# command-line-arguments
demo/bug3/main.go:12:13: internal compiler error: assertion failed

goroutine 1 [running]:
runtime/debug.Stack()
        /home/enikolov/sdk/gotip/src/runtime/debug/stack.go:24 +0x65
cmd/compile/internal/base.FatalfAt({0x12a8c0, 0xc0}, {0xceb5d4, 0x10}, {0x0, 0x0, 0x0})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/base/print.go:227 +0x154
cmd/compile/internal/base.Fatalf(...)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/base/print.go:196
cmd/compile/internal/base.Assert(...)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/base/print.go:239
cmd/compile/internal/noder.assert(...)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:27
cmd/compile/internal/noder.(*subster).node.func1({0xe58ca8, 0xc00011a8a0})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:1125 +0x8ad
cmd/compile/internal/ir.(*AssignStmt).editChildren(0xc0001256d0, 0xc000120258)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/ir/node_gen.go:163 +0xb5
cmd/compile/internal/ir.EditChildren(...)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/ir/visit.go:185
cmd/compile/internal/noder.(*subster).node.func1({0xe564d0, 0xc0001245f0})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:901 +0x416
cmd/compile/internal/noder.(*subster).node(0xc00013c080, {0xe564d0, 0xc0001245f0})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:1150 +0xa5
cmd/compile/internal/noder.(*subster).list(0x13af040, {0xc00011c220, 0x1, 0xc000094640})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:1233 +0x8e
cmd/compile/internal/noder.(*irgen).genericSubst(0xc00014e000, 0xc000125540, 0xc00012e9c0, {0xc000118178, 0x1, 0x1}, 0x0, 0xc00012a8c0)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:714 +0xcc6
cmd/compile/internal/noder.(*irgen).getInstantiation(0xc00014e000, 0xc00012e9c0, {0xc000118170, 0x1, 0x1}, 0x0)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:600 +0x33d
cmd/compile/internal/noder.(*irgen).stencil.func1({0xe568b8, 0xc0001521b0})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:109 +0x2df
cmd/compile/internal/ir.Visit.func1({0xe568b8, 0xc0001521b0})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/ir/visit.go:105 +0x30
cmd/compile/internal/ir.doNodes({0xc00011c260, 0x1, 0x0}, 0xc0001201f8)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/ir/node_gen.go:1484 +0x67
cmd/compile/internal/ir.(*Func).doChildren(0xe57150, 0xc00011e580)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/ir/func.go:152 +0x2e
cmd/compile/internal/ir.DoChildren(...)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/ir/visit.go:94
cmd/compile/internal/ir.Visit.func1({0xe57150, 0xc00011e580})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/ir/visit.go:106 +0x57
cmd/compile/internal/ir.Visit({0xe57150, 0xc00011e580}, 0xc00012a880)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/ir/visit.go:108 +0xb8
cmd/compile/internal/noder.(*irgen).stencil(0xc00014e000)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:91 +0x265
cmd/compile/internal/noder.(*irgen).generate(0xc00014e000, {0xc00007eb20, 0x2, 0x203000})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/noder/irgen.go:261 +0x259
cmd/compile/internal/noder.check2({0xc00007eb20, 0x2, 0x2})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/noder/irgen.go:92 +0x16d
cmd/compile/internal/noder.LoadPackage({0xc00001e260, 0x2, 0x0})
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/noder/noder.go:90 +0x365
cmd/compile/internal/gc.Main(0xd126a0)
        /home/enikolov/sdk/gotip/src/cmd/compile/internal/gc/main.go:190 +0xaf3
main.main()
        /home/enikolov/sdk/gotip/src/cmd/compile/main.go:55 +0xdd

I believe this case (your 2nd-to-last example) was fixed by https://go-review.googlesource.com/c/go/+/342989 by Keith.

I still need to investigate the last and 3rd-to-last examples.

@gopherbot
Copy link
Contributor

Change https://golang.org/cl/345411 mentions this issue: cmd/compile: fix reference to generic type needed by crawler

@danscales
Copy link
Contributor

I believe all your cases are fixed. My just checked-in change fixes the last case you added, and the 3rd to last case that you added (the mayCall error) was fixed by https://go-review.googlesource.com/c/go/+/344571

Feel free to create a new issue if one of these still doesn't seem to work, or you find a new case that doesn't work.

@golang golang locked and limited conversation to collaborators Jun 23, 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

7 participants