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: assigning XXX (type driver.Value) to parameter <S> (type interface {}) #50169

Closed
lstoll opened this issue Dec 14, 2021 · 6 comments
Labels
NeedsFix release-blocker
Milestone

Comments

@lstoll
Copy link

@lstoll lstoll commented Dec 14, 2021

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

$ go1.18beta1 version
go version go1.18beta1 darwin/amd64

Does this issue reproduce with the latest release?

Yes (latest beta release + tip on go.dev/play)

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

go env Output
$ go1.18beta1 env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/lincoln.stoll/Library/Caches/go-build"
GOENV="/Users/lincoln.stoll/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/lincoln.stoll/go/pkg/mod"
GONOPROXY="git.dev.pardot.com,git.soma.salesforce.com,github.com/heroku"
GONOSUMDB="git.dev.pardot.com,git.soma.salesforce.com,github.com/heroku"
GOOS="darwin"
GOPATH="/Users/lincoln.stoll/go"
GOPRIVATE="git.dev.pardot.com,git.soma.salesforce.com,github.com/heroku"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/lincoln.stoll/sdk/go1.18beta1"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/lincoln.stoll/sdk/go1.18beta1/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.18beta1"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/lincoln.stoll/src/identity/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/k6/4px2pzjx1_j28kh4wh0cfbxc0000gq/T/go-build4237473592=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Received an internal compiler error running go 1.18 beta against an existing codebase.

$ go1.18beta1 run errorer.go 
# command-line-arguments
./errorer.go:21:33: internal compiler error: assigning encv (type driver.Value) to parameter <S> (type interface {})

Please file a bug report including a short program that triggers the error.

The smallest repro code to cause this can be found at https://go.dev/play/p/lrcypQGydEi?v=gotip , where the compiler error is also evident.

What did you expect to see?

Successful compilation, works on 1.17 and earlier releases.

What did you see instead?

Internal compilation error, with request to file a bug report.

@lstoll lstoll changed the title compiler: internal compiler error: assigning XXX (type driver.Value) to parameter <S> (type interface {}) cmd/compile: internal compiler error: assigning XXX (type driver.Value) to parameter <S> (type interface {}) Dec 14, 2021
@nussjustin
Copy link
Contributor

@nussjustin nussjustin commented Dec 14, 2021

If you change

func (n *noopScanner) Scan(src interface{}) error {

to

func (n *noopScanner) Scan(src any) error {

the error disappears and the code compiles.

A quick bisect points to 2580d0e (all: gofmt -w -r 'interface{} -> any' src)

/cc @rsc @griesemer

@cherrymui cherrymui added the NeedsFix label Dec 14, 2021
@cherrymui cherrymui added this to the Go1.18 milestone Dec 14, 2021
@cherrymui
Copy link
Member

@cherrymui cherrymui commented Dec 14, 2021

cc @mdempsky

@cherrymui
Copy link
Member

@cherrymui cherrymui commented Dec 14, 2021

A simpler reproducer

package main

func main() {
	var x Value
	NewScanner().Scan(x)
}

type Value any

type Scanner interface{ Scan(any) error }

func NewScanner() Scanner {
	return &t{}
}

type t struct{}

func (*t) Scan(interface{}) error { return nil }

Also cc @danscales

@griesemer
Copy link
Contributor

@griesemer griesemer commented Dec 14, 2021

Changing the declaration above to

type Value = any // <<< make Value an alias

makes the bug go away. This looks like something is not properly working with any as an alias for interface{}.

@cherrymui
Copy link
Member

@cherrymui cherrymui commented Dec 15, 2021

It looks to me that we might miss a CONVNOP somewhere. Before walk the AST for the call looks like

.   CALLFUNC error tc(1) # s.go:5:19
.   .   METHEXPR main.Scan FUNC-func(*t, interface {}) error tc(1) # s.go:5:14
.   .   .   TYPE <S> type PTR-*t tc(1)
.   CALLFUNC-Args
.   .   DOTTYPE PTR-*t tc(1) # s.go:5:14
.   .   .   NAME-main.~R0 esc(no) Class:PAUTO Offset:0 OnStack Used main.Scanner tc(1) # s.go:5:12
.   .   NAME-main.x esc(no) Class:PAUTO Offset:0 OnStack main.Value tc(1) # s.go:4:6

The code expects the type of the argument (Value) and the type the function parameter (interface{}) are identical, which are not (one is defined type, one is not).

Note that the example only fails when inlining is enabled. It doesn't fail if inlining is disabled. Same for the original example. However, when inlining is disabled, even it doesn't ICE, the code tries to compare Value and any for identity. It should not be identical, but the code thinks they are, due to
https://cs.opensource.google/go/go/+/master:src/cmd/compile/internal/types/identity.go;l=67 , which doesn't seems right.

@gopherbot
Copy link

@gopherbot gopherbot commented Dec 15, 2021

Change https://golang.org/cl/372217 mentions this issue: cmd/compile: correct type identity comparison with "any"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsFix release-blocker
Projects
None yet
Development

No branches or pull requests

5 participants