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/gopls: parameter movement bug bash #70599

Closed
5 tasks done
findleyr opened this issue Nov 27, 2024 · 14 comments
Closed
5 tasks done

x/tools/gopls: parameter movement bug bash #70599

findleyr opened this issue Nov 27, 2024 · 14 comments
Labels
gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@findleyr
Copy link
Member

findleyr commented Nov 27, 2024

This issue tracks bugs encountered while using the new change signature/parameter movement feature.
Aggregating into a single issue for convenience; I'll keep adding to this list as I encounter bugs.

  • Unnecessary conversion between named and unnamed concrete types (example: passing type Hash [32]byte as an argument to a [32]byte parameter, we see that the inliner adds unnecessary conversions to [32]byte. I avoided unecessary interface->interface conversions, but we also don't need to worry about concrete->concrete.
  • Given a call site involving a short variable declaration (x, y := Foo(1, 2)), the inliner thinks it needs to introduce a binding declaration for x, y.
  • We offer to move variadic parameters... and then fail to type check the resulting modified package because we don't do it correctly. For now, we should not offer the parameter movement code action, if it involves a variadic parameter (my intuition is that supporting variadics would be too complicated to fix presently).
  • The inliner is too conservative about side effects. For change signature refactoring, we should ignore effects.
  • The rewrite used for change signature refactoring is liable to run into argument variables shadowed by other parameters. We can avoid this using shadow groups.
@findleyr findleyr added this to the gopls/v0.17.0 milestone Nov 27, 2024
@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Nov 27, 2024
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/632115 mentions this issue: gopls/internal/test/marker: add reproducers for moveparam bug bash bugs

@findleyr
Copy link
Member Author

(BTW, if anyone reading this is experimenting with the new parameter movement code action, please feel free to comment with any bugs you observe).

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/632935 mentions this issue: internal/refactor/inline: more precise redundant conversion detection

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/633096 mentions this issue: gopls/internal/golang: don't offer to move variadic parameters

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/632937 mentions this issue: internal/refactor/inline: fix condition for assignment splice strategy

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/633256 mentions this issue: internal/refactor/inline: substitute groups of codependent arguments

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/633255 mentions this issue: gopls/internal/golang: ignore effects for change signature refactoring

gopherbot pushed a commit to golang/tools that referenced this issue Dec 3, 2024
Add a marker test that reproduces bugs encountered during bug bash of
parameter movement refactoring. Subsequent CLs will fix these bugs.

For golang/go#70599

Change-Id: Ieb52c1c02f11fa22bc043d7793509914d76d27ca
Reviewed-on: https://go-review.googlesource.com/c/tools/+/632115
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
gopherbot pushed a commit to golang/tools that referenced this issue Dec 3, 2024
Add more precision (and hopefully clarity) to the detection of redundant
conversions, by using more granular analysis of references. We now
record, for each reference, (1) whether it appears in an assignment
context, perhaps subject to implicit conversions, (2) whether this
assignment is to an interface value, and (3) whether this assignment may
affect type inference.

With these conditions, we can more precisely detect scenarios where
conversion is necessary, as annotated in the code. Notably, this avoids
unnecessary concrete-to-concrete conversions.

Also:
- Fix a crash in falcon analysis for named literal types.
- Handle index expression assignability (previously missing).
- Avoid the print builtin as an example of a function that takes 'any',
  as the type checker records the effective type for print, and the spec
  is unclear about whether implementations are allowed to specialize for
  effective types.

For golang/go#70599
Updates golang/go#70638

Change-Id: I9730deba54d864928a1dc02a1ab00481a2ce9998
Reviewed-on: https://go-review.googlesource.com/c/tools/+/632935
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
gopherbot pushed a commit to golang/tools that referenced this issue Dec 3, 2024
While we can't handle moving variadic parameters, don't offer to move
them.

For golang/go#70599

Change-Id: I21e78b4e2ae8c061d3858f2f981d593a6b0cf5bc
Reviewed-on: https://go-review.googlesource.com/c/tools/+/633096
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Robert Findley <rfindley@google.com>
gopherbot pushed a commit to golang/tools that referenced this issue Dec 3, 2024
In the assign statements strategy, if there are no nontrivial result
conversions, we can replace a call with its result expression regardless
of the AssignStmt.Tok.

For golang/go#70599

Change-Id: Ifa2b615c17d58e3bbc708b9ecf98530858915564
Reviewed-on: https://go-review.googlesource.com/c/tools/+/632937
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
gopherbot pushed a commit to golang/tools that referenced this issue Dec 4, 2024
In change signature refactoring, the wrapper was very likely to run into
a particular unidiomatic behavior of the inliner, where arguments were
detected as unsubstitutable because they have free variables shadowed by
other parameters. But if those other parameters are going to be
substituted, this shadowing is irrelevant.

Fix this by keeping track of shadowing from other parameters in a new
shadowMap type, and then analyzing these relationships during
substitution to detect cases where closed subgraphs of parameters can be
substituted simultaneously.

Also: fix a formatting bug (golang/go#67335) that was reproduced by one
of the new tests: we need to clear positions when using nodes from the
callee in the caller's binding decl.

For golang/go#70599
Fixes golang/go#67335

Change-Id: I08970a1cea8a82ea108084394569cffbc5975235
Reviewed-on: https://go-review.googlesource.com/c/tools/+/633256
Reviewed-by: Alan Donovan <adonovan@google.com>
Auto-Submit: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
gopherbot pushed a commit to golang/tools that referenced this issue Dec 4, 2024
While using the change signature refactoring, I never want it to
literalize changed signatures based on its (very coarse) effects
analysis. Disable this inlining analysis for the purpose of change
signature refactoring.

For golang/go#70599

Change-Id: I979c4f5b6be520b67a3441fa6e0c55afe1fe9196
Reviewed-on: https://go-review.googlesource.com/c/tools/+/633255
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/633711 mentions this issue: internal/refactor/inline: more precise redundant conversion detection

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/633714 mentions this issue: internal/refactor/inline: fix condition for splice assignment strategy

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/633710 mentions this issue: gopls/internal/test/marker: add reproducers for moveparam bug bash bugs

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/633713 mentions this issue: gopls/internal/golang: don't offer to move variadic parameters

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/633719 mentions this issue: gopls/internal/golang: ignore effects for change signature refactoring

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/633718 mentions this issue: internal/refactor/inline: substitute groups of dependent arguments

@findleyr
Copy link
Member Author

findleyr commented Dec 5, 2024

All done.

@findleyr findleyr closed this as completed Dec 5, 2024
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. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

2 participants