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: compiler panic with generics across packages and pointer type parameter #51367

Closed
JOT85 opened this issue Feb 25, 2022 · 5 comments
Closed
Labels
NeedsInvestigation release-blocker
Milestone

Comments

@JOT85
Copy link

@JOT85 JOT85 commented Feb 25, 2022

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

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

What did you do?

go.mod
module go.jot.me.uk/broken

go 1.18
main.go
package main

import (
	"go.jot.me.uk/broken/foo"
)

func main() {
    foo.DoSomething[byte]()
}
foo/foo.go
package foo

type A[T any] struct{}

func (_ A[T]) Method() {}

func DoSomething[P any]() {
    a := A[*byte]{}
    a.Method()
}

What did you expect to see?

The program compile.

What did you see instead?

$ go build .
# go.jot.me.uk/broken
./main.go:8:26: internal compiler error: panic: runtime error: invalid memory address or nil pointer dereference

Please file a bug report including a short program that triggers the error.
https://go.dev/issue/new
@JOT85 JOT85 changed the title cmd/compile: compiler panic with generics across packages cmd/compile: compiler panic with generics across packages and pointer type parameter Feb 25, 2022
@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Feb 25, 2022

This builds with GOEXPERIMENT=unified.

CC @danscales @randall77 @griesemer @findleyr

Compiler backtrace:

# t
./main.go:8:26: internal compiler error: panic: runtime error: invalid memory address or nil pointer dereference

goroutine 1 [running]:
runtime/debug.Stack()
	/home/iant/go/src/runtime/debug/stack.go:24 +0x65
cmd/compile/internal/base.FatalfAt({0x21524758?, 0x7f7b?}, {0xd22309, 0x9}, {0xc000120fd0, 0x1, 0x1})
	/home/iant/go/src/cmd/compile/internal/base/print.go:227 +0x1d7
cmd/compile/internal/base.Fatalf(...)
	/home/iant/go/src/cmd/compile/internal/base/print.go:196
cmd/compile/internal/gc.handlePanic()
	/home/iant/go/src/cmd/compile/internal/gc/main.go:49 +0x85
panic({0xcabae0, 0x1310df0})
	/home/iant/go/src/runtime/panic.go:838 +0x207
cmd/compile/internal/types.(*Type).Bound(0x0?)
	/home/iant/go/src/cmd/compile/internal/types/type.go:1900 +0x18
cmd/compile/internal/typecheck.Shapify(0x40d365?, 0xbf3453?, 0xbf3453?)
	/home/iant/go/src/cmd/compile/internal/typecheck/subr.go:1453 +0xbf
cmd/compile/internal/noder.(*genInst).getInstantiation(0x1399e20, 0xc00041b520, {0xc00000e690, 0x1, 0xc0004114a0?}, 0x1)
	/home/iant/go/src/cmd/compile/internal/noder/stencil.go:665 +0x2d0
cmd/compile/internal/noder.(*genInst).scanForGenCalls.func1({0xe98dd8, 0xc000179290?})
	/home/iant/go/src/cmd/compile/internal/noder/stencil.go:151 +0x2df
cmd/compile/internal/ir.Visit.func1({0xe98dd8, 0xc000179290})
	/home/iant/go/src/cmd/compile/internal/ir/visit.go:105 +0x30
cmd/compile/internal/ir.doNodes(...)
	/home/iant/go/src/cmd/compile/internal/ir/node_gen.go:1512
cmd/compile/internal/ir.(*Func).doChildren(0xe99738?, 0xc00000ddb8?)
	/home/iant/go/src/cmd/compile/internal/ir/func.go:156 +0x6e
cmd/compile/internal/ir.DoChildren(...)
	/home/iant/go/src/cmd/compile/internal/ir/visit.go:94
cmd/compile/internal/ir.Visit.func1({0xe99738, 0xc0004114a0})
	/home/iant/go/src/cmd/compile/internal/ir/visit.go:106 +0x57
cmd/compile/internal/ir.Visit({0xe99738, 0xc0004114a0}, 0xc000035f00)
	/home/iant/go/src/cmd/compile/internal/ir/visit.go:108 +0xb8
cmd/compile/internal/noder.(*genInst).scanForGenCalls(0x1399e20, {0xe99738, 0xc0004114a0})
	/home/iant/go/src/cmd/compile/internal/noder/stencil.go:133 +0x1f0
cmd/compile/internal/noder.(*genInst).buildInstantiations(0x1399e20)
	/home/iant/go/src/cmd/compile/internal/noder/stencil.go:67 +0xc5
cmd/compile/internal/noder.BuildInstantiations(...)
	/home/iant/go/src/cmd/compile/internal/noder/stencil.go:44
cmd/compile/internal/noder.(*irgen).generate(0xc000154300, {0xc00000e448, 0x1, 0x203000?})
	/home/iant/go/src/cmd/compile/internal/noder/irgen.go:331 +0x3d1
cmd/compile/internal/noder.check2({0xc00000e448, 0x1, 0x1})
	/home/iant/go/src/cmd/compile/internal/noder/irgen.go:92 +0x16d
cmd/compile/internal/noder.LoadPackage({0xc00001e220, 0x1, 0x0?})
	/home/iant/go/src/cmd/compile/internal/noder/noder.go:90 +0x335
cmd/compile/internal/gc.Main(0xd52510)
	/home/iant/go/src/cmd/compile/internal/gc/main.go:191 +0xb13
main.main()
	/home/iant/go/src/cmd/compile/main.go:55 +0xdd

@ianlancetaylor ianlancetaylor added the NeedsInvestigation label Feb 25, 2022
@ianlancetaylor ianlancetaylor added this to the Go1.18 milestone Feb 25, 2022
@findleyr
Copy link
Contributor

@findleyr findleyr commented Feb 25, 2022

Playground link:
https://go.dev/play/p/3YuX_i5W00s?v=gotip

Marking as a release blocker as this is a valid program that does not compile.

@JOT85
Copy link
Author

@JOT85 JOT85 commented Feb 25, 2022

Playground link:
https://go.dev/play/p/3YuX_i5W00s?v=gotip

Thanks! I didn't realise you could include multiple files in the playground, neat :)

@danscales
Copy link
Contributor

@danscales danscales commented Feb 25, 2022

Missing nil check in some code related to structural type params. I'll fix this.

@danscales danscales self-assigned this Feb 25, 2022
@gopherbot
Copy link

@gopherbot gopherbot commented Feb 26, 2022

Change https://go.dev/cl/388116 mentions this issue: cmd/compile: add missing nil check for tparam in Shapify

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

No branches or pull requests

5 participants