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

x/tools/internal/refactor/inline: offer an option to inline all calls in a file #68567

Open
lfolger opened this issue Jul 24, 2024 · 2 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Refactoring Issues related to refactoring tools Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@lfolger
Copy link
Contributor

lfolger commented Jul 24, 2024

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).

@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Jul 24, 2024
@gopherbot gopherbot added this to the Unreleased milestone Jul 24, 2024
@gabyhelp
Copy link

@dmitshur dmitshur added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jul 25, 2024
@dmitshur
Copy link
Contributor

CC @adonovan.

@findleyr findleyr added the Refactoring Issues related to refactoring tools label Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Refactoring Issues related to refactoring tools Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

5 participants