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 · 8 comments
Closed
Labels
FrozenDueToAge generics Issue is related to generics NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Milestone

Comments

@danielgtaylor
Copy link

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 Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Mar 24, 2022
@ALTree ALTree added this to the Go1.19 milestone Mar 24, 2022
@ALTree
Copy link
Member

ALTree commented Mar 24, 2022

Crashes on tip too. Thanks for reporting.

cc @mdempsky @findleyr

@findleyr
Copy link
Contributor

Thanks for the report.

CC @randall77

@cuonglm
Copy link
Member

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

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

@gopherbot
Copy link

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 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 Issue is related to generics label May 11, 2022
@heschi
Copy link
Contributor

heschi commented May 11, 2022

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

@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 May 14, 2022
@gopherbot
Copy link

Change https://go.dev/cl/424775 mentions this issue: cmd/compile: enable more inlining for unified IR

gopherbot pushed a commit that referenced this issue Aug 18, 2022
The non-unified frontend had repeated issues with inlining and
generics (#49309, #51909, #52907), which led us to substantially
restrict inlining when shape types were present.

However, these issues are evidently not present in unified IR's
inliner, and the safety restrictions added for the non-unified
frontend can simply be disabled in unified mode.

Fixes #54497.

Change-Id: I8e6ac9f3393c588bfaf14c6452891b9640a9d1bd
Reviewed-on: https://go-review.googlesource.com/c/go/+/424775
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
@golang golang locked and limited conversation to collaborators Aug 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge generics Issue is related to generics NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Projects
None yet
Development

No branches or pull requests

10 participants