Skip to content

Commit 63b968f

Browse files
author
Bryan C. Mills
committed
doc/go1.17: clarify Modules changes
Writing CL 333629 clarified my thinking about the behavioral changes associated with lazy loading. There are really two interrelated changes — graph pruning, and lazy loading proper — that are both made possible by the added redundancy in the go.mod file. (I had initially approached the whole cluster of features as “lazy loading” because that was the starting point for the design. Graph pruning came into the picture when we looked at how to bound the worst-case behavior of lazy loading, but it is really the more important of the two aspects of the design.) Note that this change adds links to doc anchors added in CL 333629. Fixes #36460 Fixes #47397 Change-Id: I0ef4af57f647bf5ee210ea7099191fb4befa2cc1 Reviewed-on: https://go-review.googlesource.com/c/go/+/335135 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 70546f6 commit 63b968f

File tree

1 file changed

+45
-25
lines changed

1 file changed

+45
-25
lines changed

doc/go1.17.html

+45-25
Original file line numberDiff line numberDiff line change
@@ -134,35 +134,54 @@ <h2 id="tools">Tools</h2>
134134

135135
<h3 id="go-command">Go command</h3>
136136

137-
<h4 id="lazy-loading">Lazy module loading</h4>
137+
<a id="lazy-loading"><!-- for existing links only --></a>
138+
<h4 id="graph-pruning">Pruned module graphs in <code>go 1.17</code> modules</h4>
138139

139140
<p><!-- golang.org/issue/36460 -->
141+
If a module specifies <code>go</code> <code>1.17</code> or higher, the module
142+
graph includes only the <em>immediate</em> dependencies of
143+
other <code>go</code> <code>1.17</code> modules, not their full transitive
144+
dependencies. (See <a href="/ref/mod#graph-pruning">Module graph pruning</a>
145+
for more detail.)
146+
</p>
147+
148+
<p>
149+
For the <code>go</code> command to correctly resolve transitive imports using
150+
the pruned module graph, the <code>go.mod</code> file for each module needs to
151+
include more detail about the transitive dependencies relevant to that module.
140152
If a module specifies <code>go</code> <code>1.17</code> or higher in its
141-
<code>go.mod</code> file, its transitive requirements are now loaded lazily,
142-
avoiding the need to download or read <code>go.mod</code> files for
143-
otherwise-irrelevant dependencies. To support lazy loading, in Go 1.17 modules
144-
the <code>go</code> command maintains <em>explicit</em> requirements in
145-
the <code>go.mod</code> file for every dependency that provides any package
146-
transitively imported by any package or test within the module.
147-
See <a href="https://golang.org/design/36460-lazy-module-loading">the design
148-
document</a> for more detail.
149-
<!-- TODO(bcmills): replace the design-doc link with proper documentation. -->
153+
<code>go.mod</code> file, its <codeg>go.mod</code> file now contains an
154+
explicit <a href="/ref/mod#go-mod-file-require"><code>require</code>
155+
directive</a> for every module that provides a transitively-imported package.
156+
(In previous versions, the <code>go.mod</code> file typically only included
157+
explicit requirements for <em>directly</em>-imported packages.)
158+
<p>
159+
160+
<p>
161+
Since the expanded <code>go.mod</code> file needed for module graph pruning
162+
includes all of the dependencies needed to load the imports of any package in
163+
the main module, if the main module specifies
164+
<code>go</code> <code>1.17</code> or higher the <code>go</code> tool no longer
165+
reads (or even downloads) <code>go.mod</code> files for dependencies if they
166+
are not needed in order to complete the requested command.
167+
(See <a href="/ref/mod#lazy-loading">Lazy loading</a>.)
150168
</p>
151169

152170
<p><!-- golang.org/issue/45965 -->
153-
Because the number of additional explicit requirements in the go.mod file may
154-
be substantial, in a Go 1.17 module the newly-added requirements
155-
on <em>indirect</em> dependencies are maintained in a
156-
separate <code>require</code> block from the block containing direct
157-
dependencies.
171+
Because the number of explicit requirements may be substantially larger in an
172+
expanded Go 1.17 <code>go.mod</code> file, the newly-added requirements
173+
on <em>indirect</em> dependencies in a <code>go</code> <code>1.17</code>
174+
module are maintained in a separate <code>require</code> block from the block
175+
containing direct dependencies.
158176
</p>
159177

160178
<p><!-- golang.org/issue/45094 -->
161-
To facilitate the upgrade to lazy loading, the
162-
<code>go</code> <code>mod</code> <code>tidy</code> subcommand now supports
163-
a <code>-go</code> flag to set or change the <code>go</code> version in
164-
the <code>go.mod</code> file. To enable lazy loading for an existing module
165-
without changing the selected versions of its dependencies, run:
179+
To facilitate the upgrade to Go 1.17 pruned module graphs, the
180+
<a href="/ref/mod#go-mod-tidy"><code>go</code> <code>mod</code> <code>tidy</code></a>
181+
subcommand now supports a <code>-go</code> flag to set or change
182+
the <code>go</code> version in the <code>go.mod</code> file. To convert
183+
the <code>go.mod</code> file for an existing module to Go 1.17 without
184+
changing the selected versions of its dependencies, run:
166185
</p>
167186

168187
<pre>
@@ -199,10 +218,10 @@ <h4 id="lazy-loading">Lazy module loading</h4>
199218
</p>
200219

201220
<p><!-- golang.org/issue/46366 -->
202-
The <code>go</code> <code>mod</code> <code>graph</code> subcommand also
203-
supports the <code>-go</code> flag, which causes it to report the graph as
204-
seen by the indicated Go version, showing dependencies that may otherwise be
205-
pruned out by lazy loading.
221+
The <a href="/ref/mod#go-mod-graph"><code>go</code> <code>mod</code> <code>graph</code></a>
222+
subcommand also supports the <code>-go</code> flag, which causes it to report
223+
the graph as seen by the indicated Go version, showing dependencies that may
224+
otherwise be pruned out.
206225
</p>
207226

208227
<h4 id="module-deprecation-comments">Module deprecation comments</h4>
@@ -270,7 +289,8 @@ <h4 id="vendor"><code>vendor</code> contents</h4>
270289

271290
<p><!-- golang.org/issue/36876 -->
272291
If the main module specifies <code>go</code> <code>1.17</code> or higher,
273-
<code>go</code> <code>mod</code> <code>vendor</code> now annotates
292+
<a href="/ref/mod#go-mod-vendor"><code>go</code> <code>mod</code> <code>vendor</code></a>
293+
now annotates
274294
<code>vendor/modules.txt</code> with the <code>go</code> version indicated by
275295
each vendored module in its own <code>go.mod</code> file. The annotated
276296
version is used when building the module's packages from vendored source code.

0 commit comments

Comments
 (0)