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,x/tools/gopls: undo variadic elimination when it is safe to do so #63717

Closed
findleyr opened this issue Oct 24, 2023 · 4 comments
Assignees
Labels
FixPending Issues that have a fix which has not yet been reviewed or submitted. gopls Issues related to the Go language server, gopls. Refactoring Issues related to refactoring tools Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@findleyr
Copy link
Member

findleyr commented Oct 24, 2023

Follow up on this comment on a semi-automated CL: https://go-review.googlesource.com/c/tools/+/537475/1/gopls/internal/lsp/source/rename.go#973

The inliner should undo variadic elimination (packing variadic arguments as []T{...}) when it is safe to do so. As a result of the current logic, the inliner may introduce this redundancy at the callsite.

CC @adonovan

@findleyr findleyr added gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. labels Oct 24, 2023
@findleyr findleyr added this to the gopls/v0.15.0 milestone Oct 24, 2023
@findleyr findleyr added the Refactoring Issues related to refactoring tools label Oct 24, 2023
@adonovan
Copy link
Member

adonovan commented Oct 25, 2023

FWIW, "Safe to do so" means there is exactly one use of the parameter in the callee body and it is the final argument of an ellipsis call f(param...).

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/629136 mentions this issue: internal/refactor: undo variadic elimination during substitution

@findleyr
Copy link
Member Author

FWIW, "Safe to do so" means there is exactly one use of the parameter in the callee body and it is the final argument of an ellipsis call f(param...).

I don't think that's right. []T{a,b,c}... is safe to replace with a, b, c wherever it occurs.

@findleyr findleyr added the FixPending Issues that have a fix which has not yet been reviewed or submitted. label Nov 19, 2024
@adonovan
Copy link
Member

I don't think that's right. []T{a,b,c}... is safe to replace with a, b, c wherever it occurs.

Good point. Though I suspect that if there were multiple uses of the parameter, it would not have been substituted, so you would not see f([]T{a, b, c}...), only f(args...) after a binding decl var args = []T{a, b, c}.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FixPending Issues that have a fix which has not yet been reviewed or submitted. gopls Issues related to the Go language server, gopls. 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

4 participants