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 when unpacking arguments of variadic generic function #51925

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

cmd/compile: ICE when unpacking arguments of variadic generic function #51925

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

Comments

@sonlamho
Copy link

@sonlamho sonlamho commented Mar 24, 2022

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

$ go version
go version go1.18 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
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/holamson/.cache/go-build"
GOENV="/home/holamson/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/holamson/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/holamson/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/holamson/.local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/holamson/.local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.18"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1142584741=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Link on go.dev/play: https://go.dev/play/p/VgkIIishLsB

Complete runnable program:

package main

import "fmt"

type IntLike interface {
	~int | ~int64 | ~int32 | ~int16 | ~int8
}

func Reduce[T any, U any, Uslice ~[]U](function func(T, U) T, sequence Uslice, initial T) T {
	result := initial
	for _, x := range sequence {
		result = function(result, x)
	}
	return result
}

func min[T IntLike](x, y T) T {
	if x < y {
		return x
	}
	return y

}

// Min returns the minimum element of `nums`.
func Min[T IntLike, NumSlice ~[]T](nums NumSlice) T {
	if len(nums) == 0 {
		return T(0)
	}
	return Reduce(min[T], nums, nums[0])
}

// VarMin is the variadic version of Min.
func VarMin[T IntLike](nums ...T) T {
	return Min(nums)
}

type myInt int

func main() {
	fmt.Println(VarMin(myInt(1), myInt(2))) // OK

	seq := []myInt{1, 2}
	fmt.Println(Min(seq))       // OK
	fmt.Println(VarMin(seq...)) // ERROR

}

What did you expect to see?

Expected output:

1
1
1

What did you see instead?

./prog.go:46:20: internal compiler error: assigning nums (type []myInt) to parameter nums (type go.shape.[]int_1)

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

Go build failed.
@sonlamho sonlamho changed the title affected/package: go1.18 affected/package: go1.18 compiler error in unpacking arguments of variadic function Mar 24, 2022
@sonlamho sonlamho changed the title affected/package: go1.18 compiler error in unpacking arguments of variadic function affected/package: go1.18 compiler error when unpacking arguments of variadic function Mar 24, 2022
@sonlamho sonlamho changed the title affected/package: go1.18 compiler error when unpacking arguments of variadic function affected/package: go1.18 compiler error when unpacking arguments of variadic generic function Mar 24, 2022
@sonlamho sonlamho changed the title affected/package: go1.18 compiler error when unpacking arguments of variadic generic function cmd/compile: go1.18 compiler error when unpacking arguments of variadic generic function Mar 24, 2022
@mknyszek mknyszek changed the title cmd/compile: go1.18 compiler error when unpacking arguments of variadic generic function cmd/compile: ICE when unpacking arguments of variadic generic function Mar 24, 2022
@mknyszek mknyszek added the NeedsInvestigation label Mar 24, 2022
@mknyszek mknyszek added this to the Backlog milestone Mar 24, 2022
@mknyszek
Copy link
Contributor

@mknyszek mknyszek commented Mar 24, 2022

CC @griesemer @findleyr

@mknyszek
Copy link
Contributor

@mknyszek mknyszek commented Mar 24, 2022

CC @dr2chase

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Mar 24, 2022

CC @randall77

@ianlancetaylor ianlancetaylor removed this from the Backlog milestone Mar 24, 2022
@ianlancetaylor ianlancetaylor added this to the Go1.19 milestone Mar 24, 2022
@findleyr
Copy link
Contributor

@findleyr findleyr commented Mar 25, 2022

The error message here looks similar to #51909, though I have not confirmed that this is a dupe.

@mdempsky
Copy link
Member

@mdempsky mdempsky commented Mar 25, 2022

Prints the expected 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

@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

8 participants