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 #53762

Closed
Clemens-H opened this issue Jul 9, 2022 · 14 comments
Closed

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

Clemens-H opened this issue Jul 9, 2022 · 14 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Milestone

Comments

@Clemens-H
Copy link

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

$ go version
go version go1.19rc1 linux/amd64

and

go version devel go1.19-c1a4e0fe01 Fri Jul 8 23:41:37 2022 +0000 linux/amd64

Does this issue reproduce with the latest release?

No, it works fine with 1.18.3.

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/clemens/.cache/go-build"
GOENV="/home/clemens/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/clemens/src/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/clemens/src/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/clemens/sdk/gotip"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/clemens/sdk/gotip/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="devel go1.19-c1a4e0fe01 Fri Jul 8 23:41:37 2022 +0000"
GCCGO="/usr/bin/gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
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 -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2895368460=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Tried to compile some generics heavy code.

What did you expect to see?

A working program.

What did you see instead?

An internal compiler error.

I could not identify a small example using the referenced location.

I attach three traces here.

/home/clemens/Programs/Go/comp/sum.go:33:19: internal compiler error: assertion failed

goroutine 1 [running]:
runtime/debug.Stack()
        /home/clemens/sdk/gotip/src/runtime/debug/stack.go:24 +0x65
cmd/compile/internal/base.FatalfAt({0x11627f8?, 0xc0?}, {0xd428bb, 0x10}, {0x0, 0x0, 0x0})
        /home/clemens/sdk/gotip/src/cmd/compile/internal/base/print.go:227 +0x1d7
cmd/compile/internal/base.Fatalf(...)
        /home/clemens/sdk/gotip/src/cmd/compile/internal/base/print.go:196
cmd/compile/internal/base.Assert(...)
        /home/clemens/sdk/gotip/src/cmd/compile/internal/base/print.go:239
cmd/compile/internal/noder.assert(...)
        /home/clemens/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:27
cmd/compile/internal/noder.(*genInst).dictPass.func1({0xeafba8, 0xc0015ada90})
        /home/clemens/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:1367 +0x28c
cmd/compile/internal/ir.editNodes(...)
        /home/clemens/sdk/gotip/src/cmd/compile/internal/ir/node_gen.go:1388
cmd/compile/internal/ir.(*AssignListStmt).editChildren(0xc0011df020, 0xc000ca4660)
        /home/clemens/sdk/gotip/src/cmd/compile/internal/ir/node_gen.go:85 +0xc2
cmd/compile/internal/ir.EditChildren(...)
        /home/clemens/sdk/gotip/src/cmd/compile/internal/ir/visit.go:185
cmd/compile/internal/noder.(*genInst).dictPass.func1({0xead928, 0xc0011df020})
        /home/clemens/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:1256 +0x11b
cmd/compile/internal/ir.editNodes(...)
        /home/clemens/sdk/gotip/src/cmd/compile/internal/ir/node_gen.go:1388
cmd/compile/internal/ir.(*Func).editChildren(0xc0004ef510?, 0xc000ca4660?)
        /home/clemens/sdk/gotip/src/cmd/compile/internal/ir/func.go:152 +0x74
cmd/compile/internal/ir.EditChildren(...)
        /home/clemens/sdk/gotip/src/cmd/compile/internal/ir/visit.go:185
cmd/compile/internal/noder.(*genInst).dictPass.func1({0xeae618, 0xc000e63540})
        /home/clemens/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:1256 +0x11b
cmd/compile/internal/noder.(*genInst).dictPass(0x13cee40, 0xc0011627f8)
        /home/clemens/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:1426 +0x150
cmd/compile/internal/noder.(*genInst).buildInstantiations(0x13cee40)
        /home/clemens/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:78 +0x1cc
cmd/compile/internal/noder.BuildInstantiations(...)
        /home/clemens/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:44
cmd/compile/internal/noder.(*irgen).generate(0xc000172240, {0xc000152780, 0x14, 0x203000?})
        /home/clemens/sdk/gotip/src/cmd/compile/internal/noder/irgen.go:333 +0x3d1
cmd/compile/internal/noder.check2({0xc000152780, 0x14, 0x14})
        /home/clemens/sdk/gotip/src/cmd/compile/internal/noder/irgen.go:87 +0x14d
cmd/compile/internal/noder.LoadPackage({0xc000122100, 0x14, 0x14})
        /home/clemens/sdk/gotip/src/cmd/compile/internal/noder/noder.go:82 +0x48f
cmd/compile/internal/gc.Main(0xd6b110)
        /home/clemens/sdk/gotip/src/cmd/compile/internal/gc/main.go:189 +0xbbd
main.main()
        /home/clemens/sdk/gotip/src/cmd/compile/main.go:57 +0xdd
/home/clemens/Programs/Go/comp/sum.go:33:19: internal compiler error: assertion failed

goroutine 1 [running]:
runtime/debug.Stack()
        /home/clemens/sdk/gotip/src/runtime/debug/stack.go:24 +0x65
cmd/compile/internal/base.FatalfAt({0x16374e8?, 0xc0?}, {0xd428bb, 0x10}, {0x0, 0x0, 0x0})
        /home/clemens/sdk/gotip/src/cmd/compile/internal/base/print.go:227 +0x1d7
cmd/compile/internal/base.Fatalf(...)
        /home/clemens/sdk/gotip/src/cmd/compile/internal/base/print.go:196
cmd/compile/internal/base.Assert(...)
        /home/clemens/sdk/gotip/src/cmd/compile/internal/base/print.go:239
cmd/compile/internal/noder.assert(...)
        /home/clemens/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:27
cmd/compile/internal/noder.(*genInst).dictPass.func1({0xeafba8, 0xc00164e550})
        /home/clemens/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:1367 +0x28c
cmd/compile/internal/ir.editNodes(...)
        /home/clemens/sdk/gotip/src/cmd/compile/internal/ir/node_gen.go:1388
cmd/compile/internal/ir.(*AssignListStmt).editChildren(0xc001641980, 0xc0019d3590)
        /home/clemens/sdk/gotip/src/cmd/compile/internal/ir/node_gen.go:85 +0xc2
cmd/compile/internal/ir.EditChildren(...)
        /home/clemens/sdk/gotip/src/cmd/compile/internal/ir/visit.go:185
cmd/compile/internal/noder.(*genInst).dictPass.func1({0xead928, 0xc001641980})
        /home/clemens/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:1256 +0x11b
cmd/compile/internal/ir.editNodes(...)
        /home/clemens/sdk/gotip/src/cmd/compile/internal/ir/node_gen.go:1388
cmd/compile/internal/ir.(*Func).editChildren(0xc000d674f0?, 0xc0019d3590?)
        /home/clemens/sdk/gotip/src/cmd/compile/internal/ir/func.go:152 +0x74
cmd/compile/internal/ir.EditChildren(...)
        /home/clemens/sdk/gotip/src/cmd/compile/internal/ir/visit.go:185
cmd/compile/internal/noder.(*genInst).dictPass.func1({0xeae618, 0xc001603540})
        /home/clemens/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:1256 +0x11b
cmd/compile/internal/noder.(*genInst).dictPass(0x13cee40, 0xc0016374e8)
        /home/clemens/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:1426 +0x150
cmd/compile/internal/noder.(*genInst).buildInstantiations(0x13cee40)
        /home/clemens/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:78 +0x1cc
cmd/compile/internal/noder.BuildInstantiations(...)
        /home/clemens/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:44
cmd/compile/internal/noder.(*irgen).generate(0xc000172240, {0xc000152820, 0x14, 0x1411b00?})
        /home/clemens/sdk/gotip/src/cmd/compile/internal/noder/irgen.go:333 +0x3d1
cmd/compile/internal/noder.check2({0xc000152820, 0x14, 0x14})
        /home/clemens/sdk/gotip/src/cmd/compile/internal/noder/irgen.go:87 +0x14d
cmd/compile/internal/noder.LoadPackage({0xc000122100, 0x14, 0x14})
        /home/clemens/sdk/gotip/src/cmd/compile/internal/noder/noder.go:82 +0x48f
cmd/compile/internal/gc.Main(0xd6b110)
        /home/clemens/sdk/gotip/src/cmd/compile/internal/gc/main.go:189 +0xbbd
main.main()
        /home/clemens/sdk/gotip/src/cmd/compile/main.go:57 +0xdd
/home/clemens/Programs/Go/comp/sum.go:33:19: internal compiler error: assertion failed

goroutine 1 [running]:
runtime/debug.Stack()
        /home/clemens/sdk/gotip/src/runtime/debug/stack.go:24 +0x65
cmd/compile/internal/base.FatalfAt({0x15e92d8?, 0xc0?}, {0xd428bb, 0x10}, {0x0, 0x0, 0x0})
        /home/clemens/sdk/gotip/src/cmd/compile/internal/base/print.go:227 +0x1d7
cmd/compile/internal/base.Fatalf(...)
        /home/clemens/sdk/gotip/src/cmd/compile/internal/base/print.go:196
cmd/compile/internal/base.Assert(...)
        /home/clemens/sdk/gotip/src/cmd/compile/internal/base/print.go:239
cmd/compile/internal/noder.assert(...)
        /home/clemens/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:27
cmd/compile/internal/noder.(*genInst).dictPass.func1({0xeafba8, 0xc001600550})
        /home/clemens/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:1367 +0x28c
cmd/compile/internal/ir.editNodes(...)
        /home/clemens/sdk/gotip/src/cmd/compile/internal/ir/node_gen.go:1388
cmd/compile/internal/ir.(*AssignListStmt).editChildren(0xc0015edb00, 0xc0011724e0)
        /home/clemens/sdk/gotip/src/cmd/compile/internal/ir/node_gen.go:85 +0xc2
cmd/compile/internal/ir.EditChildren(...)
        /home/clemens/sdk/gotip/src/cmd/compile/internal/ir/visit.go:185
cmd/compile/internal/noder.(*genInst).dictPass.func1({0xead928, 0xc0015edb00})
        /home/clemens/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:1256 +0x11b
cmd/compile/internal/ir.editNodes(...)
        /home/clemens/sdk/gotip/src/cmd/compile/internal/ir/node_gen.go:1388
cmd/compile/internal/ir.(*Func).editChildren(0xc0000ff510?, 0xc0011724e0?)
        /home/clemens/sdk/gotip/src/cmd/compile/internal/ir/func.go:152 +0x74
cmd/compile/internal/ir.EditChildren(...)
        /home/clemens/sdk/gotip/src/cmd/compile/internal/ir/visit.go:185
cmd/compile/internal/noder.(*genInst).dictPass.func1({0xeae618, 0xc0015ad540})
        /home/clemens/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:1256 +0x11b
cmd/compile/internal/noder.(*genInst).dictPass(0x13cee40, 0xc0015e92d8)
        /home/clemens/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:1426 +0x150
cmd/compile/internal/noder.(*genInst).buildInstantiations(0x13cee40)
        /home/clemens/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:78 +0x1cc
cmd/compile/internal/noder.BuildInstantiations(...)
        /home/clemens/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:44
cmd/compile/internal/noder.(*irgen).generate(0xc000146240, {0xc000000820, 0x14, 0x1411b00?})
        /home/clemens/sdk/gotip/src/cmd/compile/internal/noder/irgen.go:333 +0x3d1
cmd/compile/internal/noder.check2({0xc000000820, 0x14, 0x14})
        /home/clemens/sdk/gotip/src/cmd/compile/internal/noder/irgen.go:87 +0x14d
cmd/compile/internal/noder.LoadPackage({0xc000022340, 0x14, 0x14})
        /home/clemens/sdk/gotip/src/cmd/compile/internal/noder/noder.go:82 +0x48f
cmd/compile/internal/gc.Main(0xd6b110)
        /home/clemens/sdk/gotip/src/cmd/compile/internal/gc/main.go:189 +0xbbd
main.main()
        /home/clemens/sdk/gotip/src/cmd/compile/main.go:57 +0xdd
@Clemens-H Clemens-H changed the title affected/package: go1.19rc1, gotip affected/package: go1.19rc1, gotip; internal compiler error: assertion failed Jul 9, 2022
@Clemens-H Clemens-H changed the title affected/package: go1.19rc1, gotip; internal compiler error: assertion failed affected/package: go1.19rc1 & gotip; internal compiler error: assertion failed Jul 9, 2022
@Clemens-H Clemens-H changed the title affected/package: go1.19rc1 & gotip; internal compiler error: assertion failed cmd/compile: internal compiler error: assertion failed Jul 9, 2022
@ianlancetaylor
Copy link
Contributor

Can you share a copy of the code that you are compiling? Thanks.

@Clemens-H
Copy link
Author

I am sharing two files here (had to change the suffix to upload), but I couldn't come up with a minimal example just using SumFloats and Abs. Line 33 in sum.go is where Abs is called from SumFloats.

sum.go.txt
abs.go.txt

@wdvxdr1123
Copy link
Contributor

Here is a small repro

package main

type Value[T any] interface {
}

func use[T any](v Value[T]) {
	_, _ = v.(int)
}

func main() {
	use(Value[int](nil))
}

@gopherbot
Copy link

Change https://go.dev/cl/416736 mentions this issue: cmd/compile: fix type assert in dict pass

@mknyszek mknyszek added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jul 11, 2022
@mknyszek mknyszek added this to the Go1.19 milestone Jul 11, 2022
@dmitshur dmitshur added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jul 12, 2022
@wdvxdr1123
Copy link
Contributor

I can reproduce on go 1.18.4.
@gopherbot please open a backport issue to 1.18.

@gopherbot
Copy link

Backport issue(s) opened: #53274 (for 1.18).

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases.

@Clemens-H
Copy link
Author

Thanks for your efforts. I just tried to compile with the latest gotip.

% gotip version
go version devel go1.19-c006b7ac27 Wed Jul 13 18:35:00 2022 +0000 darwin/amd64

Unfortunately, the original problem persists.

/Users/Clemens/Programs/Go/comp/sum.go:33:19: internal compiler error: assertion failed

goroutine 1 [running]:
runtime/debug.Stack()
        /Users/Clemens/sdk/gotip/src/runtime/debug/stack.go:24 +0x65
cmd/compile/internal/base.FatalfAt({0x16b0af8?, 0xc0?}, {0x193fdeb, 0x10}, {0x0, 0x0, 0x0})
        /Users/Clemens/sdk/gotip/src/cmd/compile/internal/base/print.go:227 +0x1d7
cmd/compile/internal/base.Fatalf(...)
        /Users/Clemens/sdk/gotip/src/cmd/compile/internal/base/print.go:196
cmd/compile/internal/base.Assert(...)
        /Users/Clemens/sdk/gotip/src/cmd/compile/internal/base/print.go:239
cmd/compile/internal/noder.assert(...)
        /Users/Clemens/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:27
cmd/compile/internal/noder.(*genInst).dictPass.func1({0x1aacd08, 0xc0016c14a0})
        /Users/Clemens/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:1367 +0x2bb
cmd/compile/internal/ir.editNodes(...)
        /Users/Clemens/sdk/gotip/src/cmd/compile/internal/ir/node_gen.go:1388
cmd/compile/internal/ir.(*AssignListStmt).editChildren(0xc0016bcf00, 0xc000e96cc0)
        /Users/Clemens/sdk/gotip/src/cmd/compile/internal/ir/node_gen.go:85 +0xc2
cmd/compile/internal/ir.EditChildren(...)
        /Users/Clemens/sdk/gotip/src/cmd/compile/internal/ir/visit.go:185
cmd/compile/internal/noder.(*genInst).dictPass.func1({0x1aaaa88, 0xc0016bcf00})
        /Users/Clemens/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:1256 +0x11b
cmd/compile/internal/ir.editNodes(...)
        /Users/Clemens/sdk/gotip/src/cmd/compile/internal/ir/node_gen.go:1388
cmd/compile/internal/ir.(*Func).editChildren(0xc000ba14f0?, 0xc000e96cc0?)
        /Users/Clemens/sdk/gotip/src/cmd/compile/internal/ir/func.go:152 +0x74
