@@ -612,11 +612,11 @@ func ClearPackageCachePartial(args []string) {
612
612
delete (packageCache , arg )
613
613
}
614
614
}
615
- resolvedImportCache .DeleteIf (func (key any ) bool {
616
- return shouldDelete [key .( importSpec ). path ]
615
+ resolvedImportCache .DeleteIf (func (key importSpec ) bool {
616
+ return shouldDelete [key .path ]
617
617
})
618
- packageDataCache .DeleteIf (func (key any ) bool {
619
- return shouldDelete [key .( string ) ]
618
+ packageDataCache .DeleteIf (func (key string ) bool {
619
+ return shouldDelete [key ]
620
620
})
621
621
}
622
622
@@ -628,8 +628,8 @@ func ReloadPackageNoFlags(arg string, stk *ImportStack) *Package {
628
628
p := packageCache [arg ]
629
629
if p != nil {
630
630
delete (packageCache , arg )
631
- resolvedImportCache .DeleteIf (func (key any ) bool {
632
- return key .( importSpec ). path == p .ImportPath
631
+ resolvedImportCache .DeleteIf (func (key importSpec ) bool {
632
+ return key .path == p .ImportPath
633
633
})
634
634
packageDataCache .Delete (p .ImportPath )
635
635
}
@@ -846,7 +846,7 @@ func loadPackageData(ctx context.Context, path, parentPath, parentDir, parentRoo
846
846
parentIsStd : parentIsStd ,
847
847
mode : mode ,
848
848
}
849
- r := resolvedImportCache .Do (importKey , func () any {
849
+ r := resolvedImportCache .Do (importKey , func () resolvedImport {
850
850
var r resolvedImport
851
851
if cfg .ModulesEnabled {
852
852
r .dir , r .path , r .err = modload .Lookup (parentPath , parentIsStd , path )
@@ -866,16 +866,19 @@ func loadPackageData(ctx context.Context, path, parentPath, parentDir, parentRoo
866
866
r .path = path
867
867
}
868
868
return r
869
- }).( resolvedImport )
869
+ })
870
870
// Invariant: r.path is set to the resolved import path. If the path cannot
871
871
// be resolved, r.path is set to path, the source import path.
872
872
// r.path is never empty.
873
873
874
874
// Load the package from its directory. If we already found the package's
875
875
// directory when resolving its import path, use that.
876
- data := packageDataCache .Do (r .path , func () any {
876
+ p , err := packageDataCache .Do (r .path , func () ( * build. Package , error ) {
877
877
loaded = true
878
- var data packageData
878
+ var data struct {
879
+ p * build.Package
880
+ err error
881
+ }
879
882
if r .dir != "" {
880
883
var buildMode build.ImportMode
881
884
buildContext := cfg .BuildContext
@@ -961,10 +964,10 @@ func loadPackageData(ctx context.Context, path, parentPath, parentDir, parentRoo
961
964
! strings .Contains (path , "/vendor/" ) && ! strings .HasPrefix (path , "vendor/" ) {
962
965
data .err = fmt .Errorf ("code in directory %s expects import %q" , data .p .Dir , data .p .ImportComment )
963
966
}
964
- return data
965
- }).( packageData )
967
+ return data . p , data . err
968
+ })
966
969
967
- return data . p , loaded , data . err
970
+ return p , loaded , err
968
971
}
969
972
970
973
// importSpec describes an import declaration in source code. It is used as a
@@ -984,20 +987,11 @@ type resolvedImport struct {
984
987
err error
985
988
}
986
989
987
- // packageData holds information loaded from a package. It is the value type
988
- // in packageDataCache.
989
- type packageData struct {
990
- p * build.Package
991
- err error
992
- }
993
-
994
- // resolvedImportCache maps import strings (importSpec) to canonical package names
995
- // (resolvedImport).
996
- var resolvedImportCache par.Cache
990
+ // resolvedImportCache maps import strings to canonical package names.
991
+ var resolvedImportCache par.Cache [importSpec , resolvedImport ]
997
992
998
- // packageDataCache maps canonical package names (string) to package metadata
999
- // (packageData).
1000
- var packageDataCache par.Cache
993
+ // packageDataCache maps canonical package names (string) to package metadata.
994
+ var packageDataCache par.ErrCache [string , * build.Package ]
1001
995
1002
996
// preloadWorkerCount is the number of concurrent goroutines that can load
1003
997
// packages. Experimentally, there are diminishing returns with more than
@@ -1109,13 +1103,13 @@ func cleanImport(path string) string {
1109
1103
return path
1110
1104
}
1111
1105
1112
- var isDirCache par.Cache
1106
+ var isDirCache par.Cache [ string , bool ]
1113
1107
1114
1108
func isDir (path string ) bool {
1115
- return isDirCache .Do (path , func () any {
1109
+ return isDirCache .Do (path , func () bool {
1116
1110
fi , err := fsys .Stat (path )
1117
1111
return err == nil && fi .IsDir ()
1118
- }).( bool )
1112
+ })
1119
1113
}
1120
1114
1121
1115
// ResolveImportPath returns the true meaning of path when it appears in parent.
@@ -1236,12 +1230,12 @@ func vendoredImportPath(path, parentPath, parentDir, parentRoot string) (found s
1236
1230
1237
1231
var (
1238
1232
modulePrefix = []byte ("\n module " )
1239
- goModPathCache par.Cache
1233
+ goModPathCache par.Cache [ string , string ]
1240
1234
)
1241
1235
1242
1236
// goModPath returns the module path in the go.mod in dir, if any.
1243
1237
func goModPath (dir string ) (path string ) {
1244
- return goModPathCache .Do (dir , func () any {
1238
+ return goModPathCache .Do (dir , func () string {
1245
1239
data , err := os .ReadFile (filepath .Join (dir , "go.mod" ))
1246
1240
if err != nil {
1247
1241
return ""
@@ -1277,7 +1271,7 @@ func goModPath(dir string) (path string) {
1277
1271
path = s
1278
1272
}
1279
1273
return path
1280
- }).( string )
1274
+ })
1281
1275
}
1282
1276
1283
1277
// findVersionElement returns the slice indices of the final version element /vN in path.
@@ -2264,8 +2258,8 @@ func (p *Package) collectDeps() {
2264
2258
}
2265
2259
2266
2260
// vcsStatusCache maps repository directories (string)
2267
- // to their VCS information (vcsStatusError) .
2268
- var vcsStatusCache par.Cache
2261
+ // to their VCS information.
2262
+ var vcsStatusCache par.ErrCache [ string , vcs. Status ]
2269
2263
2270
2264
// setBuildInfo gathers build information, formats it as a string to be
2271
2265
// embedded in the binary, then sets p.Internal.BuildInfo to that string.
@@ -2517,19 +2511,13 @@ func (p *Package) setBuildInfo(autoVCS bool) {
2517
2511
goto omitVCS
2518
2512
}
2519
2513
2520
- type vcsStatusError struct {
2521
- Status vcs.Status
2522
- Err error
2523
- }
2524
- cached := vcsStatusCache .Do (repoDir , func () any {
2525
- st , err := vcsCmd .Status (vcsCmd , repoDir )
2526
- return vcsStatusError {st , err }
2527
- }).(vcsStatusError )
2528
- if err := cached .Err ; err != nil {
2514
+ st , err := vcsStatusCache .Do (repoDir , func () (vcs.Status , error ) {
2515
+ return vcsCmd .Status (vcsCmd , repoDir )
2516
+ })
2517
+ if err != nil {
2529
2518
setVCSError (err )
2530
2519
return
2531
2520
}
2532
- st := cached .Status
2533
2521
2534
2522
appendSetting ("vcs" , vcsCmd .Cmd )
2535
2523
if st .Revision != "" {
0 commit comments