From 0d3044f9655c3a3f94565b2918515d93f6fe2485 Mon Sep 17 00:00:00 2001 From: Ian Alexander Date: Thu, 16 Oct 2025 18:09:57 -0400 Subject: [PATCH] cmd/go: make Reset work with any State instance 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 Reviewed-by: Michael Matloob LUCI-TryBot-Result: Go LUCI --- src/cmd/go/internal/modload/init.go | 4 ++-- src/cmd/go/internal/toolchain/select.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cmd/go/internal/modload/init.go b/src/cmd/go/internal/modload/init.go index 34af9796e5..d250d65671 100644 --- a/src/cmd/go/internal/modload/init.go +++ b/src/cmd/go/internal/modload/init.go @@ -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 { diff --git a/src/cmd/go/internal/toolchain/select.go b/src/cmd/go/internal/toolchain/select.go index d54277ed1b..b42f3dce05 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.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() -- 2.52.0