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

Closed
r-hang opened this issue Jul 29, 2022 · 13 comments
Closed

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

r-hang opened this issue Jul 29, 2022 · 13 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@r-hang
Copy link

r-hang commented Jul 29, 2022

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

master
$ go version
go version devel go1.19-5c8ec89cb5 Thu Jul 28 21:13:04 2022 +0000 linux/amd64

Does this issue reproduce with the latest release?

Fails on both go1.19rc2 and master. Passes on go1.18.

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

go env Output
$ go env
GO111MODULE="off"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/user/.cache/go-build"
GOENV="/home/user/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/user/go-code2/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/user/go-code2"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org/,direct"
GOROOT="/home/user/go/src/github.com/golang/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/user/go/src/github.com/golang/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="devel go1.19-5c8ec89cb5 Thu Jul 28 21:13:04 2022 +0000"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
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-build3108614045=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Try compiling this test program

package main

import (
	"fmt"
	"testing"
)

type Bar[T any] interface{
    Blanker()
}

type FooBar[T any] interface{}

type Foo[E comparable] struct {
	me E
}

func (b *Foo[E]) do(h Bar[E], f FooBar[E]) {
	check(h, f)
}

func check[T comparable](p Bar[T], q FooBar[T]) int {
	if _, ok := p.(Checkable); ok {
		fmt.Println(ok)
	}
	if _, ok := q.(Checkable); ok {
		fmt.Println(ok)
	}
	return 1
}

type Checkable interface{}

func TestFunction(m *testing.T) {
	x := Foo[int]{me: 2}
	fmt.Println(x)
}

What did you expect to see?

Test passed.

What did you see instead?

./main_test.go:19:7: internal compiler error: assertion failed

@r-hang r-hang changed the title affected/package: cmd/compile go1.19 Fails to build generic program cmd/compile go1.19 Fails to build generic program Jul 29, 2022
@sywhang
Copy link
Contributor

sywhang commented Jul 29, 2022

To add a bit of context, we found this issue while testing Go 1.19 on our Go Monorepo at Uber. We noticed both master and 1.19 rc2 is breaking with some of the latest changes in our codebase that made use of generics.

The program above is a small repro we were able to isolate out of the actual code that broke.

@ianlancetaylor
Copy link
Contributor

May be a dup of #53762.

@sywhang
Copy link
Contributor

sywhang commented Jul 29, 2022

@ianlancetaylor thanks, i can confirm the failure is coming from the same place as #53762.

The repro program we posted above should help debugging the root cause.

@ianlancetaylor
Copy link
Contributor

Thanks, closing as a dup. My understanding is that #53762 has already been fixed on tip.

@ianlancetaylor ianlancetaylor closed this as not planned Won't fix, can't repro, duplicate, stale Jul 29, 2022
@sywhang
Copy link
Contributor

sywhang commented Jul 29, 2022

@ianlancetaylor Sorry, but I don't think it has been. The program above still fails to build on tip. The latest comments in #53762 seems like there are others facing the same issue on tip.

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

@seankhliao seankhliao reopened this Jul 29, 2022
@seankhliao seankhliao changed the title cmd/compile go1.19 Fails to build generic program cmd/compile: internal compiler error: assertion failed Jul 29, 2022
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jul 29, 2022
@seankhliao seankhliao added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jul 29, 2022
@ianlancetaylor ianlancetaylor added this to the Go1.19 milestone Jul 30, 2022
@ianlancetaylor
Copy link
Contributor

You're right, it's still crashing. Sorry about that.

CC @randall77 @mdempsky

@gopherbot
Copy link

Change https://go.dev/cl/420394 mentions this issue: cmd/compile: fix wrong dict pass condition for type assertions

@sywhang
Copy link
Contributor

sywhang commented Jul 31, 2022

Tested the fix above, and it still is failing to build some generics code. I will follow up with a repro shortly.

@sywhang
Copy link
Contributor

sywhang commented Jul 31, 2022

The repro below still fails to build with the fix above.

import (
        "fmt"
        "testing"
)

type Foo[T comparable] interface {
        FooFoo(tt []T)
}

type Bar interface {
        BarSize() int
}

func Test[T comparable](tt []T, foos []Foo[T]) {
        if len(foos) == 0 {
                return
        }
        p := FooBar[T]{fooCnt: len(foos)}
        p.getT(foos[0])
}

type FooBar[T comparable] struct {
        fooCnt int
}

func (p *FooBar[T]) getT(foo Foo[T]) {
        barSize(foo)
}

func barSize[T comparable](p Foo[T]) {
        s := 1
        if b, ok := p.(Bar); ok {
                s = b.BarSize()
        }
        fmt.Println(s)
}

func TestTest(t *testing.T) {
        tt := []int{1, 2, 3}
        foos := []Foo[int]{}

        Test(tt, foos)
}

On Go 1.18, this passes as expected.

On Go 1.19, both on tip and tip with the patch in https://go-review.googlesource.com/c/go/+/420394/

@gopherbot
Copy link

Change https://go.dev/cl/420421 mentions this issue: test: improve generic type assertion test

gopherbot pushed a commit that referenced this issue Aug 1, 2022
The test added in CL 420394 only tested that the type assertions
compiled at all. This CL changes it into a run test to make sure the
type assertions compile and also run correctly.

Updates #54135.

Change-Id: Id17469faad1bb55ff79b0bb4163ef50179330033
Reviewed-on: https://go-review.googlesource.com/c/go/+/420421
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Auto-Submit: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
@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
@sywhang
Copy link
Contributor

sywhang commented Aug 1, 2022

Can this fix be cherry-picked to Go 1.19 branch before the release tomorrow? Plenty of code out there will be blocked on upgrading to 1.19 until this fix is made available.

@gopherbot
Copy link

Change https://go.dev/cl/420675 mentions this issue: [release-branch.go1.19] test: improve generic type assertion test

@gopherbot
Copy link

Change https://go.dev/cl/420674 mentions this issue: [release-branch.go1.19] cmd/compile: fix wrong dict pass condition for type assertions

gopherbot pushed a commit that referenced this issue Aug 1, 2022
…r type assertions

Updates #54135.

Change-Id: I2b27af8124014b2699ea44bdc765e1fb8f6c8028
Reviewed-on: https://go-review.googlesource.com/c/go/+/420394
Reviewed-by: Keith Randall <khr@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Wayne Zuo <wdvxdr@golangcn.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
(cherry picked from commit 27038b7)
Reviewed-on: https://go-review.googlesource.com/c/go/+/420674
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
gopherbot pushed a commit that referenced this issue Aug 1, 2022
The test added in CL 420674 only tested that the type assertions
compiled at all. This CL changes it into a run test to make sure the
type assertions compile and also run correctly.

Updates #54135.

Change-Id: Id17469faad1bb55ff79b0bb4163ef50179330033
Reviewed-on: https://go-review.googlesource.com/c/go/+/420421
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Auto-Submit: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
(cherry picked from commit f2a9f3e)
Reviewed-on: https://go-review.googlesource.com/c/go/+/420675
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
jproberts pushed a commit to jproberts/go that referenced this issue Aug 10, 2022
Fixes golang#54135

Change-Id: I2b27af8124014b2699ea44bdc765e1fb8f6c8028
Reviewed-on: https://go-review.googlesource.com/c/go/+/420394
Reviewed-by: Keith Randall <khr@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Wayne Zuo <wdvxdr@golangcn.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
jproberts pushed a commit to jproberts/go that referenced this issue Aug 10, 2022
The test added in CL 420394 only tested that the type assertions
compiled at all. This CL changes it into a run test to make sure the
type assertions compile and also run correctly.

Updates golang#54135.

Change-Id: Id17469faad1bb55ff79b0bb4163ef50179330033
Reviewed-on: https://go-review.googlesource.com/c/go/+/420421
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Auto-Submit: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
@golang golang locked and limited conversation to collaborators Aug 1, 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. FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

6 participants