]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: convert functions to methods
authorIan Alexander <jitsu@google.com>
Thu, 16 Oct 2025 22:15:14 +0000 (18:15 -0400)
committerIan Alexander <jitsu@google.com>
Mon, 20 Oct 2025 19:53:36 +0000 (12:53 -0700)
This commit converts the Reset and setState functions to methods.

This commit is part of the overall effort to eliminate global
modloader state.

[git-generate]
cd src/cmd/go/internal/modload
rf '
  mv setState State.setState
  mv Reset State.Reset
'

Change-Id: Ibc40071dc044ef5d1ab0a0b03f17b75243a42011
Reviewed-on: https://go-review.googlesource.com/c/go/+/712702
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Michael Matloob <matloob@google.com>
src/cmd/go/internal/modload/init.go
src/cmd/go/internal/toolchain/select.go

index d250d65671305af82dacd82033ea52e121d25324..9e07c72aa6583c5feeba25aa748be4e1957ace9b 100644 (file)
@@ -81,7 +81,7 @@ func EnterWorkspace(ctx context.Context) (exit func(), err error) {
        }
 
        // Reset the state to a clean state.
-       oldstate := setState(LoaderState, State{})
+       oldstate := LoaderState.setState(State{})
        LoaderState.ForceUseModules = true
 
        // Load in workspace mode.
@@ -93,7 +93,7 @@ func EnterWorkspace(ctx context.Context) (exit func(), err error) {
        LoaderState.requirements = requirementsFromModFiles(LoaderState, ctx, LoaderState.MainModules.workFile, slices.Collect(maps.Values(LoaderState.MainModules.modFiles)), nil)
 
        return func() {
-               setState(LoaderState, oldstate)
+               LoaderState.setState(oldstate)
        }, nil
 }
 
@@ -377,11 +377,11 @@ func WorkFilePath(loaderstate *State) string {
 
 // Reset clears all the initialized, cached state about the use of modules,
 // so that we can start over.
-func Reset(s *State) {
-       setState(s, State{})
+func (s *State) Reset() {
+       s.setState(State{})
 }
 
-func setState(s *State, new State) State {
+func (s *State) setState(new State) State {
        oldState := State{
                initialized:     s.initialized,
                ForceUseModules: s.ForceUseModules,
index b42f3dce058b5cb07bb92e744b65bb9255df03cd..8aa84e885f58bfc02814b57a6f270b7237fc2346 100644 (file)
@@ -352,7 +352,7 @@ func Exec(gotoolchain string) {
        }
 
        // Set up modules without an explicit go.mod, to download distribution.
-       modload.Reset(modload.LoaderState)
+       modload.LoaderState.Reset()
        modload.LoaderState.ForceUseModules = true
        modload.LoaderState.RootMode = modload.NoRoot
        modload.Init(modload.LoaderState)
@@ -695,7 +695,7 @@ func maybeSwitchForGoInstallVersion(minVers string) {
        modload.LoaderState.ForceUseModules = true
        modload.LoaderState.RootMode = modload.NoRoot
        modload.Init(modload.LoaderState)
-       defer modload.Reset(modload.LoaderState)
+       defer modload.LoaderState.Reset()
 
        // See internal/load.PackagesAndErrorsOutsideModule
        ctx := context.Background()