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: crash compiling code with local generic type #50350

Closed
akshaybharambe14 opened this issue Dec 26, 2021 · 3 comments
Closed

cmd/compile: crash compiling code with local generic type #50350

akshaybharambe14 opened this issue Dec 26, 2021 · 3 comments

Comments

@akshaybharambe14
Copy link

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

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

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go1.18beta1 env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\aksha\AppData\Local\go-build
set GOENV=C:\Users\aksha\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\aksha\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\aksha\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Users\aksha\sdk\go1.18beta1
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Users\aksha\sdk\go1.18beta1\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.18beta1
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=D:\github.com\akshaybharambe14\go-generics-tests-bug\go.mod
set GOWORK=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\aksha\AppData\Local\Temp\go-build162005594=/tmp/go-build -gno-record-gcc-switches

What did you do?

go test fails to run tests with an error associated with compiling tests.

Quick refrence

Module structure

- a.go
- a_test.go
- b.go
- b_test.go

Running go1.18beta1 test fails for this module.

As this involves multiple files, for simplicity I am providing a reference to a repository. Following are the quick steps to reproduce the problem.

git clone https://github.com/akshaybharambe14/go-generics-tests-bug
cd go-generics-tests-bug
go1.18beta1 test

What did you expect to see?

PASS
ok      github.com/akshaybharambe14/go-generics-tests-bug       0.197s

What did you see instead?

# github.com/akshaybharambe14/go-generics-tests-bug [github.com/akshaybharambe14/go-generics-tests-bug.test]
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x18 pc=0x9f5ae5]

goroutine 1 [running]:
cmd/compile/internal/noder.transformCompLit(0xc000068b80)
        c:/go/src/cmd/compile/internal/noder/transform.go:1019 +0x8a5
cmd/compile/internal/noder.(*irgen).compLit(0xc000142240, {0xc85150, 0xc0004e1000}, 0xc0003ebcc0)
        c:/go/src/cmd/compile/internal/noder/expr.go:372 +0x276
cmd/compile/internal/noder.(*irgen).expr0(0xc000142240, {0xc85150, 0xc0004e1000}, {0xc860a8?, 0xc0003ebcc0?})
        c:/go/src/cmd/compile/internal/noder/expr.go:107 +0x585
cmd/compile/internal/noder.(*irgen).expr(0xc000142240, {0xc860a8?, 0xc0003ebcc0?})
        c:/go/src/cmd/compile/internal/noder/expr.go:81 +0x5e8
cmd/compile/internal/noder.(*irgen).compLit(0xc000142240, {0xc851f0, 0xc000590450}, 0xc0003ebc70)
        c:/go/src/cmd/compile/internal/noder/expr.go:353 +0x57b
cmd/compile/internal/noder.(*irgen).expr0(0xc000142240, {0xc851f0, 0xc000590450}, {0xc860a8?, 0xc0003ebc70?})
        c:/go/src/cmd/compile/internal/noder/expr.go:107 +0x585
cmd/compile/internal/noder.(*irgen).expr(0xc000142240, {0xc860a8?, 0xc0003ebc70?})
        c:/go/src/cmd/compile/internal/noder/expr.go:81 +0x5e8
cmd/compile/internal/noder.(*irgen).compLit(0xc000142240, {0xc851c8, 0xc000091550}, 0xc0003ebc20)
        c:/go/src/cmd/compile/internal/noder/expr.go:360 +0x747
cmd/compile/internal/noder.(*irgen).expr0(0xc000142240, {0xc851c8, 0xc000091550}, {0xc860a8?, 0xc0003ebc20?})
        c:/go/src/cmd/compile/internal/noder/expr.go:107 +0x585
cmd/compile/internal/noder.(*irgen).expr(0xc000142240, {0xc860a8?, 0xc0003ebc20?})
        c:/go/src/cmd/compile/internal/noder/expr.go:81 +0x5e8
cmd/compile/internal/noder.(*irgen).exprs(0xc00007f360?, {0xc00007f350, 0x1, 0x200c00004cc80?})
        c:/go/src/cmd/compile/internal/noder/expr.go:329 +0x8e
cmd/compile/internal/noder.(*irgen).exprList(0x8?, {0xc860a8?, 0xc0003ebc20?})
        c:/go/src/cmd/compile/internal/noder/expr.go:312 +0x85
cmd/compile/internal/noder.(*irgen).stmt(0xc000142240, {0xc85f28?, 0xc0000579c0?})
        c:/go/src/cmd/compile/internal/noder/stmt.go:79 +0x418
cmd/compile/internal/noder.(*irgen).stmts(0xc00047b570?, {0xc000057a00?, 0x4, 0xc00007f648?})
        c:/go/src/cmd/compile/internal/noder/stmt.go:19 +0xaf
cmd/compile/internal/noder.(*irgen).funcBody(0xc000142240, 0xc00047c6e0, 0x93f320?, 0xc0000577c0, 0xc000057840)
        c:/go/src/cmd/compile/internal/noder/func.go:45 +0x25f
cmd/compile/internal/noder.(*irgen).funcDecl.func1()
        c:/go/src/cmd/compile/internal/noder/decl.go:145 +0xf5
cmd/compile/internal/noder.(*irgen).generate(0xc000142240, {0xc0003d4140, 0x4, 0xc0000a4000?})
        c:/go/src/cmd/compile/internal/noder/irgen.go:280 +0x227
cmd/compile/internal/noder.check2({0xc0003d4140, 0x4, 0x4})
        c:/go/src/cmd/compile/internal/noder/irgen.go:92 +0x16d
cmd/compile/internal/noder.LoadPackage({0xc00011e120, 0x4, 0x0?})
        c:/go/src/cmd/compile/internal/noder/noder.go:90 +0x335
cmd/compile/internal/gc.Main(0xb3f488)
        c:/go/src/cmd/compile/internal/gc/main.go:191 +0xb13
main.main()
        c:/go/src/cmd/compile/main.go:55 +0xdd
FAIL    github.com/akshaybharambe14/go-generics-tests-bug [build failed]

Some observations

  • Test runs fine if executed in isolation (go1.18beta1 test find.go find_test.go).
  • Somehow, package tests succeed by renaming one of the 'args' type declarations in tests.
    From -
func TestFind(t *testing.T) {
	type args[T comparable] struct {
		v T
		s []T
	}
}

To -

func TestFind(t *testing.T) {
	type delArgs[T comparable] struct {
		v T
		s []T
	}
}
@akshaybharambe14 akshaybharambe14 changed the title [go1.18beata1] Bug while running package tests on generic code [go1.18beta1] Bug while running package tests on generic code Dec 26, 2021
@ianlancetaylor ianlancetaylor changed the title [go1.18beta1] Bug while running package tests on generic code cmd/compile: crash compiling code with local generic type Dec 27, 2021
@ianlancetaylor
Copy link
Contributor

Pretty sure this is a dup of #47631.

@danscales
Copy link
Contributor

This is a dup of #50177 (can't currently declare a local generic type in a non-generic function). The potential fix listed on that issue fixes this issue. We haven't yet decided if we are going to support local generic types in non-generic functions for Go 1.18, but this issue can be duped with that issue. We will either make sure things work, or issue a compile-time error in this case.

Issue #47631 is a slightly different case - support for local types (generic or non-generic) in generic functions. We will definitely not support that case in Go 1.18 (i.e. we will stay with printing a compiler error)

@danscales
Copy link
Contributor

Just to clarify (I wanted to double-check myself), the problem is the two conflicting local definitions of args[T] in find_test.go and delete_test.go. We are mixing up the instantiations of the two different args[T] types. This is fixed by https://go-review.googlesource.com/c/go/+/372654/ , if we decide to check it in.

@golang golang locked and limited conversation to collaborators Dec 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants