]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/mvs: don't emit duplicates from Req
authorBryan C. Mills <bcmills@google.com>
Thu, 28 Jan 2021 15:18:24 +0000 (10:18 -0500)
committerBryan C. Mills <bcmills@google.com>
Thu, 18 Feb 2021 17:57:36 +0000 (17:57 +0000)
Req is supposed to return “a minimal requirement list”
that includes each of the module paths listed in base.
Currently, if base contains duplicates Req emits duplicates,
and a list containing duplicates is certainly not minimal.

That, in turn, requires callers to be careful to deduplicate the base
slice, and there are multiple callers that are already quite
complicated to reason about even without the added complication of
deduplicating slices.

For #36460

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

index b630b610f10e03641362acf7b385f34781e58cf5..f016d8ff15d96ddcddb91b235105b2645ddb4d29 100644 (file)
@@ -293,10 +293,15 @@ func Req(target module.Version, base []string, reqs Reqs) ([]module.Version, err
        }
        // First walk the base modules that must be listed.
        var min []module.Version
+       haveBase := map[string]bool{}
        for _, path := range base {
+               if haveBase[path] {
+                       continue
+               }
                m := module.Version{Path: path, Version: max[path]}
                min = append(min, m)
                walk(m)
+               haveBase[path] = true
        }
        // Now the reverse postorder to bring in anything else.
        for i := len(postorder) - 1; i >= 0; i-- {
index 721cd9635c8d84dabead835817dfa9f817b97fc2..995a38fa92a8e711d9bb84827186a88d7247bdb3 100644 (file)
@@ -327,6 +327,19 @@ B1: Cnone D1
 E1: Fnone
 build M: M B1 D1 E1
 req M: B1 E1
+
+name: reqdup
+M: A1 B1
+A1: B1
+B1:
+req M A A: A1
+
+name: reqcross
+M: A1 B1 C1
+A1: B1 C1
+B1: C1
+C1:
+req M A B: A1 B1
 `
 
 func Test(t *testing.T) {