@@ -4,16 +4,13 @@ import (
4
4
"errors"
5
5
"fmt"
6
6
"go/types"
7
- "io"
8
7
"reflect"
9
8
"runtime/debug"
10
9
"time"
11
10
12
11
"golang.org/x/tools/go/analysis"
13
12
"golang.org/x/tools/go/packages"
14
- "golang.org/x/tools/go/types/objectpath"
15
13
16
- "github.com/golangci/golangci-lint/internal/cache"
17
14
"github.com/golangci/golangci-lint/internal/errorutil"
18
15
"github.com/golangci/golangci-lint/pkg/goanalysis/pkgerrors"
19
16
)
@@ -66,27 +63,6 @@ func (act *action) String() string {
66
63
return fmt .Sprintf ("%s@%s" , act .a , act .pkg )
67
64
}
68
65
69
- func (act * action ) loadCachedFacts () bool {
70
- if act .loadCachedFactsDone { // can't be set in parallel
71
- return act .loadCachedFactsOk
72
- }
73
-
74
- res := func () bool {
75
- if act .isInitialPkg {
76
- return true // load cached facts only for non-initial packages
77
- }
78
-
79
- if len (act .a .FactTypes ) == 0 {
80
- return true // no need to load facts
81
- }
82
-
83
- return act .loadPersistedFacts ()
84
- }()
85
- act .loadCachedFactsDone = true
86
- act .loadCachedFactsOk = res
87
- return res
88
- }
89
-
90
66
func (act * action ) waitUntilDependingAnalyzersWorked () {
91
67
for _ , dep := range act .deps {
92
68
if dep .pkg == act .pkg {
@@ -287,91 +263,6 @@ func (act *action) factType(fact analysis.Fact) reflect.Type {
287
263
return t
288
264
}
289
265
290
- func (act * action ) persistFactsToCache () error {
291
- analyzer := act .a
292
- if len (analyzer .FactTypes ) == 0 {
293
- return nil
294
- }
295
-
296
- // Merge new facts into the package and persist them.
297
- var facts []Fact
298
- for key , fact := range act .packageFacts {
299
- if key .pkg != act .pkg .Types {
300
- // The fact is from inherited facts from another package
301
- continue
302
- }
303
- facts = append (facts , Fact {
304
- Path : "" ,
305
- Fact : fact ,
306
- })
307
- }
308
- for key , fact := range act .objectFacts {
309
- obj := key .obj
310
- if obj .Pkg () != act .pkg .Types {
311
- // The fact is from inherited facts from another package
312
- continue
313
- }
314
-
315
- path , err := objectpath .For (obj )
316
- if err != nil {
317
- // The object is not globally addressable
318
- continue
319
- }
320
-
321
- facts = append (facts , Fact {
322
- Path : string (path ),
323
- Fact : fact ,
324
- })
325
- }
326
-
327
- factsCacheDebugf ("Caching %d facts for package %q and analyzer %s" , len (facts ), act .pkg .Name , act .a .Name )
328
-
329
- key := fmt .Sprintf ("%s/facts" , analyzer .Name )
330
- return act .r .pkgCache .Put (act .pkg , cache .HashModeNeedAllDeps , key , facts )
331
- }
332
-
333
- func (act * action ) loadPersistedFacts () bool {
334
- var facts []Fact
335
- key := fmt .Sprintf ("%s/facts" , act .a .Name )
336
- if err := act .r .pkgCache .Get (act .pkg , cache .HashModeNeedAllDeps , key , & facts ); err != nil {
337
- if ! errors .Is (err , cache .ErrMissing ) && ! errors .Is (err , io .EOF ) {
338
- act .r .log .Warnf ("Failed to get persisted facts: %s" , err )
339
- }
340
-
341
- factsCacheDebugf ("No cached facts for package %q and analyzer %s" , act .pkg .Name , act .a .Name )
342
- return false
343
- }
344
-
345
- factsCacheDebugf ("Loaded %d cached facts for package %q and analyzer %s" , len (facts ), act .pkg .Name , act .a .Name )
346
-
347
- for _ , f := range facts {
348
- if f .Path == "" { // this is a package fact
349
- key := packageFactKey {act .pkg .Types , act .factType (f .Fact )}
350
- act .packageFacts [key ] = f .Fact
351
- continue
352
- }
353
- obj , err := objectpath .Object (act .pkg .Types , objectpath .Path (f .Path ))
354
- if err != nil {
355
- // Be lenient about these errors. For example, when
356
- // analyzing io/ioutil from source, we may get a fact
357
- // for methods on the devNull type, and objectpath
358
- // will happily create a path for them. However, when
359
- // we later load io/ioutil from export data, the path
360
- // no longer resolves.
361
- //
362
- // If an exported type embeds the unexported type,
363
- // then (part of) the unexported type will become part
364
- // of the type information and our path will resolve
365
- // again.
366
- continue
367
- }
368
- factKey := objectFactKey {obj , act .factType (f .Fact )}
369
- act .objectFacts [factKey ] = f .Fact
370
- }
371
-
372
- return true
373
- }
374
-
375
266
func (act * action ) markDepsForAnalyzingSource () {
376
267
// Horizontal deps (analyzer.Requires) must be loaded from source and analyzed before analyzing
377
268
// this action.
0 commit comments