]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: make Reset work with any State instance
authorIan Alexander <jitsu@google.com>
Thu, 16 Oct 2025 22:09:57 +0000 (18:09 -0400)
committerIan Alexander <jitsu@google.com>
Mon, 20 Oct 2025 19:52:55 +0000 (12:52 -0700)
This commit updates the Reset function to work with any state
object in preparation for converting it to a method.

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

Change-Id: I6103842ea0a0528698217930afc0e34a2aa21eea
Reviewed-on: https://go-review.googlesource.com/c/go/+/712701
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Michael Matloob <matloob@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/cmd/go/internal/modload/init.go
src/cmd/go/internal/toolchain/select.go

index 34af9796e59ad19bff8ffd0d3dc1992f5bcec3cf..d250d65671305af82dacd82033ea52e121d25324 100644 (file)
@@ -377,8 +377,8 @@ 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() {
-       setState(LoaderState, State{})
+func Reset(s *State) {
+       setState(s, State{})
 }
 
 func setState(s *State, new State) State {
index d54277ed1b4beafc71d16429a44c960e35deca98..b42f3dce058b5cb07bb92e744b65bb9255df03cd 100644 (file)
@@ -352,7 +352,7 @@ func Exec(gotoolchain string) {
        }
 
        // Set up modules without an explicit go.mod, to download distribution.
-       modload.Reset()
+       modload.Reset(modload.LoaderState)
        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()
+       defer modload.Reset(modload.LoaderState)
 
        // See internal/load.PackagesAndErrorsOutsideModule
        ctx := context.Background()