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: ICE on method value involving imported anonymous interface #58563

Closed
zapo opened this issue Feb 16, 2023 · 6 comments
Closed

cmd/compile: ICE on method value involving imported anonymous interface #58563

zapo opened this issue Feb 16, 2023 · 6 comments
Assignees
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

@zapo
Copy link

zapo commented Feb 16, 2023

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

$ go version
go version go1.20.1 linux/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
10:52 $ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/zapo/.cache/go-build"
GOENV="/home/zapo/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/zapo/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/zapo/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/zapo/.asdf/installs/golang/1.20.1/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/zapo/.asdf/installs/golang/1.20.1/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.20.1"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/zapo/src/test/go.mod"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2227726188=/tmp/go-build -gno-record-gcc-switches"

What did you do?

./pkg/pkg.go

package pkg

func Start() interface{ Stop() } {
	return new(Stopper)
}

type Stopper struct{}

func (s *Stopper) Stop() {}

./main.go

package main

import "test/pkg"

func main() {
	stop := start()
	defer stop()
}

func start() func() {
	return pkg.Start().Stop
}

What did you expect to see?

Successful build.

What did you see instead?

./pkg/pkg.go:3:6: internal compiler error: assertion failed

I can fix it by allocating the return of Start() or using a named interface, or avoiding to return the pointer to Stop interface by chaning start() to:

func start() func() {
	return func() { pkg.Start().Stop() }
}

Also I couldn't reproduce it if merging in the same package.

@thanm thanm added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. compiler/runtime Issues related to the Go compiler and/or runtime. labels Feb 21, 2023
@thanm
Copy link
Contributor

thanm commented Feb 21, 2023

This is also reproducible on tip.

@golang/compiler @mdempsky

@mdempsky mdempsky self-assigned this Feb 21, 2023
@mdempsky mdempsky changed the title build: internal compiler error: assertion failed when returning a pointer to an anonymous interface func from another package cmd/compile: ICE on method value involving imported anonymous interface Feb 21, 2023
@cuonglm
Copy link
Member

cuonglm commented Feb 22, 2023

@mdempsky It seems to me that the assertion failed due to mismatch between method selection position. There're two distinct anonymous interface types interface { Stop() } on line 3 and line 4, the corresponding Stop method also got different position. The wrapperFn uses the one on line 3, but the pkg.Start() use the one on line 4.

@mdempsky
Copy link
Contributor

@cuonglm Yeah, I think the assertion can just be relaxed. I have a CL, just power was out in my apt all day.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/471676 mentions this issue: cmd/compile: relax overly strict assertion

@mdempsky
Copy link
Contributor

@gopherbot Please backport to 1.20.

@gopherbot
Copy link
Contributor

Backport issue(s) opened: #58776 (for 1.20).

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

@dmitshur dmitshur modified the milestones: Backlog, Go1.21 Feb 28, 2023
@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 Feb 28, 2023
@golang golang locked and limited conversation to collaborators Feb 29, 2024
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

7 participants