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: not inlined closures can't inline inner closures #41988

Open
DmitriyMV opened this issue Oct 15, 2020 · 2 comments
Open

cmd/compile: not inlined closures can't inline inner closures #41988

DmitriyMV opened this issue Oct 15, 2020 · 2 comments

Comments

@DmitriyMV
Copy link

@DmitriyMV DmitriyMV commented Oct 15, 2020

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

$ go version
go version go1.15 darwin/amd64

Does this issue reproduce with the latest release?

Yes.

What did you do?

Wrote code:

package go_closures

func callInt(val int) int {
	getInt := func() int { return val }
	return callFn(getInt)
}

func callFn(getInt func() int) int {
	outer := func() int { return getInt() }
	return globalFunc(outer)
}

var globalFunc = func(f func() int) int {
	return f()
}

What did you expect to see?

getInt is inlined into outer. outer escapes to the heap.

What did you see instead?

getInt isn't inlined into outer. Both outer and getInt escape to the heap.

@DmitriyMV
Copy link
Author

@DmitriyMV DmitriyMV commented Oct 15, 2020

The main problem here is that getInt closure escapes when it can be folded into outer (even with call).

@mdempsky
Copy link
Member

@mdempsky mdempsky commented Oct 18, 2020

The issue here is we don't currently support inlining functions that contain closures. We'd first need to inline callFn into callInt to be able to inline getInt into outer.

Escape analysis is a red herring here. Escape analysis runs after inlining and doesn't affect inlining decisions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.