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: functions evaluated in defer and go statements are not checked for inlining #42194

Closed
zephyrtronium opened this issue Oct 25, 2020 · 2 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@zephyrtronium
Copy link
Contributor

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

$ go version
go version devel +4c7a18d74a Thu Oct 22 01:20:16 2020 +0000 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
PS E:\gotip\src> E:\gotip\bin\go env
set GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\zephyr\AppData\Local\go-build
set GOENV=C:\Users\zephyr\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=E:\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=E:\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=E:\gotip
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=E:\gotip\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=E:\gotip\src\go.mod
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\zephyr\AppData\Local\Temp\go-build120537955=/tmp/go-build -gno-record-gcc-switches

What did you do?

Compile this source code with go tool compile -m=2 p.go:

package p

func f(x int) {
	defer f(g())
}

func g() int {
	return 1
}

What did you expect to see?

E:\go\p.go:7:6: can inline g with cost 2 as: func() int { return 1 }
E:\go\p.go:3:6: cannot inline f: recursive
E:\go\p.go:4:3: inlining call to g func() int { return 1 }

What did you see instead?

E:\go\p.go:7:6: can inline g with cost 2 as: func() int { return 1 }
E:\go\p.go:3:6: cannot inline f: recursive

I.e., I expect g to be inlined, but it is not.

Even though g is eligible to be inlined, and it is evaluated on line 4 to provide the argument to the deferred call to f, it is not inlined. The issue appears to be that inlnode marks the callee in defer and go statements as ineligible for inlining and then immediately returns, so the arguments to that callee are not checked.

I found this during work on #41117.

@gopherbot
Copy link

Change https://golang.org/cl/264997 mentions this issue: cmd/compile: inline functions evaluated in go and defer statements

@prattmic
Copy link
Member

For reference, #38471 is similar, though that one is about inlining of the deferred function itself, not calls in the deferred function arguments.

cc @randall77

@dmitshur dmitshur added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Oct 28, 2020
@dmitshur dmitshur added this to the Backlog milestone Oct 28, 2020
@golang golang locked and limited conversation to collaborators Oct 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants