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/go/packages: Load(&cfg...) modifies cfg, contra explicit documentation #67702

Closed
adonovan opened this issue May 29, 2024 · 3 comments
Closed
Labels
Documentation Issues describing a change to documentation. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@adonovan
Copy link
Member

adonovan commented May 29, 2024

The Load function claims not to mutate the Config, but it does in fact mutate the non-exported fields, and has done for some time. In https://go.dev/cl588936 I proposed to update the docs to match reality:

// Calls to [Load] do not modify the public fields of this struct, but
// may modify hidden fields, so concurrent calls to [Load] must not
// use the same Config.

but perhaps we should instead reestablish the invariant rather than give it up.

@findleyr @matloob

@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label May 29, 2024
@gopherbot gopherbot added this to the Unreleased milestone May 29, 2024
@gopherbot gopherbot added the Documentation Issues describing a change to documentation. label May 29, 2024
@mknyszek mknyszek added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jun 3, 2024
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/625255 mentions this issue: go/packages: remove unexported fields from user facing Config

@xieyuschen
Copy link
Contributor

Hi @adonovan , I have sent you a CL by moving all unexport fields from Config to an unexported config struct so packages.Load won't modify user provided Config in any case. Let me know whether you like this approach:)

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/625475 mentions this issue: go/packages: do not mutate Config

dennypenta pushed a commit to dennypenta/tools that referenced this issue Dec 3, 2024
This CL establishes the documented (but previously false)
invariant that Load does not mutate Config.

The stateful fields have been moved:
- gocmdRunner is moved to golistState;
- goListOverlayFile is now a parameter of driver.
  In principle a non-standard driver might use
  this field (as suggested by the Config.Overlay
  documentation) but today none does.
  Nonetheless WriteOverlays is now called before
  the external driver.

Fixes golang/go#67702

Change-Id: Ifc8a5228aecc6bcb6240ac82e2be3a514f03637e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/625475
Auto-Submit: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Issues describing a change to documentation. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. 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