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: missing typecheck #56727

Closed
biffen opened this issue Nov 14, 2022 · 7 comments
Closed

cmd/compile: internal compiler error: missing typecheck #56727

biffen opened this issue Nov 14, 2022 · 7 comments
Assignees
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@biffen
Copy link

biffen commented Nov 14, 2022

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

$ go version
go version go1.19.3 linux/amd64

Does this issue reproduce with the latest release?

Yes (v1.19.3).

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/biffen/.cache/go-build"
GOENV="/home/biffen/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/biffen/.local/go/pkg/mod"
GONOPROXY="███"
GONOSUMDB="███"
GOOS="linux"
GOPATH="/home/biffen/.local/go:/home/biffen/src/go:/home/biffen/src/private/go"
GOPRIVATE="███"
GOPROXY="direct"
GOROOT="/usr/local/go"
GOSUMDB="off"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.19.3"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/biffen/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 -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build735231424=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I came across an internal compiler error while testing a project. First locally then in CI/CD (self-hosted GitLab running a golang Docker container).

I removed enough code to produce this:

package main

import (
	"fmt"

	"github.com/doug-martin/goqu/v9"
	"github.com/doug-martin/goqu/v9/exp"
)

type Cols []exp.Expression

func main() {
	columns := struct {
		Foo exp.IdentifierExpression
		Bar exp.IdentifierExpression
		Baz exp.IdentifierExpression
	}{
		Foo: goqu.I("foo"),
		Bar: goqu.I("bar"),
		Baz: goqu.I("baz"),
	}

	_ = [...]struct {
		Columns Cols
	}{
		{
			Columns: Cols{columns.Bar},
		},
		{
			Columns: Cols{columns.Bar},
		},
		{
			Columns: Cols{columns.Bar},
		},
		{
			Columns: Cols{columns.Baz, columns.Foo},
		},
		{
			Columns: Cols{columns.Baz, columns.Foo},
		},
	}

	fmt.Println("done")
}

With the above code in test.go I ran go run ./test.go.

(Strangely, the same code seems to work on go.dev/play: https://go.dev/play/p/A-TOmDsk13O)

What did you expect to see?

done and a 0 exit code.

What did you see instead?

$ go run ./test.go 
# command-line-arguments
./test.go:27:25: internal compiler error: missing typecheck: 
.   AS # test.go:27:25
.   .   NAME-main..autotmp_21 esc(N) Class:PAUTO Offset:0 AutoTemp OnStack Used exp.IdentifierExpression tc(1) # test.go:27:25
.   .   DOT main.Bar exp.IdentifierExpression tc(1) # test.go:27:25
.   .   .   NAME-main.columns esc(no) Class:PAUTO Offset:0 OnStack Used STRUCT-struct { Foo exp.IdentifierExpression; Bar exp.IdentifierExpression; Baz exp.IdentifierExpression } tc(1) # test.go:13:2

Please file a bug report including a short program that triggers the error.
https://go.dev/issue/new
@biffen biffen changed the title affected/package: internal compiler error: missing typecheck Nov 14, 2022
@seankhliao seankhliao changed the title internal compiler error: missing typecheck cmd/compile: internal compiler error: missing typecheck Nov 14, 2022
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Nov 14, 2022
@seankhliao seankhliao added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Nov 14, 2022
@wdvxdr1123
Copy link
Contributor

I add line println(runtime.Version()) in playground and got go1.19.2. So, this file can be compiled well with go1.19.2 but failed with go1.19.3. Maybe 0618956 is the bad commit.

@cuonglm
Copy link
Member

cuonglm commented Nov 14, 2022

Simpler reproducer:

package p

type I interface {
	M()
}

type S struct{}

func (*S) M() {}

type slice []I

func f() {
	ss := struct {
		i I
	}{
		i: &S{},
	}

	_ = [...]struct {
		s slice
	}{
		{
			s: slice{ss.i},
		},
		{
			s: slice{ss.i},
		},
		{
			s: slice{ss.i},
		},
		{
			s: slice{ss.i},
		},
		{
			s: slice{ss.i},
		},
	}
}

The problem is that orderBlock may return un-typechecked node for nested composite literal. I will send the fix shortly.

@cuonglm cuonglm self-assigned this Nov 14, 2022
@cuonglm cuonglm 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 Nov 14, 2022
@cuonglm cuonglm added this to the Go1.20 milestone Nov 14, 2022
@gopherbot
Copy link

Change https://go.dev/cl/450215 mentions this issue: cmd/compile: fix missing typecheck for static initialization slice

@cuonglm
Copy link
Member

cuonglm commented Nov 14, 2022

Seems we need to backport this cc @mdempsky @randall77

@cuonglm cuonglm reopened this Nov 15, 2022
@cuonglm
Copy link
Member

cuonglm commented Nov 15, 2022

Reopen for backporting cc @randall77

@randall77
Copy link
Contributor

@gopherbot please open a backport issue for 1.19.

@gopherbot
Copy link

Backport issue(s) opened: #56744 (for 1.19).

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

6 participants