mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/go/internal/modload: only check root-promotion during tidy for lazy modules
In a lazy module, it is important that tidyRoots does not add any new roots because the dependencies of non-roots are pruned out. In an eager module, that property is not important (and does not hold in general) because no dependencies are ever pruned out. Fixes #45952 Change-Id: I5c95b5696b7112b9219e38af04e0dece7fb6e202 Reviewed-on: https://go-review.googlesource.com/c/go/+/316754 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>
This commit is contained in:
parent
6a6aa32783
commit
62a87f64b9
2 changed files with 29 additions and 9 deletions
|
|
@ -1065,15 +1065,19 @@ func loadFromRoots(ctx context.Context, params loaderParams) *loader {
|
||||||
ld.errorf("go: %v\n", err)
|
ld.errorf("go: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ld.requirements.depth == lazy {
|
||||||
// We continuously add tidy roots to ld.requirements during loading, so at
|
// We continuously add tidy roots to ld.requirements during loading, so at
|
||||||
// this point the tidy roots should be a subset of the roots of
|
// this point the tidy roots should be a subset of the roots of
|
||||||
// ld.requirements. If not, there is a bug in the loading loop above.
|
// ld.requirements, ensuring that no new dependencies are brought inside
|
||||||
|
// the lazy-loading horizon.
|
||||||
|
// If that is not the case, there is a bug in the loading loop above.
|
||||||
for _, m := range rs.rootModules {
|
for _, m := range rs.rootModules {
|
||||||
if v, ok := ld.requirements.rootSelected(m.Path); !ok || v != m.Version {
|
if v, ok := ld.requirements.rootSelected(m.Path); !ok || v != m.Version {
|
||||||
ld.errorf("go: internal error: a requirement on %v is needed but was not added during package loading\n", m)
|
ld.errorf("go: internal error: a requirement on %v is needed but was not added during package loading\n", m)
|
||||||
base.ExitIfErrors()
|
base.ExitIfErrors()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
ld.requirements = rs
|
ld.requirements = rs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
20
src/cmd/go/testdata/script/mod_tidy_newroot.txt
vendored
20
src/cmd/go/testdata/script/mod_tidy_newroot.txt
vendored
|
|
@ -12,8 +12,8 @@
|
||||||
# dependency (or else no new root would be needed). An additional package D
|
# dependency (or else no new root would be needed). An additional package D
|
||||||
# in its own module satisfies that condition, reproducing the bug.
|
# in its own module satisfies that condition, reproducing the bug.
|
||||||
|
|
||||||
! go mod tidy
|
go mod tidy
|
||||||
stderr 'internal error'
|
cmp go.mod go.mod.tidy
|
||||||
|
|
||||||
-- go.mod --
|
-- go.mod --
|
||||||
module example.net/a
|
module example.net/a
|
||||||
|
|
@ -25,6 +25,22 @@ require (
|
||||||
example.net/d v0.1.0
|
example.net/d v0.1.0
|
||||||
)
|
)
|
||||||
|
|
||||||
|
replace (
|
||||||
|
example.net/b v0.1.0 => ./b
|
||||||
|
example.net/c v0.1.0 => ./c
|
||||||
|
example.net/c v0.2.0 => ./c
|
||||||
|
example.net/d v0.1.0 => ./d
|
||||||
|
)
|
||||||
|
-- go.mod.tidy --
|
||||||
|
module example.net/a
|
||||||
|
|
||||||
|
go 1.16
|
||||||
|
|
||||||
|
require (
|
||||||
|
example.net/c v0.2.0 // indirect
|
||||||
|
example.net/d v0.1.0
|
||||||
|
)
|
||||||
|
|
||||||
replace (
|
replace (
|
||||||
example.net/b v0.1.0 => ./b
|
example.net/b v0.1.0 => ./b
|
||||||
example.net/c v0.1.0 => ./c
|
example.net/c v0.1.0 => ./c
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue