@@ -21,7 +21,7 @@ import (
21
21
// 2. Each module version in tryUpgrade is upgraded toward the indicated
22
22
// version as far as can be done without violating (1).
23
23
//
24
- // 3. Each module version in rs.rootModules (or rs.graph, if rs.depth is eager )
24
+ // 3. Each module version in rs.rootModules (or rs.graph, if rs is unpruned )
25
25
// is downgraded from its original version only to the extent needed to
26
26
// satisfy (1), or upgraded only to the extent needed to satisfy (1) and
27
27
// (2).
@@ -69,10 +69,11 @@ func editRequirements(ctx context.Context, rs *Requirements, tryUpgrade, mustSel
69
69
}
70
70
71
71
var roots []module.Version
72
- if rs .depth == eager {
73
- // In an eager module, modules that provide packages imported by the main
74
- // module may either be explicit roots or implicit transitive dependencies.
75
- // We promote the modules in mustSelect to be explicit requirements.
72
+ if rs .pruning == unpruned {
73
+ // In a module without graph pruning, modules that provide packages imported
74
+ // by the main module may either be explicit roots or implicit transitive
75
+ // dependencies. We promote the modules in mustSelect to be explicit
76
+ // requirements.
76
77
var rootPaths []string
77
78
for _ , m := range mustSelect {
78
79
if ! MainModules .Contains (m .Path ) && m .Version != "none" {
@@ -102,8 +103,8 @@ func editRequirements(ctx context.Context, rs *Requirements, tryUpgrade, mustSel
102
103
return nil , false , err
103
104
}
104
105
} else {
105
- // In a lazy module, every module that provides a package imported by the
106
- // main module must be retained as a root.
106
+ // In a module with a pruned graph , every module that provides a package
107
+ // imported by the main module must be retained as a root.
107
108
roots = mods
108
109
if ! changed {
109
110
// Because the roots we just computed are unchanged, the entire graph must
@@ -126,7 +127,7 @@ func editRequirements(ctx context.Context, rs *Requirements, tryUpgrade, mustSel
126
127
direct [m .Path ] = true
127
128
}
128
129
}
129
- return newRequirements (rs .depth , roots , direct ), changed , nil
130
+ return newRequirements (rs .pruning , roots , direct ), changed , nil
130
131
}
131
132
132
133
// limiterForEdit returns a versionLimiter with its max versions set such that
@@ -149,11 +150,12 @@ func limiterForEdit(ctx context.Context, rs *Requirements, tryUpgrade, mustSelec
149
150
}
150
151
}
151
152
152
- if rs .depth == eager {
153
- // Eager go.mod files don't indicate which transitive dependencies are
154
- // actually relevant to the main module, so we have to assume that any module
155
- // that could have provided any package — that is, any module whose selected
156
- // version was not "none" — may be relevant.
153
+ if rs .pruning == unpruned {
154
+ // go.mod files that do not support graph pruning don't indicate which
155
+ // transitive dependencies are actually relevant to the main module, so we
156
+ // have to assume that any module that could have provided any package —
157
+ // that is, any module whose selected version was not "none" — may be
158
+ // relevant.
157
159
for _ , m := range mg .BuildList () {
158
160
restrictTo (m )
159
161
}
@@ -175,7 +177,7 @@ func limiterForEdit(ctx context.Context, rs *Requirements, tryUpgrade, mustSelec
175
177
}
176
178
}
177
179
178
- if err := raiseLimitsForUpgrades (ctx , maxVersion , rs .depth , tryUpgrade , mustSelect ); err != nil {
180
+ if err := raiseLimitsForUpgrades (ctx , maxVersion , rs .pruning , tryUpgrade , mustSelect ); err != nil {
179
181
return nil , err
180
182
}
181
183
@@ -185,7 +187,7 @@ func limiterForEdit(ctx context.Context, rs *Requirements, tryUpgrade, mustSelec
185
187
restrictTo (m )
186
188
}
187
189
188
- return newVersionLimiter (rs .depth , maxVersion ), nil
190
+ return newVersionLimiter (rs .pruning , maxVersion ), nil
189
191
}
190
192
191
193
// raiseLimitsForUpgrades increases the module versions in maxVersions to the
@@ -195,12 +197,12 @@ func limiterForEdit(ctx context.Context, rs *Requirements, tryUpgrade, mustSelec
195
197
//
196
198
// Versions not present in maxVersion are unrestricted, and it is assumed that
197
199
// they will not be promoted to root requirements (and thus will not contribute
198
- // their own dependencies if the main module is lazy ).
200
+ // their own dependencies if the main module supports graph pruning ).
199
201
//
200
202
// These limits provide an upper bound on how far a module may be upgraded as
201
203
// part of an incidental downgrade, if downgrades are needed in order to select
202
204
// the versions in mustSelect.
203
- func raiseLimitsForUpgrades (ctx context.Context , maxVersion map [string ]string , depth modDepth , tryUpgrade []module.Version , mustSelect []module.Version ) error {
205
+ func raiseLimitsForUpgrades (ctx context.Context , maxVersion map [string ]string , pruning modPruning , tryUpgrade []module.Version , mustSelect []module.Version ) error {
204
206
// allow raises the limit for m.Path to at least m.Version.
205
207
// If m.Path was already unrestricted, it remains unrestricted.
206
208
allow := func (m module.Version ) {
@@ -213,9 +215,9 @@ func raiseLimitsForUpgrades(ctx context.Context, maxVersion map[string]string, d
213
215
}
214
216
}
215
217
216
- var eagerUpgrades []module.Version
217
- if depth == eager {
218
- eagerUpgrades = tryUpgrade
218
+ var unprunedUpgrades []module.Version
219
+ if pruning == unpruned {
220
+ unprunedUpgrades = tryUpgrade
219
221
} else {
220
222
for _ , m := range tryUpgrade {
221
223
if MainModules .Contains (m .Path ) {
@@ -229,11 +231,11 @@ func raiseLimitsForUpgrades(ctx context.Context, maxVersion map[string]string, d
229
231
if err != nil {
230
232
return err
231
233
}
232
- if summary .depth == eager {
233
- // For efficiency, we'll load all of the eager upgrades as one big
234
+ if summary .pruning == unpruned {
235
+ // For efficiency, we'll load all of the unpruned upgrades as one big
234
236
// graph, rather than loading the (potentially-overlapping) subgraph for
235
237
// each upgrade individually.
236
- eagerUpgrades = append (eagerUpgrades , m )
238
+ unprunedUpgrades = append (unprunedUpgrades , m )
237
239
continue
238
240
}
239
241
@@ -244,14 +246,14 @@ func raiseLimitsForUpgrades(ctx context.Context, maxVersion map[string]string, d
244
246
}
245
247
}
246
248
247
- if len (eagerUpgrades ) > 0 {
248
- // Compute the max versions for eager upgrades all together.
249
- // Since these modules are eager , we'll end up scanning all of their
249
+ if len (unprunedUpgrades ) > 0 {
250
+ // Compute the max versions for unpruned upgrades all together.
251
+ // Since these modules are unpruned , we'll end up scanning all of their
250
252
// transitive dependencies no matter which versions end up selected,
251
253
// and since we have a large dependency graph to scan we might get
252
254
// a significant benefit from not revisiting dependencies that are at
253
255
// common versions among multiple upgrades.
254
- upgradeGraph , err := readModGraph (ctx , eager , eagerUpgrades )
256
+ upgradeGraph , err := readModGraph (ctx , unpruned , unprunedUpgrades )
255
257
if err != nil {
256
258
// Compute the requirement path from a module path in tryUpgrade to the
257
259
// error, and the requirement path (if any) from rs.rootModules to the
@@ -268,7 +270,7 @@ func raiseLimitsForUpgrades(ctx context.Context, maxVersion map[string]string, d
268
270
}
269
271
270
272
if len (mustSelect ) > 0 {
271
- mustGraph , err := readModGraph (ctx , depth , mustSelect )
273
+ mustGraph , err := readModGraph (ctx , pruning , mustSelect )
272
274
if err != nil {
273
275
return err
274
276
}
@@ -300,7 +302,7 @@ func selectPotentiallyImportedModules(ctx context.Context, limiter *versionLimit
300
302
}
301
303
302
304
var initial []module.Version
303
- if rs .depth == eager {
305
+ if rs .pruning == unpruned {
304
306
mg , err := rs .Graph (ctx )
305
307
if err != nil {
306
308
return nil , false , err
@@ -327,7 +329,7 @@ func selectPotentiallyImportedModules(ctx context.Context, limiter *versionLimit
327
329
// downgraded module may require a higher (but still allowed) version of
328
330
// another. The lower version may require extraneous dependencies that aren't
329
331
// actually relevant, so we need to compute the actual selected versions.
330
- mg , err := readModGraph (ctx , rs .depth , mods )
332
+ mg , err := readModGraph (ctx , rs .pruning , mods )
331
333
if err != nil {
332
334
return nil , false , err
333
335
}
@@ -349,16 +351,16 @@ func selectPotentiallyImportedModules(ctx context.Context, limiter *versionLimit
349
351
// A versionLimiter tracks the versions that may be selected for each module
350
352
// subject to constraints on the maximum versions of transitive dependencies.
351
353
type versionLimiter struct {
352
- // depth is the depth at which the dependencies of the modules passed to
354
+ // pruning is the pruning at which the dependencies of the modules passed to
353
355
// Select and UpgradeToward are loaded.
354
- depth modDepth
356
+ pruning modPruning
355
357
356
358
// max maps each module path to the maximum version that may be selected for
357
359
// that path.
358
360
//
359
361
// Paths with no entry are unrestricted, and we assume that they will not be
360
362
// promoted to root dependencies (so will not contribute dependencies if the
361
- // main module is lazy ).
363
+ // main module supports graph pruning ).
362
364
max map [string ]string
363
365
364
366
// selected maps each module path to a version of that path (if known) whose
@@ -410,16 +412,16 @@ func (dq dqState) isDisqualified() bool {
410
412
// in the map are unrestricted. The limiter assumes that unrestricted paths will
411
413
// not be promoted to root dependencies.
412
414
//
413
- // If depth is lazy , then if a module passed to UpgradeToward or Select is
414
- // itself lazy , its unrestricted dependencies are skipped when scanning
415
- // requirements.
416
- func newVersionLimiter (depth modDepth , max map [string ]string ) * versionLimiter {
415
+ // If module graph pruning is in effect , then if a module passed to
416
+ // UpgradeToward or Select supports pruning , its unrestricted dependencies are
417
+ // skipped when scanning requirements.
418
+ func newVersionLimiter (pruning modPruning , max map [string ]string ) * versionLimiter {
417
419
selected := make (map [string ]string )
418
420
for _ , m := range MainModules .Versions () {
419
421
selected [m .Path ] = m .Version
420
422
}
421
423
return & versionLimiter {
422
- depth : depth ,
424
+ pruning : pruning ,
423
425
max : max ,
424
426
selected : selected ,
425
427
dqReason : map [module.Version ]dqState {},
@@ -430,8 +432,8 @@ func newVersionLimiter(depth modDepth, max map[string]string) *versionLimiter {
430
432
// UpgradeToward attempts to upgrade the selected version of m.Path as close as
431
433
// possible to m.Version without violating l's maximum version limits.
432
434
//
433
- // If depth is lazy and m itself is lazy , the the dependencies of unrestricted
434
- // dependencies of m will not be followed.
435
+ // If module graph pruning is in effect and m itself supports pruning , the
436
+ // dependencies of unrestricted dependencies of m will not be followed.
435
437
func (l * versionLimiter ) UpgradeToward (ctx context.Context , m module.Version ) error {
436
438
selected , ok := l .selected [m .Path ]
437
439
if ok {
@@ -443,7 +445,7 @@ func (l *versionLimiter) UpgradeToward(ctx context.Context, m module.Version) er
443
445
selected = "none"
444
446
}
445
447
446
- if l .check (m , l .depth ).isDisqualified () {
448
+ if l .check (m , l .pruning ).isDisqualified () {
447
449
candidates , err := versions (ctx , m .Path , CheckAllowed )
448
450
if err != nil {
449
451
// This is likely a transient error reaching the repository,
@@ -460,7 +462,7 @@ func (l *versionLimiter) UpgradeToward(ctx context.Context, m module.Version) er
460
462
})
461
463
candidates = candidates [:i ]
462
464
463
- for l .check (m , l .depth ).isDisqualified () {
465
+ for l .check (m , l .pruning ).isDisqualified () {
464
466
n := len (candidates )
465
467
if n == 0 || cmpVersion (selected , candidates [n - 1 ]) >= 0 {
466
468
// We couldn't find a suitable candidate above the already-selected version.
@@ -477,7 +479,7 @@ func (l *versionLimiter) UpgradeToward(ctx context.Context, m module.Version) er
477
479
478
480
// Select attempts to set the selected version of m.Path to exactly m.Version.
479
481
func (l * versionLimiter ) Select (m module.Version ) (conflict module.Version , err error ) {
480
- dq := l .check (m , l .depth )
482
+ dq := l .check (m , l .pruning )
481
483
if ! dq .isDisqualified () {
482
484
l .selected [m .Path ] = m .Version
483
485
}
@@ -487,14 +489,14 @@ func (l *versionLimiter) Select(m module.Version) (conflict module.Version, err
487
489
// check determines whether m (or its transitive dependencies) would violate l's
488
490
// maximum version limits if added to the module requirement graph.
489
491
//
490
- // If depth is lazy and m itself is lazy, then the dependencies of unrestricted
491
- // dependencies of m will not be followed. If the lazy loading invariants hold
492
- // for the main module up to this point, the packages in those modules are at
493
- // best only imported by tests of dependencies that are themselves loaded from
494
- // outside modules. Although we would like to keep 'go test all' as reproducible
495
- // as is feasible, we don't want to retain test dependencies that are only
496
- // marginally relevant at best.
497
- func (l * versionLimiter ) check (m module.Version , depth modDepth ) dqState {
492
+ // If pruning is in effect and m itself supports graph pruning, the dependencies
493
+ // of unrestricted dependencies of m will not be followed. If the graph-pruning
494
+ // invariants hold for the main module up to this point, the packages in those
495
+ // modules are at best only imported by tests of dependencies that are
496
+ // themselves loaded from outside modules. Although we would like to keep
497
+ // 'go test all' as reproducible as is feasible, we don't want to retain test
498
+ // dependencies that are only marginally relevant at best.
499
+ func (l * versionLimiter ) check (m module.Version , pruning modPruning ) dqState {
498
500
if m .Version == "none" || m == MainModules .mustGetSingleMainModule () {
499
501
// version "none" has no requirements, and the dependencies of Target are
500
502
// tautological.
@@ -525,20 +527,20 @@ func (l *versionLimiter) check(m module.Version, depth modDepth) dqState {
525
527
return l .disqualify (m , dqState {err : err })
526
528
}
527
529
528
- if summary .depth == eager {
529
- depth = eager
530
+ if summary .pruning == unpruned {
531
+ pruning = unpruned
530
532
}
531
533
for _ , r := range summary .require {
532
- if depth == lazy {
534
+ if pruning == pruned {
533
535
if _ , restricted := l .max [r .Path ]; ! restricted {
534
536
// r.Path is unrestricted, so we don't care at what version it is
535
537
// selected. We assume that r.Path will not become a root dependency, so
536
- // since m is lazy , r's dependencies won't be followed.
538
+ // since m supports pruning , r's dependencies won't be followed.
537
539
continue
538
540
}
539
541
}
540
542
541
- if dq := l .check (r , depth ); dq .isDisqualified () {
543
+ if dq := l .check (r , pruning ); dq .isDisqualified () {
542
544
return l .disqualify (m , dq )
543
545
}
544
546
0 commit comments