Skip to content

x/tools/internal/refactor/inline: reduce call if neither binding decl nor callee body would create name conflicts #70759

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

Open
adonovan opened this issue Dec 10, 2024 · 1 comment
Labels
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

@adonovan
Copy link
Member

adonovan commented Dec 10, 2024

Inlining even simple calls such as:

_ = astutil.NodeContains(p.File, typeError.Pos)

causes literalization due to the need for a binding decl within the function body:

_ = func() bool { var n ast.Node = p.File; return n.Pos() <= typeError.Pos && typeError.Pos <= n.End() }()

But the name n is not used in the caller block, so it would be fine to melt the call down to:

var n ast.Node = p.File
_ = n.Pos() <= typeError.Pos && typeError.Pos <= n.End()

FWIW, without the _ = ... assignment, the inliner does reduce the call:

{
	var n ast.Node = p.File
	_ = n.Pos() <= typeError.Pos && typeError.Pos <= n.End()
}

@findleyr

@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Dec 10, 2024
@gopherbot gopherbot added this to the Unreleased milestone Dec 10, 2024
@adonovan adonovan added 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. and removed Tools This label describes issues relating to any tools in the x/tools repository. labels Dec 10, 2024
@findleyr findleyr modified the milestones: Unreleased, gopls/backlog Dec 10, 2024
@findleyr
Copy link
Member

Agreed.

FWIW, without the _ = ... assignment, the inliner does reduce the call:

Using a similar heuristic, we should remove the unnecessary nested block in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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

3 participants