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: inline message not right #54159

Closed
578559967 opened this issue Aug 1, 2022 · 3 comments
Closed

cmd/compile: inline message not right #54159

578559967 opened this issue Aug 1, 2022 · 3 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@578559967
Copy link

578559967 commented Aug 1, 2022

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

$ go version
go version devel go1.19-be0b2a393a Wed Jun 22 02:40:04 2022 +0000 darwin/arm64

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
GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/r/Library/Caches/go-build"
GOENV="/Users/r/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/r/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/r/go"
GOPRIVATE=""
GOPROXY="https://goproxy.cn,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="devel go1.19-be0b2a393a Wed Jun 22 02:40:04 2022 +0000"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/renzhenyu/workspace/testcode/testinline/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 -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/lr/5ttkwx8x6s9fm23m80546v180000gn/T/go-build3093233778=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

package main

import "fmt"

func run() {
	f := func() {
		fmt.Println("hello")
	}
	f()
	run()
}

func main() {
	run()
}

build this program with gcflags="-m=2",you will get these two conflict message:

go build --gcflags="-m=2" ./test3.go
# command-line-arguments
./test3.go:5:6: cannot inline run: recursive
./test3.go:6:7: can inline run.func1 with cost 76 as: func() { fmt.Println("hello") }
./test3.go:9:3: inlining call to run.func1      <------------------------------------------- message 1
./test3.go:9:3: inlining call to fmt.Println
./test3.go:6:7: cannot inline run.func1: recursive  <------------------------------------------- message 2
./test3.go:7:14: inlining call to fmt.Println
./test3.go:13:6: can inline main with cost 59 as: func() { run() }
./test3.go:9:3: "hello" escapes to heap:
./test3.go:9:3:   flow: {storage for ... argument} = &{storage for "hello"}:
./test3.go:9:3:     from "hello" (spill) at ./test3.go:9:3
./test3.go:9:3:     from ... argument (slice-literal-element) at ./test3.go:9:3
./test3.go:9:3:   flow: fmt.a = &{storage for ... argument}:
./test3.go:9:3:     from ... argument (spill) at ./test3.go:9:3
./test3.go:9:3:     from fmt.a := ... argument (assign-pair) at ./test3.go:9:3
./test3.go:9:3:   flow: {heap} = *fmt.a:
./test3.go:9:3:     from fmt.Fprintln(io.Writer(os.Stdout), fmt.a...) (call parameter) at ./test3.go:9:3
./test3.go:7:15: "hello" escapes to heap:
./test3.go:7:15:   flow: {storage for ... argument} = &{storage for "hello"}:
./test3.go:7:15:     from "hello" (spill) at ./test3.go:7:15
./test3.go:7:15:     from ... argument (slice-literal-element) at ./test3.go:7:14
./test3.go:7:15:   flow: fmt.a = &{storage for ... argument}:
./test3.go:7:15:     from ... argument (spill) at ./test3.go:7:14
./test3.go:7:15:     from fmt.a := ... argument (assign-pair) at ./test3.go:7:14
./test3.go:7:15:   flow: {heap} = *fmt.a:
./test3.go:7:15:     from fmt.Fprintln(io.Writer(os.Stdout), fmt.a...) (call parameter) at ./test3.go:7:14
./test3.go:6:7: func literal does not escape
./test3.go:7:14: ... argument does not escape
./test3.go:7:15: "hello" escapes to heap
./test3.go:9:3: ... argument does not escape
./test3.go:9:3: "hello" escapes to heap

What did you expect to see?

Expect message 2 ("cannot inline run.func1: recursive") not to be shown.

What did you see instead?

Message 2("cannot inline run.func1: recursive") is printed.

@578559967 578559967 changed the title affected/package: cmd/compile: inline message not right. Aug 1, 2022
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Aug 1, 2022
@mvdan
Copy link
Member

mvdan commented Aug 1, 2022

What is not right about that message?

@mvdan mvdan added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Aug 1, 2022
@578559967
Copy link
Author

What is not right about that message?

The message 1 shows that the run.func1 has been inlined, but the message 2 show that run.func1 can't be inlined.

@mknyszek mknyszek changed the title cmd/compile: inline message not right. cmd/compile: inline message not right Aug 3, 2022
@mknyszek mknyszek added this to the Backlog milestone Aug 3, 2022
@seankhliao seankhliao added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. and removed WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Dec 17, 2022
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/463233 mentions this issue: cmd/compile: fix -m=2 output for recursive function with closures

@golang golang locked and limited conversation to collaborators Jan 28, 2024
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 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

5 participants