Skip to content

Commit 06ce489

Browse files
author
Bryan C. Mills
committed
_content/ref/mod: update terminology for Go 1.17 changes
For golang/go#47397 Change-Id: I7046bddb17bdd7957603e16580e7c9bab4a8c05a Reviewed-on: https://go-review.googlesource.com/c/website/+/339991 Trust: Bryan C. Mills <[email protected]> Run-TryBot: Bryan C. Mills <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Jay Conrod <[email protected]>
1 parent 0c3ebd1 commit 06ce489

File tree

2 files changed

+73
-73
lines changed

2 files changed

+73
-73
lines changed

_content/doc/modules/gomod-ref.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,9 @@ specified by the `go` directive. This has the following effects:
183183
package transitively imported by a package or test in the main module. (At
184184
`go 1.16` and lower, an indirect dependency is included only if [minimal
185185
version selection](/ref/mod#minimal-version-selection) would otherwise
186-
select a different version.) This extra information enables [lazy
187-
loading](/ref/mod#lazy-loading) and [module graph
188-
pruning](/ref/mod#graph-pruning).
186+
select a different version.) This extra information enables [module graph
187+
pruning](/ref/mod#graph-pruning) and [lazy module
188+
loading](/ref/mod#lazy-loading).
189189
* Because there may be many more `// indirect` dependencies than in previous
190190
`go` versions, indirect dependencies are recorded in a separate block
191191
within the `go.mod` file.

_content/ref/mod.md

Lines changed: 70 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,8 @@ specified by the `go` directive. This has the following effects:
571571
1.16` and lower, an [indirect dependency](#glos-direct-dependency) is
572572
included only if [minimal version selection](#minimal-version-selection)
573573
would otherwise select a different version.) This extra information enables
574-
[lazy loading](#lazy-loading) and [module graph pruning](#graph-pruning).
574+
[module graph pruning](#graph-pruning) and [lazy module
575+
loading](#lazy-loading).
575576
* Because there may be many more `// indirect` dependencies than in previous
576577
`go` versions, indirect dependencies are recorded in a separate block
577578
within the `go.mod` file.
@@ -580,7 +581,7 @@ specified by the `go` directive. This has the following effects:
580581
subdirectories of `vendor` to identify the correct main module.)
581582
* `go mod vendor` records the `go` version from each dependency's `go.mod`
582583
file in `vendor/modules.txt`.
583-
<!-- If you update this list, also update /doc/modules/gomod-ref#go. -->
584+
<!-- If you update this list, also update /doc/modules/gomod-ref#go-notes. -->
584585

585586
A `go.mod` file may contain at most one `go` directive. Most commands will add a
586587
`go` directive with the current Go version if one is not present.
@@ -620,9 +621,11 @@ requirement in its own `go.mod` file (such as a dependency that lacks a `go.mod`
620621
file altogether).
621622

622623
At `go 1.17` and above, the `go` command adds an indirect requirement for each
623-
module that provides a package transitively imported by any package or test in
624-
the main module. These extra requirements enable [lazy loading](#lazy-loading)
625-
and [module graph pruning](#graph-pruning).
624+
module that provides any package imported (even
625+
[indirectly](#glos-indirect-dependency)) by a package or test in the main module
626+
or passed as an argument to `go get`. These more comprehensive requirements
627+
enable [module graph pruning](#graph-pruning) and [lazy module
628+
loading](#lazy-loading).
626629

627630
```
628631
RequireDirective = "require" ( RequireSpec | "(" newline { RequireSpec } ")" newline ) .
@@ -835,6 +838,8 @@ For example, consider this `go.mod` file:
835838
```
836839
module example.com/M
837840
841+
go 1.16
842+
838843
require (
839844
example.com/A v1
840845
example.com/B v1.0.0
@@ -989,62 +994,25 @@ is changed to 1.1.
989994
suffix after an argument. This works similarly to a downgrade. All versions
990995
of the named module are removed from the module graph.
991996

992-
## Module graph redundancy {#graph-redundancy}
993-
994-
In a module with a [`go` directive](#go-mod-file-go) at `go 1.17` or higher, the
995-
`go.mod` file is expected to include an explicit [`require`
996-
directive](#go-mod-file-require) to the `go.mod` file for the [selected
997-
version](#glos-selected-version) of every module that provides any package
998-
imported (even [indirectly](#glos-indirect-dependency)) by a package or test in
999-
the [main module](#glos-main-module).
1000-
1001-
When the `go` command loads packages it makes a best effort to check and
1002-
maintain this property: [`go mod tidy`](#go-mod-tidy) adds indirect requirements
1003-
for all packages imported by the main module, and [`go get`](#go-get) adds
1004-
indirect requirements for the packages imported by those named on the command
1005-
line.
1006-
1007-
A module that _does not_ provide any imported package cannot affect the compiled
1008-
artifacts produced by `go build` and `go test`, so this added redundancy allows
1009-
packages in the main module to be built and tested using only the requirements
1010-
listed in the its own `go.mod` file. The `go` command takes advantage of that
1011-
property to substantially reduce the size of the overall module graph.
1012-
1013-
(At `go 1.16` and below, the `go.mod` file includes only [direct
1014-
dependencies](#glos-direct-dependency), so a much larger graph must be loaded to
1015-
ensure that all indirect dependencies are included.)
1016-
1017-
See [the design document](/design/36460-lazy-module-loading) for more detail.
1018-
1019-
### Lazy loading {#lazy-loading}
1020-
1021-
If the main module is at `go 1.17` or higher, the `go` command avoids loading
1022-
the complete module graph until (and unless) it is needed. Instead, it loads
1023-
only the main module's `go.mod` file, then attempts to load the packages to be
1024-
built using only those requirements. If a package to be imported (for example, a
1025-
dependency of a test for a package outside the main module) is not found among
1026-
those requirements, then the rest of the module graph is loaded on demand.
1027-
1028-
If all packages can be found without loading the full module graph, the `go`
1029-
command then loads the `go.mod` files for _only_ the modules containing those
1030-
packages, and their requirements are checked against the requirements of the
1031-
main module to ensure that they are locally consistent. (Inconsistencies can
1032-
arise due to version-control merges, hand-edits, and changes in modules that
1033-
have been [replaced](#go-mod-file-replace) using local filesystem paths.)
1034-
1035-
### Module graph pruning {#graph-pruning}
997+
## Module graph pruning {#graph-pruning}
1036998

1037999
If the main module is at `go 1.17` or higher, the [module
10381000
graph](#glos-module-graph) used for [minimal version
1039-
selection](#minimal-version-selection) includes only the _immediate_ (not
1040-
transitive) requirements for each module dependency that specifies `go 1.17` or
1041-
higher in its own `go.mod` file, unless that version of the module is also
1042-
(transitively) required by some _other_ dependency at `go 1.16` or below.
1043-
1044-
Since a `go 1.17` `go.mod` file includes every dependency needed to build any
1045-
package or test in that module, the pruned module graph includes every
1046-
dependency needed to `go build` or `go test` the packages in every dependency
1047-
explicitly [required](#go-mod-file-require) by the main module.
1001+
selection](#minimal-version-selection) includes only the _immediate_
1002+
requirements for each module dependency that specifies `go 1.17` or higher in
1003+
its own `go.mod` file, unless that version of the module is also (transitively)
1004+
required by some _other_ dependency at `go 1.16` or below. (The _transitive_
1005+
dependencies of `go 1.17` dependencies are _pruned out_ of the module graph.)
1006+
1007+
Since a `go 1.17` `go.mod` file includes a [require
1008+
directive](#go-mod-file-require) for every dependency needed to build any
1009+
package or test in that module, the pruned module graph includes all of the
1010+
dependencies needed to `go build` or `go test` the packages in any dependency
1011+
explicitly required by the [main module](#glos-main-module). A module that is
1012+
_not_ needed to build any package or test in a given module cannot affect the
1013+
run-time behavior of its packages, so the dependencies that are pruned out of
1014+
the module graph would only cause interference between otherwise-unrelated
1015+
modules.
10481016

10491017
Modules whose requirements have been pruned out still appear in the module graph
10501018
and are still reported by `go list -m all`: their [selected
@@ -1058,10 +1026,11 @@ named package to an explicit dependency, allowing `go build` or `go test` to be
10581026
invoked on that package.
10591027

10601028
Because Go 1.16 and earlier did not support module graph pruning, the full
1061-
transitive closure of dependencies — including transitive `go 1.17` dependencies
1062-
— is still included for each module that specifies `go 1.16` or lower. (The
1063-
`go.mod` file for a `go 1.16` or lower module does not necessarily include the
1064-
requirements needed to build the packages and tests in that module.)
1029+
transitive closure of dependencies — including transitive `go 1.17`
1030+
dependencies — is still included for each module that specifies `go 1.16` or
1031+
lower. (At `go 1.16` and below, the `go.mod` file includes only
1032+
[direct dependencies](#glos-direct-dependency), so a much larger graph must be
1033+
loaded to ensure that all indirect dependencies are included.)
10651034

10661035
The [`go.sum` file](#go-sum-files) recorded by [`go mod tidy`](#go-mod-tidy) for
10671036
a module by default includes checksums needed by the Go version _one below_ the
@@ -1072,6 +1041,26 @@ module graph loaded by Go 1.17. The `-compat` flag can be used to override the
10721041
default version (for example, to prune the `go.sum` file more aggressively in a
10731042
`go 1.17` module).
10741043

1044+
See [the design document](/design/36460-lazy-module-loading) for more detail.
1045+
1046+
### Lazy module loading {#lazy-loading}
1047+
1048+
The more comprehensive requirements added for module graph pruning also enable
1049+
another optimization when working within a module. If the main module is at
1050+
`go 1.17` or higher, the `go` command avoids loading the complete module graph
1051+
until (and unless) it is needed. Instead, it loads only the main module's
1052+
`go.mod` file, then attempts to load the packages to be built using only those
1053+
requirements. If a package to be imported (for example, a dependency of a test
1054+
for a package outside the main module) is not found among those requirements,
1055+
then the rest of the module graph is loaded on demand.
1056+
1057+
If all imported packages can be found without loading the module graph, the
1058+
`go` command then loads the `go.mod` files for _only_ the modules containing
1059+
those packages, and their requirements are checked against the requirements of
1060+
the main module to ensure that they are locally consistent. (Inconsistencies can
1061+
arise due to version-control merges, hand-edits, and changes in modules that
1062+
have been [replaced](#go-mod-file-replace) using local filesystem paths.)
1063+
10751064
## Compatibility with non-module repositories {#non-module-compat}
10761065

10771066
To ensure a smooth transition from `GOPATH` to modules, the `go` command can
@@ -1927,12 +1916,12 @@ imported by other packages.
19271916

19281917
Once `go mod tidy` has loaded this set of packages, it ensures that each module
19291918
that provides one or more packages has a `require` directive in the main
1930-
module's `go.mod` file or, if the main module is at `go 1.16` or below (see
1931-
[Module graph redundancy](#graph-redundancy)), is required by another required
1932-
module. `go mod tidy` will add a requirement on the latest version on each
1933-
missing module (see [Version queries](#version-queries) for the definition of
1934-
the `latest` version). `go mod tidy` will remove `require` directives for
1935-
modules that don't provide any packages in the set described above.
1919+
module's `go.mod` file orif the main module is at `go 1.16` or below — is
1920+
required by another required module. `go mod tidy` will add a requirement on the
1921+
latest version of each missing module (see [Version queries](#version-queries)
1922+
for the definition of the `latest` version). `go mod tidy` will remove `require`
1923+
directives for modules that don't provide any packages in the set described
1924+
above.
19361925

19371926
`go mod tidy` may also add or remove `// indirect` comments on `require`
19381927
directives. An `// indirect` comment denotes a module that does not provide a
@@ -1942,8 +1931,9 @@ dependencies and comments are added.)
19421931

19431932
If the `-go` flag is set, `go mod tidy` will update the [`go`
19441933
directive](#go-mod-file-go) to the indicated version, enabling or disabling
1945-
[lazy loading](#lazy-loading) and [module graph pruning](#graph-pruning) (and
1946-
adding or removing indirect requirements as needed) according to that version.
1934+
[module graph pruning](#graph-pruning) and [lazy module loading](#lazy-loading)
1935+
(and adding or removing indirect requirements as needed) according to that
1936+
version.
19471937

19481938
By default, `go mod tidy` will check that the [selected
19491939
versions](#glos-selected-version) of modules do not change when the module graph
@@ -4062,6 +4052,11 @@ or a module that appears in the [module graph](#glos-module-graph) but does not
40624052
provide any package directly imported by the main module.
40634053
(Compare [direct dependency](#glos-direct-dependency).)
40644054

4055+
<a id="glos-lazy-module-loading"></a>
4056+
**lazy module loading:** A change in Go 1.17 that avoids loading the [module
4057+
graph](#glos-module-graph) for commands that do not need it in modules that
4058+
specify `go 1.17` or higher. See [Lazy module loading](#lazy-loading).
4059+
40654060
<a id="glos-main-module"></a>
40664061
**main module:** The module in which the `go` command is invoked. The main
40674062
module is defined by a [`go.mod` file](#glos-go-mod-file) in the current
@@ -4113,6 +4108,11 @@ module](#glos-main-module). Each vertex in the graph is a module; each edge is a
41134108
version from a `require` statement in a `go.mod` file (subject to `replace` and
41144109
`exclude` statements in the main module's `go.mod` file.
41154110

4111+
<a id="glos-module-graph-pruning"></a>
4112+
**module graph pruning:** A change in Go 1.17 that reduces the size of the
4113+
module graph by omitting transitive dependencies of modules that specify `go
4114+
1.17` or higher. See [Module graph pruning](#graph-pruning).
4115+
41164116
<a id="glos-module-path"></a>
41174117
**module path:** A path that identifies a module and acts as a prefix for
41184118
package import paths within the module. For example, `"golang.org/x/net"`.

0 commit comments

Comments
 (0)