]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: add loaderstate as field on `mvsReqs`
authorIan Alexander <jitsu@google.com>
Thu, 2 Oct 2025 19:31:10 +0000 (15:31 -0400)
committerIan Alexander <jitsu@google.com>
Sat, 25 Oct 2025 01:07:56 +0000 (18:07 -0700)
This change modifies the type `mvsReqs` to have an additional field to
store the current module loader state.  The field is used to break the
dependency on the global `modload.LoaderState` variable.

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

Change-Id: Id6bd96bc5de68bf327f9e78a778173634e1d15d2
Reviewed-on: https://go-review.googlesource.com/c/go/+/711122
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/buildlist.go
src/cmd/go/internal/modload/edit.go
src/cmd/go/internal/modload/mvs.go

index bd3fc3ec75713b938399facbf53f6291fa5778a2..cb64bec9c81d121c1a360a761384bebc2527bdd5 100644 (file)
@@ -1319,7 +1319,7 @@ func tidyUnprunedRoots(loaderstate *State, ctx context.Context, mainModule modul
 
        // Construct a build list with a minimal set of roots.
        // This may remove or downgrade modules in altMods.
-       reqs := &mvsReqs{roots: keep}
+       reqs := &mvsReqs{loaderstate: loaderstate, roots: keep}
        min, err := mvs.Req(mainModule, rootPaths, reqs)
        if err != nil {
                return nil, err
@@ -1445,7 +1445,7 @@ func updateUnprunedRoots(loaderstate *State, ctx context.Context, direct map[str
 
        var roots []module.Version
        for _, mainModule := range loaderstate.MainModules.Versions() {
-               min, err := mvs.Req(mainModule, rootPaths, &mvsReqs{roots: keep})
+               min, err := mvs.Req(mainModule, rootPaths, &mvsReqs{loaderstate: loaderstate, roots: keep})
                if err != nil {
                        return rs, err
                }
index 72d0f754224456789742745ab52e538d58ac7d4c..1996b7c26b0dc6464eb7056d3b2076bc99420079 100644 (file)
@@ -532,7 +532,7 @@ func editRequirements(loaderstate *State, ctx context.Context, rs *Requirements,
                        }
                }
 
-               roots, err = mvs.Req(loaderstate.MainModules.mustGetSingleMainModule(loaderstate), rootPaths, &mvsReqs{roots: roots})
+               roots, err = mvs.Req(loaderstate.MainModules.mustGetSingleMainModule(loaderstate), rootPaths, &mvsReqs{loaderstate: loaderstate, roots: roots})
                if err != nil {
                        return nil, false, err
                }
index fba508873faee1bb1e0f7c21119d0fd412d71e18..63fedae0f162124a16c0509561a3ceea8ebc342c 100644 (file)
@@ -39,11 +39,12 @@ func cmpVersion(p string, v1, v2 string) int {
 // mvsReqs implements mvs.Reqs for module semantic versions,
 // with any exclusions or replacements applied internally.
 type mvsReqs struct {
-       roots []module.Version
+       loaderstate *State // TODO(jitsu): Is there a way we can not depend on the entire loader state?
+       roots       []module.Version
 }
 
 func (r *mvsReqs) Required(mod module.Version) ([]module.Version, error) {
-       if mod.Version == "" && LoaderState.MainModules.Contains(mod.Path) {
+       if mod.Version == "" && r.loaderstate.MainModules.Contains(mod.Path) {
                // Use the build list as it existed when r was constructed, not the current
                // global build list.
                return r.roots, nil
@@ -53,7 +54,7 @@ func (r *mvsReqs) Required(mod module.Version) ([]module.Version, error) {
                return nil, nil
        }
 
-       summary, err := goModSummary(LoaderState, mod)
+       summary, err := goModSummary(r.loaderstate, mod)
        if err != nil {
                return nil, err
        }
@@ -130,7 +131,7 @@ func previousVersion(loaderstate *State, ctx context.Context, m module.Version)
        return module.Version{Path: m.Path, Version: "none"}, nil
 }
 
-func (*mvsReqs) Previous(m module.Version) (module.Version, error) {
+func (*mvsReqs) Previous(m module.Version) (module.Version, error) {
        // TODO(golang.org/issue/38714): thread tracing context through MVS.
-       return previousVersion(LoaderState, context.TODO(), m)
+       return previousVersion(r.loaderstate, context.TODO(), m)
 }