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 when using generics #48412

Closed
IlyaFloppy opened this issue Sep 16, 2021 · 3 comments
Closed

cmd/compile: internal compiler error when using generics #48412

IlyaFloppy opened this issue Sep 16, 2021 · 3 comments
Labels
Milestone

Comments

@IlyaFloppy
Copy link

@IlyaFloppy IlyaFloppy commented Sep 16, 2021

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

$ go version
go version devel go1.18-b2c04f0d48 Tue Sep 14 21:57:30 2021 +0000 darwin/amd64

Does this issue reproduce with the latest release?

Using master

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/ilya/Library/Caches/go-build"
GOENV="/Users/ilya/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/ilya/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/ilya/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/ilya/Development/goroot"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/ilya/Development/goroot/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="devel go1.18-b2c04f0d48 Tue Sep 14 21:57:30 2021 +0000"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/ilya/Development/genericsbug/go.mod"
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/7m/d4lybfs976gdy3bf8n25dxbc0000gn/T/go-build62774187=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I was trying to implement a simple library for broadcasting messages between goroutines using generics
https://github.com/IlyaFloppy/observable
Then faced internal compiler error using it
https://github.com/IlyaFloppy/genericsbug

/* main.go*/
package main

import (
	"genericsbug/lib"

	"github.com/IlyaFloppy/observable" // used in line 1
)

func main() {
	var _ *observable.Object[string] // <- 1
	lib.Main()
}


/* a.go */
package lib

import (
	"context"
	"fmt"
	"time"

	"github.com/IlyaFloppy/observable"
)

type ThisTypeDecalarationCausesInternalCompilerError struct {
	obj *observable.Object[string] // <- 2
}

func Main() {
	_ = observable.New[string]("hello")
	fmt.Println("hello")
}

Code compiles and works as expected if either line 1 or 2 is removed.

What did you expect to see?

Successful compilation

What did you see instead?

Internal compiler error

typecheck
.   DOTPTR tc(2) PTR-*observable.state[observable.T₅] # object.go:24:13 observable.state PTR-*observable.state[observable.T₅]
.   .   NAME-observable.o Class:PPARAM Offset:0 OnStack PTR-*observable.Object[observable.T₅] # object.go:20:7
/Users/ilya/go/pkg/mod/github.com/!ilya!floppy/observable@v0.0.0-20210915233658-b864272250be/object.go:24:13: internal compiler error: typecheck DOTPTR
Full error message
typecheck
.   DOTPTR tc(2) PTR-*observable.state[observable.T₅] # object.go:24:13 observable.state PTR-*observable.state[observable.T₅]
.   .   NAME-observable.o Class:PPARAM Offset:0 OnStack PTR-*observable.Object[observable.T₅] # object.go:20:7
/Users/ilya/go/pkg/mod/github.com/!ilya!floppy/observable@v0.0.0-20210915233658-b864272250be/object.go:24:13: internal compiler error: typecheck DOTPTR

goroutine 1 [running]:
runtime/debug.Stack()
/Users/ilya/Development/goroot/src/runtime/debug/stack.go:24 +0x65
cmd/compile/internal/base.FatalfAt({0x7de00, 0xc0}, {0x18f4bc9, 0xc}, {0xc0004cbc78, 0x1, 0x1})
/Users/ilya/Development/goroot/src/cmd/compile/internal/base/print.go:227 +0x154
cmd/compile/internal/base.Fatalf(...)
/Users/ilya/Development/goroot/src/cmd/compile/internal/base/print.go:196
cmd/compile/internal/typecheck.typecheck1({0x1a6b220, 0xc00007de00}, 0x6)
/Users/ilya/Development/goroot/src/cmd/compile/internal/typecheck/typecheck.go:478 +0x2c0b
cmd/compile/internal/typecheck.typecheck({0x1a6b220, 0xc00007de00}, 0x6)
/Users/ilya/Development/goroot/src/cmd/compile/internal/typecheck/typecheck.go:365 +0x4b0
cmd/compile/internal/typecheck.AddImplicitDots(0xc00007dec0)
/Users/ilya/Development/goroot/src/cmd/compile/internal/typecheck/subr.go:140 +0x45
cmd/compile/internal/typecheck.(*importReader).node(0xc000370990)
/Users/ilya/Development/goroot/src/cmd/compile/internal/typecheck/iimport.go:1390 +0x34a5
cmd/compile/internal/typecheck.(*importReader).expr(0xc000370990)
/Users/ilya/Development/goroot/src/cmd/compile/internal/typecheck/iimport.go:1221 +0x1d
cmd/compile/internal/typecheck.(*importReader).node(0xc000370990)
/Users/ilya/Development/goroot/src/cmd/compile/internal/typecheck/iimport.go:1498 +0x1945
cmd/compile/internal/typecheck.(*importReader).expr(0xc000370990)
/Users/ilya/Development/goroot/src/cmd/compile/internal/typecheck/iimport.go:1221 +0x1d
cmd/compile/internal/typecheck.(*importReader).node(0xc000370990)
/Users/ilya/Development/goroot/src/cmd/compile/internal/typecheck/iimport.go:1606 +0x1170
cmd/compile/internal/typecheck.(*importReader).stmtList(0x8)
/Users/ilya/Development/goroot/src/cmd/compile/internal/typecheck/iimport.go:1159 +0x5b
cmd/compile/internal/typecheck.(*importReader).funcBody(0xc000370990, 0xc000096c60)
/Users/ilya/Development/goroot/src/cmd/compile/internal/typecheck/iimport.go:1080 +0x92
cmd/compile/internal/typecheck.(*importReader).doInline(0x18, 0xc000096c60)
/Users/ilya/Development/goroot/src/cmd/compile/internal/typecheck/iimport.go:1044 +0x99
cmd/compile/internal/typecheck.ImportBody(0xc000096c60)
/Users/ilya/Development/goroot/src/cmd/compile/internal/typecheck/iimport.go:80 +0x206
cmd/compile/internal/noder.checkFetchBody(0xc0000e9790)
/Users/ilya/Development/goroot/src/cmd/compile/internal/noder/stencil.go:570 +0x96
cmd/compile/internal/noder.(*irgen).getInstantiation(0xc0000ea000, 0xc0000e9790, {0xc000090c08, 0x1, 0x1}, 0x90)
/Users/ilya/Development/goroot/src/cmd/compile/internal/noder/stencil.go:581 +0x5e
cmd/compile/internal/noder.(*irgen).instantiateMethods(0xc0001256b0)
/Users/ilya/Development/goroot/src/cmd/compile/internal/noder/stencil.go:522 +0x24e
cmd/compile/internal/noder.(*irgen).stencil(0xc0000ea000)
/Users/ilya/Development/goroot/src/cmd/compile/internal/noder/stencil.go:50 +0x9b
cmd/compile/internal/noder.(*irgen).generate(0xc0000ea000, {0xc000068b70, 0x2, 0xc0000a6000})
/Users/ilya/Development/goroot/src/cmd/compile/internal/noder/irgen.go:302 +0x359
cmd/compile/internal/noder.check2({0xc000068b70, 0x2, 0x2})
/Users/ilya/Development/goroot/src/cmd/compile/internal/noder/irgen.go:93 +0x16d
cmd/compile/internal/noder.LoadPackage({0xc00001e210, 0x2, 0x0})
/Users/ilya/Development/goroot/src/cmd/compile/internal/noder/noder.go:90 +0x335
cmd/compile/internal/gc.Main(0x191fc48)
/Users/ilya/Development/goroot/src/cmd/compile/internal/gc/main.go:190 +0xaf3
main.main()
/Users/ilya/Development/goroot/src/cmd/compile/main.go:55 +0xdd

@cuonglm
Copy link
Member

@cuonglm cuonglm commented Sep 16, 2021

Build ok with GOEXPERIMENT=unified go build.

cc @danscales @randall77

Loading

@cuonglm cuonglm added this to the Go1.18 milestone Sep 16, 2021
@danscales
Copy link

@danscales danscales commented Sep 16, 2021

This is fixed by cfa233d , which was just checked in yesterday, assuming I am running your code correctly via 'go run cmd/main.go'. I get the problem without the above change, and have a successful run with the above change.

Let me know if there's still a problem, else you can close this. (And of course feel free to create a new issue if you run into any further problem.)

Loading

@IlyaFloppy
Copy link
Author

@IlyaFloppy IlyaFloppy commented Sep 16, 2021

The issue does not reproduce with latest master indeed. Thank you!

Loading

@IlyaFloppy IlyaFloppy closed this Sep 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants