@@ -144,13 +144,7 @@ const (
144
144
// A Config specifies details about how packages should be loaded.
145
145
// The zero value is a valid configuration.
146
146
//
147
- // Calls to Load do not modify this struct.
148
- //
149
- // TODO(adonovan): #67702: this is currently false: in fact,
150
- // calls to [Load] do not modify the public fields of this struct, but
151
- // may modify hidden fields, so concurrent calls to [Load] must not
152
- // use the same Config. But perhaps we should reestablish the
153
- // documented invariant.
147
+ // Calls to [Load] do not modify this struct.
154
148
type Config struct {
155
149
// Mode controls the level of information returned for each package.
156
150
Mode LoadMode
@@ -181,19 +175,10 @@ type Config struct {
181
175
//
182
176
Env []string
183
177
184
- // gocmdRunner guards go command calls from concurrency errors.
185
- gocmdRunner * gocommand.Runner
186
-
187
178
// BuildFlags is a list of command-line flags to be passed through to
188
179
// the build system's query tool.
189
180
BuildFlags []string
190
181
191
- // modFile will be used for -modfile in go command invocations.
192
- modFile string
193
-
194
- // modFlag will be used for -modfile in go command invocations.
195
- modFlag string
196
-
197
182
// Fset provides source position information for syntax trees and types.
198
183
// If Fset is nil, Load will use a new fileset, but preserve Fset's value.
199
184
Fset * token.FileSet
@@ -240,9 +225,13 @@ type Config struct {
240
225
// drivers may vary in their level of support for overlays.
241
226
Overlay map [string ][]byte
242
227
243
- // goListOverlayFile is the JSON file that encodes the Overlay
244
- // mapping, used by 'go list -overlay=...'
245
- goListOverlayFile string
228
+ // -- Hidden configuration fields only for use in x/tools --
229
+
230
+ // modFile will be used for -modfile in go command invocations.
231
+ modFile string
232
+
233
+ // modFlag will be used for -modfile in go command invocations.
234
+ modFlag string
246
235
}
247
236
248
237
// Load loads and returns the Go packages named by the given patterns.
@@ -333,21 +322,24 @@ func defaultDriver(cfg *Config, patterns ...string) (*DriverResponse, bool, erro
333
322
} else if ! response .NotHandled {
334
323
return response , true , nil
335
324
}
336
- // ( fall through)
325
+ // not handled: fall through
337
326
}
338
327
339
328
// go list fallback
340
- //
329
+
341
330
// Write overlays once, as there are many calls
342
331
// to 'go list' (one per chunk plus others too).
343
- overlay , cleanupOverlay , err := gocommand .WriteOverlays (cfg .Overlay )
332
+ overlayFile , cleanupOverlay , err := gocommand .WriteOverlays (cfg .Overlay )
344
333
if err != nil {
345
334
return nil , false , err
346
335
}
347
336
defer cleanupOverlay ()
348
- cfg .goListOverlayFile = overlay
349
337
350
- response , err := callDriverOnChunks (goListDriver , cfg , chunks )
338
+ var runner gocommand.Runner // (shared across many 'go list' calls)
339
+ driver := func (cfg * Config , patterns []string ) (* DriverResponse , error ) {
340
+ return goListDriver (cfg , & runner , overlayFile , patterns )
341
+ }
342
+ response , err := callDriverOnChunks (driver , cfg , chunks )
351
343
if err != nil {
352
344
return nil , false , err
353
345
}
@@ -385,16 +377,14 @@ func splitIntoChunks(patterns []string, argMax int) ([][]string, error) {
385
377
386
378
func callDriverOnChunks (driver driver , cfg * Config , chunks [][]string ) (* DriverResponse , error ) {
387
379
if len (chunks ) == 0 {
388
- return driver (cfg )
380
+ return driver (cfg , nil )
389
381
}
390
382
responses := make ([]* DriverResponse , len (chunks ))
391
383
errNotHandled := errors .New ("driver returned NotHandled" )
392
384
var g errgroup.Group
393
385
for i , chunk := range chunks {
394
- i := i
395
- chunk := chunk
396
386
g .Go (func () (err error ) {
397
- responses [i ], err = driver (cfg , chunk ... )
387
+ responses [i ], err = driver (cfg , chunk )
398
388
if responses [i ] != nil && responses [i ].NotHandled {
399
389
err = errNotHandled
400
390
}
@@ -749,9 +739,6 @@ func newLoader(cfg *Config) *loader {
749
739
if ld .Config .Env == nil {
750
740
ld .Config .Env = os .Environ ()
751
741
}
752
- if ld .Config .gocmdRunner == nil {
753
- ld .Config .gocmdRunner = & gocommand.Runner {}
754
- }
755
742
if ld .Context == nil {
756
743
ld .Context = context .Background ()
757
744
}
0 commit comments