At the moment the inliner operates on one call at a time this limits the cleanup work the inliner can do when you want to inline all calls in a single file.

One example for such cleanups are import renames and removals. Since #67281 is fixed it now works for individual calls. However, if there are multiple calls in a single file, the problems remains. The inliner analyzer generates one diagnostic per call and the attached suggested fix needs to be self contained and correct when applied in isolation. This means if there are two calls, the inliner cannot avoid the import rename and cannot remove the import of the old package because it would make it impossible to apply the suggested fixes in isolation. Example:

-- path/to/old/dependency/dep.go --
package dependency
import "path/to/new/dependency"
// inlineme
func Foo() { dependency.Foo() }

-- path/to/new/dependency/dep.go --
package dependency
func Foo() {}

-- some/user/main.go --
package main
import "path/to/old/dependency"
func main() {
  dependency.Foo() // one diagnostic here
  dependency.Foo() // another diagnostic here
}

To solve this problem the inliner could offer a mode in which it generated one diagnostic per file with a suggested fix that inlines all calls (potentially of different functions).

Comment From: gabyhelp

Related Issues and Documentation

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

Comment From: dmitshur

CC @adonovan.

Comment From: adonovan

Related: - https://github.com/golang/go/issues/66370 deals with "inline all" and "inline away".

This issue overlaps with it, but is really about the problem that fixes that are valid in isolation may conflict, either syntactically or semantically, when applied together. This is a general problem with all fixes, but inlining is a special case where the optimum solution to "inline all" is not simply the sum of a set of nonconflicting individual fixes. I suspect it is a difficult problem.