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

Closed
fogfish opened this issue Jun 6, 2022 · 7 comments
Closed

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

fogfish opened this issue Jun 6, 2022 · 7 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@fogfish
Copy link

fogfish commented Jun 6, 2022

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

$ go version
go version go1.18.3 darwin/amd64

Does this issue reproduce with the latest release?

Yes

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

The issue is reproducible at

  • darwin/amd64
  • linux/amd64
go env Output
$ go env

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/kolesnik/Library/Caches/go-build"
GOENV="/Users/kolesnik/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/kolesnik/devel/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/kolesnik/devel/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.18.3"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/kolesnik/devel/go/src/github.com/fogfish/dynamo/go.mod"
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 -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/gj/dt8b38qd4xx60g9y89d5mfj40000gn/T/go-build2387231264=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

assertion failed error appears while trying to run go test ./... or go vet ./... on the library that uses various generic abstraction. It has started to fail at 1.18.3 release but works perfectly with 1.18.1 and also building the library with go build ./... works with 1.18.3.

You can reproduce an error with following commands

git clone https://github.com/fogfish/dynamo
cd dynamo
go test ./...

What did you expect to see?

Successful compilation.

What did you see instead?

go test ./...
# github.com/fogfish/dynamo/internal/ddb [github.com/fogfish/dynamo/internal/ddb.test]
/Users/kolesnik/devel/go/pkg/mod/github.com/fogfish/golem@v0.8.5/pure/hseq/hseq.go:99:11: internal compiler error: assertion failed

The error report fails to compile dependency but building that decencies in other context also works fine.

Something fishy is going on... any advice is welcome how to debug this issue!

@cherrymui cherrymui changed the title cmd/go/internal/test: internal compiler error: assertion failed cmd/compile: internal compiler error: assertion failed Jun 6, 2022
@cherrymui
Copy link
Member

cherrymui commented Jun 6, 2022

Reproduced at tip. Here is the error message

/Users/cherryyz/gopkg/pkg/mod/github.com/fogfish/golem@v0.8.5/pure/hseq/hseq.go:99:11: internal compiler error: assertion failed

goroutine 1 [running]:
runtime/debug.Stack()
	/Users/cherryyz/src/go-tmp/src/runtime/debug/stack.go:24 +0x65
cmd/compile/internal/base.FatalfAt({0x138ceb8?, 0xc0?}, {0x193e93e, 0x10}, {0x0, 0x0, 0x0})
	/Users/cherryyz/src/go-tmp/src/cmd/compile/internal/base/print.go:227 +0x1d7
cmd/compile/internal/base.Fatalf(...)
	/Users/cherryyz/src/go-tmp/src/cmd/compile/internal/base/print.go:196
cmd/compile/internal/base.Assert(...)
	/Users/cherryyz/src/go-tmp/src/cmd/compile/internal/base/print.go:239
cmd/compile/internal/noder.assert(...)
	/Users/cherryyz/src/go-tmp/src/cmd/compile/internal/noder/stencil.go:27
cmd/compile/internal/noder.convertUsingDictionary(0xc00138ceb8, 0xc000455250?, {0x1805371?, 0x0?}, {0x1aa9690, 0xc001361440}, {0x1aa9ae0?, 0xc00139e640}, 0xc00132bb20)
	/Users/cherryyz/src/go-tmp/src/cmd/compile/internal/noder/stencil.go:1487 +0x837
cmd/compile/internal/noder.(*genInst).dictPass.func1({0x1aa9ae0, 0xc00139e640})
	/Users/cherryyz/src/go-tmp/src/cmd/compile/internal/noder/stencil.go:1330 +0x39e
cmd/compile/internal/ir.editNodes(...)
	/Users/cherryyz/src/go-tmp/src/cmd/compile/internal/ir/node_gen.go:1388
cmd/compile/internal/ir.(*ReturnStmt).editChildren(0xc00138f2d0?, 0xc000e904b0)
	/Users/cherryyz/src/go-tmp/src/cmd/compile/internal/ir/node_gen.go:962 +0xa2
cmd/compile/internal/ir.EditChildren(...)
	/Users/cherryyz/src/go-tmp/src/cmd/compile/internal/ir/visit.go:185
cmd/compile/internal/noder.(*genInst).dictPass.func1({0x1aaacd8, 0xc00139e550})
	/Users/cherryyz/src/go-tmp/src/cmd/compile/internal/noder/stencil.go:1230 +0x11b
cmd/compile/internal/ir.editNodes(...)
	/Users/cherryyz/src/go-tmp/src/cmd/compile/internal/ir/node_gen.go:1388
cmd/compile/internal/ir.(*Func).editChildren(0xc000455510?, 0xc000e904b0?)
	/Users/cherryyz/src/go-tmp/src/cmd/compile/internal/ir/func.go:152 +0x74
cmd/compile/internal/ir.EditChildren(...)
	/Users/cherryyz/src/go-tmp/src/cmd/compile/internal/ir/visit.go:185
cmd/compile/internal/noder.(*genInst).dictPass.func1({0x1aa9e78, 0xc0013643c0})
	/Users/cherryyz/src/go-tmp/src/cmd/compile/internal/noder/stencil.go:1230 +0x11b
cmd/compile/internal/noder.(*genInst).dictPass(0x1fcab00, 0xc00138ceb8)
	/Users/cherryyz/src/go-tmp/src/cmd/compile/internal/noder/stencil.go:1400 +0x150
cmd/compile/internal/noder.(*genInst).buildInstantiations(0x1fcab00)
	/Users/cherryyz/src/go-tmp/src/cmd/compile/internal/noder/stencil.go:78 +0x1cc
cmd/compile/internal/noder.BuildInstantiations(...)
	/Users/cherryyz/src/go-tmp/src/cmd/compile/internal/noder/stencil.go:44
cmd/compile/internal/noder.(*irgen).generate(0xc000690300, {0xc000372ff0, 0x6, 0x200d760?})
	/Users/cherryyz/src/go-tmp/src/cmd/compile/internal/noder/irgen.go:333 +0x3d1
cmd/compile/internal/noder.check2({0xc000372ff0, 0x6, 0x6})
	/Users/cherryyz/src/go-tmp/src/cmd/compile/internal/noder/irgen.go:87 +0x14d
cmd/compile/internal/noder.LoadPackage({0xc0000be100, 0x6, 0x6})
	/Users/cherryyz/src/go-tmp/src/cmd/compile/internal/noder/noder.go:84 +0x49c
cmd/compile/internal/gc.Main(0x1966cf8)
	/Users/cherryyz/src/go-tmp/src/cmd/compile/internal/gc/main.go:189 +0xbbd
main.main()
	/Users/cherryyz/src/go-tmp/src/cmd/compile/main.go:57 +0xdd

It appears to be from instantiating a generic function. cc @randall77

@cherrymui cherrymui added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jun 6, 2022
@cherrymui cherrymui added this to the Go1.19 milestone Jun 6, 2022
@wdvxdr1123
Copy link
Contributor

wdvxdr1123 commented Jun 7, 2022

Here is a simple repro.
https://go.dev/play/p/cjrTt3JyRTZ?v=gotip

package main

type Interface[T any] interface {
}

func F[T any]() Interface[T] {
	var i int
	return i
}

func main() {
	F[int]()
}

@gopherbot
Copy link

gopherbot commented Jun 7, 2022

Change https://go.dev/cl/410655 mentions this issue: cmd/compile: don't use dictionary convert to shaped empty interface

@randall77
Copy link
Contributor

randall77 commented Jun 7, 2022

@gopherbot please open a backport issue to 1.18.

@gopherbot
Copy link

gopherbot commented Jun 7, 2022

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.

@arvidfm
Copy link

arvidfm commented Jun 14, 2022

I also got the same error. MWE of the code I was working with:

package main

import "fmt"

type Interface[K any] interface {
	Name() string
}

type interfaceImpl[K any] struct {
	name string
}

func (i interfaceImpl[K]) Name() string {
	return i.name
}

type Type[T any, K any] struct {
	interfaceImpl[K]
}

func main() {
	a := Type[int, int]{
		interfaceImpl[int]{name: "hello"},
	}
	printName(a)
}

func printName[T any](k Type[T, int]) {
	fmt.Println(k.Name())
}

@wdvxdr1123
Copy link
Contributor

wdvxdr1123 commented Jun 16, 2022

@arvidfm I believe this is an another issue because of different stack backtrace. I open a new issue and will mail a fix soon.

jproberts pushed a commit to jproberts/go that referenced this issue Aug 10, 2022
Fixes: golang#53254

Change-Id: I3153d6ebb9f25957b09363f45c5cd4651ee84c2d
Reviewed-on: https://go-review.googlesource.com/c/go/+/410655
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Wayne Zuo <wdvxdr@golangcn.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
Development

No branches or pull requests

6 participants