Skip to content

Commit

Permalink
[dev.typeparams] all: merge master (eb98272) into dev.typeparams
Browse files Browse the repository at this point in the history
Merge List:

+ 2021-02-18 eb98272 cmd/go/internal/mvs: fix Downgrade to match Algorithm 4
+ 2021-02-18 3b7277d cmd/go: add a script test for artifacts resulting from 'go get -u'
+ 2021-02-18 f3c2208 cmd/go: add script tests for potential upgrades due to downgrades
+ 2021-02-18 a5c8a15 cmd/go/internal/mvs: clarify and annotate test cases
+ 2021-02-18 a76efea cmd/go/internal/mvs: don't emit duplicates from Req
+ 2021-02-18 609d82b cmd/dist: set GOARM=7 for windows/arm
+ 2021-02-18 f0be3cc runtime: unbreak linux/riscv64 following regabi merge
+ 2021-02-18 07ef313 runtime/cgo: add cast in C code to avoid C compiler warning

Change-Id: I8e58ad1e82a9ea313a99c1b11df5b341f80680d4
  • Loading branch information
griesemer committed Feb 18, 2021
2 parents 2ff1e05 + eb98272 commit e7493a9
Show file tree
Hide file tree
Showing 9 changed files with 462 additions and 34 deletions.
4 changes: 4 additions & 0 deletions src/cmd/dist/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,10 @@ func xgetgoarm() string {
// sense to auto-detect the setting.
return "7"
}
if goos == "windows" {
// windows/arm only works with ARMv7 executables.
return "7"
}
if gohostarch != "arm" || goos != gohostos {
// Conservative default for cross-compilation.
return "5"
Expand Down
32 changes: 27 additions & 5 deletions src/cmd/go/internal/mvs/mvs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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-- {
Expand Down Expand Up @@ -370,10 +375,19 @@ func Upgrade(target module.Version, reqs Reqs, upgrade ...module.Version) ([]mod
// reqs.Previous, but the methods of reqs must otherwise handle such versions
// correctly.
func Downgrade(target module.Version, reqs Reqs, downgrade ...module.Version) ([]module.Version, error) {
list, err := reqs.Required(target)
// Per https://research.swtch.com/vgo-mvs#algorithm_4:
// “To avoid an unnecessary downgrade to E 1.1, we must also add a new
// requirement on E 1.2. We can apply Algorithm R to find the minimal set of
// new requirements to write to go.mod.”
//
// In order to generate those new requirements, we need to identify versions
// for every module in the build list — not just reqs.Required(target).
list, err := BuildList(target, reqs)
if err != nil {
return nil, err
}
list = list[1:] // remove target

max := make(map[string]string)
for _, r := range list {
max[r.Path] = r.Version
Expand Down Expand Up @@ -406,6 +420,9 @@ func Downgrade(target module.Version, reqs Reqs, downgrade ...module.Version) ([
}
added[m] = true
if v, ok := max[m.Path]; ok && reqs.Max(m.Version, v) != v {
// m would upgrade an existing dependency — it is not a strict downgrade,
// and because it was already present as a dependency, it could affect the
// behavior of other relevant packages.
exclude(m)
return
}
Expand All @@ -422,6 +439,7 @@ func Downgrade(target module.Version, reqs Reqs, downgrade ...module.Version) ([
// is transient (we couldn't download go.mod), return the error from
// Downgrade. Currently, we can't tell what kind of error it is.
exclude(m)
return
}
for _, r := range list {
add(r)
Expand All @@ -433,8 +451,8 @@ func Downgrade(target module.Version, reqs Reqs, downgrade ...module.Version) ([
}
}

var out []module.Version
out = append(out, target)
downgraded := make([]module.Version, 0, len(list)+1)
downgraded = append(downgraded, target)
List:
for _, r := range list {
add(r)
Expand All @@ -461,10 +479,14 @@ List:
add(p)
r = p
}
out = append(out, r)
downgraded = append(downgraded, r)
}

return out, nil
return BuildList(target, &override{
target: target,
list: downgraded,
Reqs: reqs,
})
}

type override struct {
Expand Down
106 changes: 81 additions & 25 deletions src/cmd/go/internal/mvs/mvs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ D4: E2 F1
D5: E2
G1: C4
A2: B1 C4 D4
build A: A B1 C2 D4 E2 F1
upgrade* A: A B1 C4 D5 E2 F1 G1
upgrade A C4: A B1 C4 D4 E2 F1 G1
downgrade A2 D2: A2 C4 D2
build A: A B1 C2 D4 E2 F1
upgrade* A: A B1 C4 D5 E2 F1 G1
upgrade A C4: A B1 C4 D4 E2 F1 G1
build A2: A2 B1 C4 D4 E2 F1 G1
downgrade A2 D2: A2 C4 D2 E2 F1 G1
name: trim
A: B1 C2
Expand Down Expand Up @@ -68,7 +69,7 @@ B2: D1
C: D2
D1: E2
D2: E1
build A: A B1 C D2 E1
build A: A B1 C D2 E1
upgrade A B2: A B2 C D2 E2
name: cross1R
Expand Down Expand Up @@ -136,17 +137,17 @@ name: cross5
A: D1
D1: E2
D2: E1
build A: A D1 E2
upgrade* A: A D2 E2
upgrade A D2: A D2 E2
build A: A D1 E2
upgrade* A: A D2 E2
upgrade A D2: A D2 E2
upgradereq A D2: D2 E2
name: cross6
A: D2
D1: E2
D2: E1
build A: A D2 E1
upgrade* A: A D2 E2
build A: A D2 E1
upgrade* A: A D2 E2
upgrade A E2: A D2 E2
name: cross7
Expand Down Expand Up @@ -175,7 +176,7 @@ B1: D1
B2:
C2:
D2:
build A: A B1 C1 D1
build A: A B1 C1 D1
upgrade* A: A B2 C2 D2
name: simplify
Expand All @@ -194,7 +195,7 @@ B4:
B5.hidden:
C2:
C3:
build A: A B1 C1
build A: A B1 C1
upgrade* A: A B4 C3
name: up2
Expand All @@ -206,15 +207,15 @@ B4:
B5.hidden:
C2:
C3:
build A: A B5.hidden C1
build A: A B5.hidden C1
upgrade* A: A B5.hidden C3
name: down1
A: B2
B1: C1
B2: C2
build A: A B2 C2
downgrade A C1: A B1
build A: A B2 C2
downgrade A C1: A B1 C1
name: down2
A: B2 E2
Expand All @@ -227,33 +228,75 @@ D2: B2
E2: D2
E1:
F1:
downgrade A F1: A B1 E1
build A: A B2 C2 D2 E2 F2
downgrade A F1: A B1 C1 D1 E1 F1
# https://research.swtch.com/vgo-mvs#algorithm_4:
# “[D]owngrades are constrained to only downgrade packages, not also upgrade
# them; if an upgrade before downgrade is needed, the user must ask for it
# explicitly.”
#
# Here, downgrading B2 to B1 upgrades C1 to C2, and C2 does not depend on D2.
# However, C2 would be an upgrade — not a downgrade — so B1 must also be
# rejected.
name: downcross1
A: B2 C1
B1: C2
B2: C1
C1: D2
C2:
D1:
D2:
build A: A B2 C1 D2
downgrade A D1: A D1
# https://research.swtch.com/vgo-mvs#algorithm_4:
# “Unlike upgrades, downgrades must work by removing requirements, not adding
# them.”
#
# However, downgrading a requirement may introduce a new requirement on a
# previously-unrequired module. If each dependency's requirements are complete
# (“tidy”), that can't change the behavior of any other package whose version is
# not also being downgraded, so we should allow it.
name: downcross2
A: B2
B1: C1
B2: D2
C1:
D1:
D2:
build A: A B2 D2
downgrade A D1: A B1 C1 D1
name: downcycle
A: A B2
B2: A
B1:
build A: A B2
downgrade A B1: A B1
# golang.org/issue/25542.
name: noprev1
A: B4 C2
B2.hidden:
C2:
build A: A B4 C2
downgrade A B2.hidden: A B2.hidden C2
name: noprev2
A: B4 C2
B2.hidden:
B1:
C2:
build A: A B4 C2
downgrade A B2.hidden: A B2.hidden C2
name: noprev3
A: B4 C2
B3:
B2.hidden:
C2:
build A: A B4 C2
downgrade A B2.hidden: A B2.hidden C2
# Cycles involving the target.
Expand All @@ -264,9 +307,9 @@ A: B1
B1: A1
B2: A2
B3: A3
build A: A B1
build A: A B1
upgrade A B2: A B2
upgrade* A: A B3
upgrade* A: A B3
# golang.org/issue/29773:
# Requirements of older versions of the target
Expand All @@ -280,7 +323,7 @@ B2: A2
C1: A2
C2:
D2:
build A: A B1 C1 D1
build A: A B1 C1 D1
upgrade* A: A B2 C2 D2
# Cycles with multiple possible solutions.
Expand All @@ -293,23 +336,23 @@ B2: C2
C1:
C2: B2
build M: M A1 B2 C2
req M: A1 B2
req M A: A1 B2
req M C: A1 C2
req M: A1 B2
req M A: A1 B2
req M C: A1 C2
# Requirement minimization.
name: req1
A: B1 C1 D1 E1 F1
B1: C1 E1 F1
req A: B1 D1
req A: B1 D1
req A C: B1 C1 D1
name: req2
A: G1 H1
G1: H1
H1: G1
req A: G1
req A: G1
req A G: G1
req A H: H1
Expand All @@ -326,7 +369,20 @@ M: Anone B1 D1 E1
B1: Cnone D1
E1: Fnone
build M: M B1 D1 E1
req M: B1 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) {
Expand Down
Loading

0 comments on commit e7493a9

Please sign in to comment.