From: Bryan C. Mills Date: Thu, 28 Jan 2021 15:18:24 +0000 (-0500) Subject: cmd/go/internal/mvs: don't emit duplicates from Req X-Git-Tag: go1.17beta1~1533 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=a76efea1fe18045ecb8d1cf2c1104208e636fbae;p=gostls13.git cmd/go/internal/mvs: don't emit duplicates from Req 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 Run-TryBot: Bryan C. Mills TryBot-Result: Go Bot Reviewed-by: Michael Matloob Reviewed-by: Jay Conrod --- diff --git a/src/cmd/go/internal/mvs/mvs.go b/src/cmd/go/internal/mvs/mvs.go index b630b610f1..f016d8ff15 100644 --- a/src/cmd/go/internal/mvs/mvs.go +++ b/src/cmd/go/internal/mvs/mvs.go @@ -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-- { diff --git a/src/cmd/go/internal/mvs/mvs_test.go b/src/cmd/go/internal/mvs/mvs_test.go index 721cd9635c..995a38fa92 100644 --- a/src/cmd/go/internal/mvs/mvs_test.go +++ b/src/cmd/go/internal/mvs/mvs_test.go @@ -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) {