From f859799ccf537bc5f506698ae2d1ce028b81c78c Mon Sep 17 00:00:00 2001 From: Ian Alexander Date: Wed, 1 Oct 2025 23:21:21 -0400 Subject: [PATCH] cmd/go: inject State parameter into `modcmd.runVerify` This command modifies the call tree starting at `modcmd.runVerify` to inject a `State` parameter to every function that is currently using the global `modload.LoaderState` variable. By explicilty passing a `State` parameter, we can begin to eliminate the usage of the global `modload.LoaderState`. This commit is part of the overall effort to eliminate global modloader state. [git-generate] cd src/cmd/go/internal/modcmd rf 'inject modload.LoaderState runVerify' cd .. ./rf-cleanup.zsh Change-Id: I5b3b4670a4e2d19375049e585035145d14248b40 Reviewed-on: https://go-review.googlesource.com/c/go/+/709985 Reviewed-by: Michael Matloob Reviewed-by: Michael Matloob LUCI-TryBot-Result: Go LUCI --- src/cmd/go/internal/modcmd/verify.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cmd/go/internal/modcmd/verify.go b/src/cmd/go/internal/modcmd/verify.go index bf803fd2ebb..358d7dd2030 100644 --- a/src/cmd/go/internal/modcmd/verify.go +++ b/src/cmd/go/internal/modcmd/verify.go @@ -71,7 +71,7 @@ func runVerify(ctx context.Context, cmd *base.Command, args []string) { errsChans[i] = errsc mod := mod // use a copy to avoid data races go func() { - errsc <- verifyMod(ctx, mod) + errsc <- verifyMod(modload.LoaderState, ctx, mod) <-sem }() } @@ -89,12 +89,12 @@ func runVerify(ctx context.Context, cmd *base.Command, args []string) { } } -func verifyMod(ctx context.Context, mod module.Version) []error { +func verifyMod(loaderstate *modload.State, ctx context.Context, mod module.Version) []error { if gover.IsToolchain(mod.Path) { // "go" and "toolchain" have no disk footprint; nothing to verify. return nil } - if modload.LoaderState.MainModules.Contains(mod.Path) { + if loaderstate.MainModules.Contains(mod.Path) { return nil } var errs []error