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: relax recursive restriction while inlining #29737

Open
randall77 opened this Issue Jan 14, 2019 · 2 comments

Comments

Projects
None yet
2 participants
@randall77
Copy link
Contributor

randall77 commented Jan 14, 2019

package main

func main() {
	f(100)
}

func f(x int) {
	if x < 0 {
		return
	}
	g(x - 1)
}
func g(x int) {
	h(x - 1)
}
func h(x int) {
	f(x - 1)
}

The compiler refuses to inline anything in this example:

$ go tool compile -m=2 tmp.go
tmp.go:7:6: cannot inline f: recursive
tmp.go:13:6: cannot inline g: recursive
tmp.go:16:6: cannot inline h: recursive
tmp.go:3:6: can inline main as: func() { f(100) }

There's no reason to not inline, e.g., g into f.
As long as we're not inlining a function into itself, it should be ok (and even that might be ok, as long as we don't do it an infinite number of times).

This comes up only with mid-stack inlining. When we only inlined leaves, it was perfectly reasonable to abort on recursion. Now we don't have to.

This came up when looking at runtime.pcdatavalue. I had a CL (CL 157799) which modified it, and the modified version should have inlined. It didn't because of this issue, because pcdatavalue it is part of a reasonably large recursive loop.

@randall77 randall77 added this to the Go1.13 milestone Jan 14, 2019

@randall77

This comment has been minimized.

Copy link
Contributor Author

randall77 commented Jan 14, 2019

@josharian

This comment has been minimized.

Copy link
Contributor

josharian commented Jan 14, 2019

This might also help with a problem @CAFxX ran into (which also has another possible solution).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment