Skip to content

Commit ade9f33

Browse files
committed
cmd/go: add loaderstate as field on mvsReqs
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 <[email protected]> Reviewed-by: Michael Matloob <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent ccf4192 commit ade9f33

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

src/cmd/go/internal/modload/buildlist.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,7 +1319,7 @@ func tidyUnprunedRoots(loaderstate *State, ctx context.Context, mainModule modul
13191319

13201320
// Construct a build list with a minimal set of roots.
13211321
// This may remove or downgrade modules in altMods.
1322-
reqs := &mvsReqs{roots: keep}
1322+
reqs := &mvsReqs{loaderstate: loaderstate, roots: keep}
13231323
min, err := mvs.Req(mainModule, rootPaths, reqs)
13241324
if err != nil {
13251325
return nil, err
@@ -1445,7 +1445,7 @@ func updateUnprunedRoots(loaderstate *State, ctx context.Context, direct map[str
14451445

14461446
var roots []module.Version
14471447
for _, mainModule := range loaderstate.MainModules.Versions() {
1448-
min, err := mvs.Req(mainModule, rootPaths, &mvsReqs{roots: keep})
1448+
min, err := mvs.Req(mainModule, rootPaths, &mvsReqs{loaderstate: loaderstate, roots: keep})
14491449
if err != nil {
14501450
return rs, err
14511451
}

src/cmd/go/internal/modload/edit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ func editRequirements(loaderstate *State, ctx context.Context, rs *Requirements,
532532
}
533533
}
534534

535-
roots, err = mvs.Req(loaderstate.MainModules.mustGetSingleMainModule(loaderstate), rootPaths, &mvsReqs{roots: roots})
535+
roots, err = mvs.Req(loaderstate.MainModules.mustGetSingleMainModule(loaderstate), rootPaths, &mvsReqs{loaderstate: loaderstate, roots: roots})
536536
if err != nil {
537537
return nil, false, err
538538
}

src/cmd/go/internal/modload/mvs.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@ func cmpVersion(p string, v1, v2 string) int {
3939
// mvsReqs implements mvs.Reqs for module semantic versions,
4040
// with any exclusions or replacements applied internally.
4141
type mvsReqs struct {
42-
roots []module.Version
42+
loaderstate *State // TODO(jitsu): Is there a way we can not depend on the entire loader state?
43+
roots []module.Version
4344
}
4445

4546
func (r *mvsReqs) Required(mod module.Version) ([]module.Version, error) {
46-
if mod.Version == "" && LoaderState.MainModules.Contains(mod.Path) {
47+
if mod.Version == "" && r.loaderstate.MainModules.Contains(mod.Path) {
4748
// Use the build list as it existed when r was constructed, not the current
4849
// global build list.
4950
return r.roots, nil
@@ -53,7 +54,7 @@ func (r *mvsReqs) Required(mod module.Version) ([]module.Version, error) {
5354
return nil, nil
5455
}
5556

56-
summary, err := goModSummary(LoaderState, mod)
57+
summary, err := goModSummary(r.loaderstate, mod)
5758
if err != nil {
5859
return nil, err
5960
}
@@ -130,7 +131,7 @@ func previousVersion(loaderstate *State, ctx context.Context, m module.Version)
130131
return module.Version{Path: m.Path, Version: "none"}, nil
131132
}
132133

133-
func (*mvsReqs) Previous(m module.Version) (module.Version, error) {
134+
func (r *mvsReqs) Previous(m module.Version) (module.Version, error) {
134135
// TODO(golang.org/issue/38714): thread tracing context through MVS.
135-
return previousVersion(LoaderState, context.TODO(), m)
136+
return previousVersion(r.loaderstate, context.TODO(), m)
136137
}

0 commit comments

Comments
 (0)