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: OCALLMETH missed by typecheck #57309

Closed
dbc60 opened this issue Dec 14, 2022 · 6 comments
Closed

cmd/compile: internal compiler error: OCALLMETH missed by typecheck #57309

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

Comments

@dbc60
Copy link

dbc60 commented Dec 14, 2022

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

$ go version
go version go1.19.4 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
$ go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\dcuthbertson\AppData\Local\go-build
set GOENV=C:\Users\dcuthbertson\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\dcuthbertson\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\dcuthbertson\go
set GOPRIVATE=
set GOROOT=C:\local\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\local\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.19.4
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\Users\dcuthbertson\repos\boom\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 -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=C:\Users\DCUTHB~1\AppData\Local\Temp\go-build1037280389=/tmp/go-build -gno-record-gcc-switches

What did you do?

I ran go test -v on the following code in pruner_test.go:

package prune

import (
	"os"
	"testing"

	"github.com/spf13/afero"
)

func TestPruner_Prune(t *testing.T) {
	testIO := []struct {
		name string
		fs   afero.Fs
	}{
		{
			name: "a simple test",
			fs: func() afero.Fs {
				fs := afero.NewMemMapFs()
				_ = fs.Mkdir("/proc/2", os.ModeDir)
				// Uncomment the next two lines prevent a compiler error
				//_ = afero.WriteFile(fs, "/proc/2/stat", []byte("2 (tail) S 1 SKIP 12"), 0777)
				//_ = fs.Remove("/proc/2/stat")

				return fs
			}(),
		},
	}

	for _, test := range testIO {
		t.Run(test.name, func(t *testing.T) {
		})
	}
}

What did you expect to see?

=== RUN   TestPruner_Prune
=== RUN   TestPruner_Prune/a_simple_test
--- PASS: TestPruner_Prune (0.00s)
    --- PASS: TestPruner_Prune/a_simple_test (0.00s)
PASS
ok      example.com/boom        0.310s

What did you see instead?

# example.com/boom [example.com/boom.test]
.\pruner_test.go:19:17: internal compiler error: OCALLMETH missed by typecheck

Please file a bug report including a short program that triggers the error.
https://go.dev/issue/new
FAIL    example.com/boom [build failed]

This compiler error can be avoided by uncommenting the two lines of commented-out code indicated in the source above. regardless, I believe the compiler shouldn't fail in either case.

@randall77
Copy link
Contributor

This reproduces with tip. Looking.

@thanm thanm added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Dec 14, 2022
@randall77
Copy link
Contributor

Simpler reproducer:

package main

type I interface {
	M()
}

type S struct {
}

func (S) M() {
}

func makeS() I {
	return &S{}
}

func main() {
	a := []struct {
		fs I
	}{
		{
			fs: func() I {
				x := makeS()
				x.M()
				return x
			}(),
		},
	}
	_ = a
}

@randall77
Copy link
Contributor

Buggy since 1.18.

@seankhliao seankhliao changed the title affected/package: cmd/compile: internal compiler error: OCALLMETH missed by typecheck Dec 14, 2022
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Dec 14, 2022
@randall77
Copy link
Contributor

This is not working because the escape pass is the one that calls typecheck.FixMethodCall. But the escape pass doesn't walk internal functions directly. Instead, it walks only top-level functions. As part of that, it keeps track of closures that it sees and walks those as well. But in this instance, we have an internal function that gets inlined. It doesn't get walked because it isn't at top level, and it isn't listed as a closure anywhere because the closure call got inlined.

I'm not sure why the escape pass is responsible for this rewrite.
@mdempsky You added some of the !IsHiddenClosure guards involved here.

Even simpler repro:

package main

type I interface {
	M()
}

type S struct {
}

func (*S) M() {
}

func main() {
	func() {
		I(&S{}).M()
	}()
}

@randall77
Copy link
Contributor

Conceivably we could just drop this function - there's no point in compiling it because all calls to it got inlined.

@mdempsky mdempsky self-assigned this Dec 14, 2022
@mdempsky mdempsky 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 Dec 14, 2022
@gopherbot
Copy link

Change https://go.dev/cl/457715 mentions this issue: cmd/compile: desugar OCALLMETH->OCALLFUNC within devirtualization

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

No branches or pull requests

5 participants