@@ -49,7 +49,6 @@ const (
49
49
NeedImports
50
50
51
51
// NeedDeps adds the fields requested by the LoadMode in the packages in Imports.
52
- // If NeedImports is not set, it will be added automatically.
53
52
NeedDeps
54
53
55
54
// NeedExportsFile adds ExportsFile.
@@ -61,7 +60,7 @@ const (
61
60
// NeedSyntax adds Syntax.
62
61
NeedSyntax
63
62
64
- // NeedTypesInfo adds TypesInfo. If NeedImports is not set, it will be added automatically.
63
+ // NeedTypesInfo adds TypesInfo.
65
64
NeedTypesInfo
66
65
67
66
// NeedTypesSizes adds TypesSizes.
@@ -416,11 +415,13 @@ type loader struct {
416
415
parseCacheMu sync.Mutex
417
416
exportMu sync.Mutex // enforces mutual exclusion of exportdata operations
418
417
419
- // TODO(matloob): Add an implied mode here and use that instead of mode.
420
- // Implied mode would contain all the fields we need the data for so we can
421
- // get the actually requested fields. We'll zero them out before returning
422
- // packages to the user. This will make it easier for us to get the conditions
423
- // where we need certain modes right.
418
+ // Config.Mode contains the implied mode (see implyLoadMode).
419
+ // Implied mode contains all the fields we need the data for.
420
+ // In requestedMode there are the actually requested fields.
421
+ // We'll zero them out before returning packages to the user.
422
+ // This makes it easier for us to get the conditions where
423
+ // we need certain modes right.
424
+ requestedMode LoadMode
424
425
}
425
426
426
427
type parseValue struct {
@@ -477,7 +478,9 @@ func newLoader(cfg *Config) *loader {
477
478
}
478
479
}
479
480
480
- ld .addDependingLoadModes ()
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 ()
481
484
return ld
482
485
}
483
486
@@ -625,35 +628,35 @@ func (ld *loader) refine(roots []string, list ...*Package) ([]*Package, error) {
625
628
}
626
629
for i := range ld .pkgs {
627
630
// Clear all unrequested fields, for extra de-Hyrum-ization.
628
- if ld .Mode & NeedName == 0 {
631
+ if ld .requestedMode & NeedName == 0 {
629
632
ld .pkgs [i ].Name = ""
630
633
ld .pkgs [i ].PkgPath = ""
631
634
}
632
- if ld .Mode & NeedFiles == 0 {
635
+ if ld .requestedMode & NeedFiles == 0 {
633
636
ld .pkgs [i ].GoFiles = nil
634
637
ld .pkgs [i ].OtherFiles = nil
635
638
}
636
- if ld .Mode & NeedCompiledGoFiles == 0 {
639
+ if ld .requestedMode & NeedCompiledGoFiles == 0 {
637
640
ld .pkgs [i ].CompiledGoFiles = nil
638
641
}
639
- if ld .Mode & NeedImports == 0 {
642
+ if ld .requestedMode & NeedImports == 0 {
640
643
ld .pkgs [i ].Imports = nil
641
644
}
642
- if ld .Mode & NeedExportsFile == 0 {
645
+ if ld .requestedMode & NeedExportsFile == 0 {
643
646
ld .pkgs [i ].ExportFile = ""
644
647
}
645
- if ld .Mode & NeedTypes == 0 {
648
+ if ld .requestedMode & NeedTypes == 0 {
646
649
ld .pkgs [i ].Types = nil
647
650
ld .pkgs [i ].Fset = nil
648
651
ld .pkgs [i ].IllTyped = false
649
652
}
650
- if ld .Mode & NeedSyntax == 0 {
653
+ if ld .requestedMode & NeedSyntax == 0 {
651
654
ld .pkgs [i ].Syntax = nil
652
655
}
653
- if ld .Mode & NeedTypesInfo == 0 {
656
+ if ld .requestedMode & NeedTypesInfo == 0 {
654
657
ld .pkgs [i ].TypesInfo = nil
655
658
}
656
- if ld .Mode & NeedTypesSizes == 0 {
659
+ if ld .requestedMode & NeedTypesSizes == 0 {
657
660
ld .pkgs [i ].TypesSizes = nil
658
661
}
659
662
}
@@ -1077,8 +1080,8 @@ func (ld *loader) loadFromExportData(lpkg *loaderPackage) (*types.Package, error
1077
1080
return tpkg , nil
1078
1081
}
1079
1082
1080
- // addDependingLoadModes adds dependencies for choosed LoadMode in ld.Mode
1081
- func (ld * loader ) addDependingLoadModes () {
1083
+ // implyLoadMode adds dependencies for choosed LoadMode in ld.Mode
1084
+ func (ld * loader ) implyLoadMode () {
1082
1085
if ld .Mode & NeedTypesInfo != 0 && ld .Mode & NeedImports == 0 {
1083
1086
// If NeedTypesInfo, go/packages needs to do typechecking itself so it can
1084
1087
// associate type info with the AST. To do so, we need the export data
0 commit comments