]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/modload: remove the Reqs function
authorBryan C. Mills <bcmills@google.com>
Fri, 20 Nov 2020 22:03:42 +0000 (17:03 -0500)
committerBryan C. Mills <bcmills@google.com>
Sat, 21 Nov 2020 03:29:37 +0000 (03:29 +0000)
The Reqs function returns an mvs.Reqs implemention for the global
build list. The API that it presents assumes that the build list is
globally consistent (problematic for #40775) and readily available
(problematic for #36460).

Fortunately, it is no longer used outside of the modload package.
We can instead use individual instances of the unexported mvsReqs
struct, making the dependency on the global build list more explicit.

For #36460
For #40775

Change-Id: I8674442f2a86416b0bf9c3395cb591c1e724c9d2
Reviewed-on: https://go-review.googlesource.com/c/go/+/272129
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
src/cmd/go/internal/modload/init.go
src/cmd/go/internal/modload/load.go
src/cmd/go/internal/modload/mvs.go
src/cmd/go/internal/modload/mvs_test.go

index b9345acbce2dc740a2244579503f18522360006b..a9b77c82b353b97e50271cec0cbe20756950282b 100644 (file)
@@ -853,7 +853,7 @@ func MinReqs() mvs.Reqs {
                        retain = append(retain, m.Path)
                }
        }
-       min, err := mvs.Req(Target, retain, Reqs())
+       min, err := mvs.Req(Target, retain, &mvsReqs{buildList: buildList})
        if err != nil {
                base.Fatalf("go: %v", err)
        }
@@ -985,7 +985,7 @@ func keepSums(addDirect bool) map[module.Version]bool {
        keep := make(map[module.Version]bool)
        var mu sync.Mutex
        reqs := &keepSumReqs{
-               Reqs: Reqs(),
+               Reqs: &mvsReqs{buildList: buildList},
                visit: func(m module.Version) {
                        // If we build using a replacement module, keep the sum for the replacement,
                        // since that's the code we'll actually use during a build.
index 302330278eba273784aabdcedc5fdc983bc22642..732c4af92b57375129627d5c6c25c4ee75dacc5d 100644 (file)
@@ -800,7 +800,7 @@ func loadFromRoots(params loaderParams) *loader {
        }
 
        var err error
-       reqs := Reqs()
+       reqs := &mvsReqs{buildList: buildList}
        buildList, err = mvs.BuildList(Target, reqs)
        if err != nil {
                base.Fatalf("go: %v", err)
@@ -842,7 +842,7 @@ func loadFromRoots(params loaderParams) *loader {
                }
 
                // Recompute buildList with all our additions.
-               reqs = Reqs()
+               reqs = &mvsReqs{buildList: buildList}
                buildList, err = mvs.BuildList(Target, reqs)
                if err != nil {
                        // If an error was found in a newly added module, report the package
index db57b3ec5fe4c18abc26324d2406e83d1299edf2..167d6819b06ae51620dc01195eacc30d17116ae1 100644 (file)
@@ -11,7 +11,6 @@ import (
        "sort"
 
        "cmd/go/internal/modfetch"
-       "cmd/go/internal/mvs"
 
        "golang.org/x/mod/module"
        "golang.org/x/mod/semver"
@@ -23,16 +22,6 @@ type mvsReqs struct {
        buildList []module.Version
 }
 
-// Reqs returns the current module requirement graph.
-// Future calls to EditBuildList do not affect the operation
-// of the returned Reqs.
-func Reqs() mvs.Reqs {
-       r := &mvsReqs{
-               buildList: buildList,
-       }
-       return r
-}
-
 func (r *mvsReqs) Required(mod module.Version) ([]module.Version, error) {
        if mod == Target {
                // Use the build list as it existed when r was constructed, not the current
index 0cb376ec3c06fc124dabf56e91f1d38802fdde03..50e93c381fdd1d4fba4c99c939368c0e04f5a9d3 100644 (file)
@@ -2,19 +2,17 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-package modload_test
+package modload
 
 import (
        "testing"
-
-       "cmd/go/internal/modload"
 )
 
 func TestReqsMax(t *testing.T) {
        type testCase struct {
                a, b, want string
        }
-       reqs := modload.Reqs()
+       reqs := new(mvsReqs)
        for _, tc := range []testCase{
                {a: "v0.1.0", b: "v0.2.0", want: "v0.2.0"},
                {a: "v0.2.0", b: "v0.1.0", want: "v0.2.0"},
@@ -27,7 +25,7 @@ func TestReqsMax(t *testing.T) {
        } {
                max := reqs.Max(tc.a, tc.b)
                if max != tc.want {
-                       t.Errorf("Reqs().Max(%q, %q) = %q; want %q", tc.a, tc.b, max, tc.want)
+                       t.Errorf("(%T).Max(%q, %q) = %q; want %q", reqs, tc.a, tc.b, max, tc.want)
                }
        }
 }