Skip to content

Commit 2e3a46e

Browse files
committed
go/packages: make impliedLoadMode function
1 parent 3540c02 commit 2e3a46e

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

go/packages/packages.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ type loader struct {
415415
parseCacheMu sync.Mutex
416416
exportMu sync.Mutex // enforces mutual exclusion of exportdata operations
417417

418-
// Config.Mode contains the implied mode (see implyLoadMode).
418+
// Config.Mode contains the implied mode (see impliedLoadMode).
419419
// Implied mode contains all the fields we need the data for.
420420
// In requestedMode there are the actually requested fields.
421421
// We'll zero them out before returning packages to the user.
@@ -463,6 +463,10 @@ func newLoader(cfg *Config) *loader {
463463
}
464464
}
465465

466+
// Save the actually requested fields. We'll zero them out before returning packages to the user.
467+
ld.requestedMode = ld.Mode
468+
ld.Mode = impliedLoadMode(ld.Mode)
469+
466470
if ld.Mode&NeedTypes != 0 {
467471
if ld.Fset == nil {
468472
ld.Fset = token.NewFileSet()
@@ -478,9 +482,6 @@ func newLoader(cfg *Config) *loader {
478482
}
479483
}
480484

481-
// Save the actually requested fields. We'll zero them out before returning packages to the user.
482-
ld.requestedMode = ld.Mode
483-
ld.implyLoadMode()
484485
return ld
485486
}
486487

@@ -1080,23 +1081,23 @@ func (ld *loader) loadFromExportData(lpkg *loaderPackage) (*types.Package, error
10801081
return tpkg, nil
10811082
}
10821083

1083-
// implyLoadMode adds dependencies for choosed LoadMode in ld.Mode
1084-
func (ld *loader) implyLoadMode() {
1085-
if ld.Mode&NeedTypesInfo != 0 && ld.Mode&NeedImports == 0 {
1084+
// impliedLoadMode returns loadMode with it's dependencies
1085+
func impliedLoadMode(loadMode LoadMode) LoadMode {
1086+
if loadMode&NeedTypesInfo != 0 && loadMode&NeedImports == 0 {
10861087
// If NeedTypesInfo, go/packages needs to do typechecking itself so it can
10871088
// associate type info with the AST. To do so, we need the export data
10881089
// for dependencies, which means we need to ask for the direct dependencies.
10891090
// NeedImports is used to ask for the direct dependencies.
1090-
ld.Mode |= NeedImports
1091-
ld.Logf("Added load mode dependency of NeedTypesInfo: NeedImports")
1091+
loadMode |= NeedImports
10921092
}
10931093

1094-
if ld.Mode&NeedDeps != 0 && ld.Mode&NeedImports == 0 {
1094+
if loadMode&NeedDeps != 0 && loadMode&NeedImports == 0 {
10951095
// With NeedDeps we need to load at least direct dependencies.
10961096
// NeedImports is used to ask for the direct dependencies.
1097-
ld.Mode |= NeedImports
1098-
ld.Logf("Added load mode dependency of NeedDeps: NeedImports")
1097+
loadMode |= NeedImports
10991098
}
1099+
1100+
return loadMode
11001101
}
11011102

11021103
func usesExportData(cfg *Config) bool {

0 commit comments

Comments
 (0)