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 in Go 1.18 using type parameters #51909

Closed
danielgtaylor opened this issue Mar 24, 2022 · 7 comments
Closed

cmd/compile: internal compiler error in Go 1.18 using type parameters #51909

danielgtaylor opened this issue Mar 24, 2022 · 7 comments
Labels
generics NeedsFix release-blocker
Milestone

Comments

@danielgtaylor
Copy link

@danielgtaylor danielgtaylor commented Mar 24, 2022

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

$ go version
go version go1.18 darwin/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
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/user/Library/Caches/go-build"
GOENV="/Users/user/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/user/go/pkg/mod"
GONOPROXY="github.com/redacted"
GONOSUMDB="github.com/redacted"
GOOS="darwin"
GOPATH="/Users/user/go"
GOPRIVATE="github.com/redacted"
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"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/user/src/tmp/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/rv/chjwd3812yzf6fm1j66m8g_40000gp/T/go-build2308498026=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I triggered an internal compiler error while playing around with Go 1.18 type parameters (generics). From https://go.dev/play/p/AlyOOLesUjM:

package main

import (
	"fmt"
	"net/http"
)

type None struct{}

type Response interface {
	send(ctx *struct{})
}

type HandlerFunc[Input any] func(Input) Response

func Operation[Input any](method, path string, h HandlerFunc[Input]) {
	var input Input
	response := h(input)
	fmt.Println(response)
}

func Get[Headers, Body any](path string, h HandlerFunc[struct {
	Headers Headers
	Body    Body
}]) {
	Operation(http.MethodGet, path, h)
}

func main() {
	Get("/", func(req struct {
		Headers struct {
			Authorization string
		}
		Body None
	}) Response {
		return nil
	})
}

What did you expect to see?

Successful compilation.

What did you see instead?

./prog.go:30:5: internal compiler error: assigning h (type HandlerFunc[struct { Headers struct { Authorization string }; Body "".None }]) to parameter h (type HandlerFunc[go.shape.struct { Headers struct { Authorization string }; Body struct {} }_0])

Please file a bug report including a short program that triggers the error.
https://go.dev/issue/new

Go build failed.
@ALTree ALTree changed the title cmd/go: internal compiler error in Go 1.18 using type parameters cmd/compile: internal compiler error in Go 1.18 using type parameters Mar 24, 2022
@ALTree ALTree added the NeedsInvestigation label Mar 24, 2022
@ALTree ALTree added this to the Go1.19 milestone Mar 24, 2022
@ALTree
Copy link
Member

@ALTree ALTree commented Mar 24, 2022

Crashes on tip too. Thanks for reporting.

cc @mdempsky @findleyr

@findleyr
Copy link
Contributor

@findleyr findleyr commented Mar 24, 2022

Thanks for the report.

CC @randall77

@cuonglm
Copy link
Member

@cuonglm cuonglm commented Mar 25, 2022

It seems to me this is the reverse of #49309.

There, we don't inline a function that has no shape parameters, but is passed at least one shape arg. Here, we may not want to inline a function that has shape parameters, but is passed no shape arg.

cc @randall77 @danscales

@mdempsky
Copy link
Member

@mdempsky mdempsky commented Mar 25, 2022

Successfully builds and runs (prints <nil>\n as output) with GOEXPERIMENT=unified.

@gopherbot
Copy link

@gopherbot gopherbot commented Mar 25, 2022

Change https://go.dev/cl/395854 mentions this issue: cmd/compile: don't inline fn with shape params, but passed no shape arg

@ungerik
Copy link

@ungerik ungerik commented Apr 19, 2022

Same problem using 1.18 and 1.18.1 with other similar code. GOEXPERIMENT=unified fixes it.

@heschi heschi added the generics label May 11, 2022
@heschi
Copy link
Contributor

@heschi heschi commented May 11, 2022

ping: this is a release blocker that hasn't been updated in a while.

@dmitshur dmitshur added NeedsFix and removed NeedsInvestigation labels May 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
generics NeedsFix release-blocker
Projects
None yet
Development

No branches or pull requests

10 participants