From: Ian Alexander Date: Thu, 16 Oct 2025 22:15:14 +0000 (-0400) Subject: cmd/go: convert functions to methods X-Git-Tag: go1.26rc1~577 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=bcf7da1595;p=gostls13.git cmd/go: convert functions to methods 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 Reviewed-by: Michael Matloob Reviewed-by: Michael Matloob --- diff --git a/src/cmd/go/internal/modload/init.go b/src/cmd/go/internal/modload/init.go index d250d65671..9e07c72aa6 100644 --- a/src/cmd/go/internal/modload/init.go +++ b/src/cmd/go/internal/modload/init.go @@ -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, diff --git a/src/cmd/go/internal/toolchain/select.go b/src/cmd/go/internal/toolchain/select.go index b42f3dce05..8aa84e885f 100644 --- a/src/cmd/go/internal/toolchain/select.go +++ b/src/cmd/go/internal/toolchain/select.go @@ -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()