cmd/compile/internal/ir.EditChildren(...)
        /Users/Clemens/sdk/gotip/src/cmd/compile/internal/ir/visit.go:185
cmd/compile/internal/noder.(*genInst).dictPass.func1({0x1aab778, 0xc0013f5680})
        /Users/Clemens/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:1256 +0x11b
cmd/compile/internal/noder.(*genInst).dictPass(0x1fccb20, 0xc0016b0af8)
        /Users/Clemens/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:1426 +0x150
cmd/compile/internal/noder.(*genInst).buildInstantiations(0x1fccb20)
        /Users/Clemens/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:78 +0x1cc
cmd/compile/internal/noder.BuildInstantiations(...)
        /Users/Clemens/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:44
cmd/compile/internal/noder.(*irgen).generate(0xc0001f0240, {0xc0001a8780, 0x14, 0x200f780?})
        /Users/Clemens/sdk/gotip/src/cmd/compile/internal/noder/irgen.go:333 +0x3d1
cmd/compile/internal/noder.check2({0xc0001a8780, 0x14, 0x14})
        /Users/Clemens/sdk/gotip/src/cmd/compile/internal/noder/irgen.go:87 +0x14d
cmd/compile/internal/noder.LoadPackage({0xc00019c100, 0x14, 0x14})
        /Users/Clemens/sdk/gotip/src/cmd/compile/internal/noder/noder.go:82 +0x48f
cmd/compile/internal/gc.Main(0x1968268)
        /Users/Clemens/sdk/gotip/src/cmd/compile/internal/gc/main.go:189 +0xbbd
main.main()
        /Users/Clemens/sdk/gotip/src/cmd/compile/main.go:57 +0xdd

Will you re-open this issue or should I create a new one?

@Clemens-H
Copy link
Author

I did some more testing:

  • Version 1.18.3: no error
  • Version 1.18.4: internal compiler error as described above
  • Version 1.19rc1: internal compiler error as described above
  • Version gotip go1.19-c006b7ac27: internal compiler error as described above

I hope this helps to bisect the change.

@wdvxdr1123
Copy link
Contributor

@Clemens-H can you share more code? I cannot reproduce with your code.

@Clemens-H
Copy link
Author

Yes, as I mentioned above, the two functions I posted are referenced as the source position, but these two functions by themselves are not enough to trigger the error. I have been trying to come up with a minimal example, but for now the remaining program is still quite large.

The smallest example I have is this: I can import SumAsFloats into main.go from a module and it works. If I add a superfluous import to another module that uses SumAsFloats as well the import is not recognized as superfluous and the compiler error is triggered.

The compiler error is due to the assertion in line 1367 in gotip/src/cmd/compile/internal/noder/stencil.go failing, which leads to findDictType.

@sywhang
Copy link
Contributor

sywhang commented Jul 29, 2022

Can this issue be re-opened? I believe tip is still broken and fails to compile some code with generics. #54135 has a small standalone repro for this issue.

@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 Aug 1, 2022
@Clemens-H
Copy link
Author

Good news:

  • Version 1.18.5: no error
  • Version devel go1.19-f2a9f3e2e0 Mon Aug 1 20:44:41 2022 +0000 darwin/amd64: no error

jproberts pushed a commit to jproberts/go that referenced this issue Aug 10, 2022
For type assertions, if src type is empty interface, we should
use normal type assertions rather than dynamic type assertions.

Fixes golang#53762

Change-Id: I596b2e4ad647fe5e42ad884f7273c78f8f50dac2
Reviewed-on: https://go-review.googlesource.com/c/go/+/416736
Run-TryBot: Wayne Zuo <wdvxdr@golangcn.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
@hmmftg
Copy link

hmmftg commented Feb 5, 2023

Bad news:

  • Version 1.19.5: no error
  • Version 1.20/stable: 1.20 2023-02-02 (10045) 94MB classic: internal compiler error: assertion failed
  • I've reverted my snap package to 1.19.5 😢

@seankhliao
Copy link
Member

please file new, proper bug reports.

@golang golang locked as resolved and limited conversation to collaborators Feb 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Projects
None yet
Development

No branches or pull requests

9 participants