From: Ian Alexander Date: Fri, 10 Oct 2025 01:05:35 +0000 (-0400) Subject: cmd/go: use local state object in `env.runEnv` X-Git-Tag: go1.26rc1~487 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=26a8a21d7f;p=gostls13.git cmd/go: use local state object in `env.runEnv` This commit modifies `env.runEnv` to construct a new modload.State object using the new constructor instead of the current global `modload.LoaderState` variable. This commit is part of the overall effort to eliminate global modloader state. [git-generate] cd src/cmd/go/internal/envcmd rf ' add env.go:/func runEnv\(/-0 var moduleLoaderState *modload.State ex { import "cmd/go/internal/modload"; modload.LoaderState -> moduleLoaderState } add runEnv://+0 moduleLoaderState := modload.NewState() rm env.go:/var moduleLoaderState \*modload.State/ ' Change-Id: I1177df5d09a6ee642eade6cfa4278bb1629843a8 Reviewed-on: https://go-review.googlesource.com/c/go/+/711131 Reviewed-by: Michael Matloob Reviewed-by: Michael Matloob LUCI-TryBot-Result: Go LUCI --- diff --git a/src/cmd/go/internal/envcmd/env.go b/src/cmd/go/internal/envcmd/env.go index aaadc2fde1..f600a35472 100644 --- a/src/cmd/go/internal/envcmd/env.go +++ b/src/cmd/go/internal/envcmd/env.go @@ -272,6 +272,7 @@ func argKey(arg string) string { } func runEnv(ctx context.Context, cmd *base.Command, args []string) { + moduleLoaderState := modload.NewState() if *envJson && *envU { base.Fatalf("go: cannot use -json with -u") } @@ -306,7 +307,7 @@ func runEnv(ctx context.Context, cmd *base.Command, args []string) { } env := cfg.CmdEnv - env = append(env, ExtraEnvVars(modload.LoaderState)...) + env = append(env, ExtraEnvVars(moduleLoaderState)...) if err := fsys.Init(); err != nil { base.Fatal(err) @@ -336,8 +337,8 @@ func runEnv(ctx context.Context, cmd *base.Command, args []string) { } } if needCostly { - work.BuildInit(modload.LoaderState) - env = append(env, ExtraEnvVarsCostly(modload.LoaderState)...) + work.BuildInit(moduleLoaderState) + env = append(env, ExtraEnvVarsCostly(moduleLoaderState)...) } if len(args) > 0 {