|
1 | 1 | package goanalysis
|
2 | 2 |
|
3 | 3 | import (
|
4 |
| - "errors" |
5 | 4 | "fmt"
|
6 | 5 | "go/types"
|
7 | 6 | "reflect"
|
8 | 7 | "runtime/debug"
|
9 |
| - "time" |
10 | 8 |
|
11 | 9 | "golang.org/x/tools/go/analysis"
|
12 | 10 | "golang.org/x/tools/go/packages"
|
13 | 11 |
|
14 | 12 | "github.com/golangci/golangci-lint/internal/errorutil"
|
15 |
| - "github.com/golangci/golangci-lint/pkg/goanalysis/pkgerrors" |
16 | 13 | )
|
17 | 14 |
|
18 | 15 | type actionAllocator struct {
|
@@ -89,96 +86,6 @@ func (act *action) analyzeSafe() {
|
89 | 86 | act.r.sw.TrackStage(act.a.Name, act.analyze)
|
90 | 87 | }
|
91 | 88 |
|
92 |
| -func (act *action) analyze() { |
93 |
| - defer close(act.analysisDoneCh) // unblock actions depending on this action |
94 |
| - |
95 |
| - if !act.needAnalyzeSource { |
96 |
| - return |
97 |
| - } |
98 |
| - |
99 |
| - defer func(now time.Time) { |
100 |
| - analyzeDebugf("go/analysis: %s: %s: analyzed package %q in %s", act.r.prefix, act.a.Name, act.pkg.Name, time.Since(now)) |
101 |
| - }(time.Now()) |
102 |
| - |
103 |
| - // Report an error if any dependency failures. |
104 |
| - var depErrors error |
105 |
| - for _, dep := range act.deps { |
106 |
| - if dep.err == nil { |
107 |
| - continue |
108 |
| - } |
109 |
| - |
110 |
| - depErrors = errors.Join(depErrors, errors.Unwrap(dep.err)) |
111 |
| - } |
112 |
| - if depErrors != nil { |
113 |
| - act.err = fmt.Errorf("failed prerequisites: %w", depErrors) |
114 |
| - return |
115 |
| - } |
116 |
| - |
117 |
| - // Plumb the output values of the dependencies |
118 |
| - // into the inputs of this action. Also facts. |
119 |
| - inputs := make(map[*analysis.Analyzer]any) |
120 |
| - startedAt := time.Now() |
121 |
| - for _, dep := range act.deps { |
122 |
| - if dep.pkg == act.pkg { |
123 |
| - // Same package, different analysis (horizontal edge): |
124 |
| - // in-memory outputs of prerequisite analyzers |
125 |
| - // become inputs to this analysis pass. |
126 |
| - inputs[dep.a] = dep.result |
127 |
| - } else if dep.a == act.a { // (always true) |
128 |
| - // Same analysis, different package (vertical edge): |
129 |
| - // serialized facts produced by prerequisite analysis |
130 |
| - // become available to this analysis pass. |
131 |
| - inheritFacts(act, dep) |
132 |
| - } |
133 |
| - } |
134 |
| - factsDebugf("%s: Inherited facts in %s", act, time.Since(startedAt)) |
135 |
| - |
136 |
| - // Run the analysis. |
137 |
| - pass := &analysis.Pass{ |
138 |
| - Analyzer: act.a, |
139 |
| - Fset: act.pkg.Fset, |
140 |
| - Files: act.pkg.Syntax, |
141 |
| - OtherFiles: act.pkg.OtherFiles, |
142 |
| - Pkg: act.pkg.Types, |
143 |
| - TypesInfo: act.pkg.TypesInfo, |
144 |
| - TypesSizes: act.pkg.TypesSizes, |
145 |
| - ResultOf: inputs, |
146 |
| - Report: func(d analysis.Diagnostic) { act.diagnostics = append(act.diagnostics, d) }, |
147 |
| - ImportObjectFact: act.importObjectFact, |
148 |
| - ExportObjectFact: act.exportObjectFact, |
149 |
| - ImportPackageFact: act.importPackageFact, |
150 |
| - ExportPackageFact: act.exportPackageFact, |
151 |
| - AllObjectFacts: act.allObjectFacts, |
152 |
| - AllPackageFacts: act.allPackageFacts, |
153 |
| - } |
154 |
| - act.pass = pass |
155 |
| - act.r.passToPkgGuard.Lock() |
156 |
| - act.r.passToPkg[pass] = act.pkg |
157 |
| - act.r.passToPkgGuard.Unlock() |
158 |
| - |
159 |
| - if act.pkg.IllTyped { |
160 |
| - // It looks like there should be !pass.Analyzer.RunDespiteErrors |
161 |
| - // but govet's cgocall crashes on it. Govet itself contains !pass.Analyzer.RunDespiteErrors condition here, |
162 |
| - // but it exits before it if packages.Load have failed. |
163 |
| - act.err = fmt.Errorf("analysis skipped: %w", &pkgerrors.IllTypedError{Pkg: act.pkg}) |
164 |
| - } else { |
165 |
| - startedAt = time.Now() |
166 |
| - act.result, act.err = pass.Analyzer.Run(pass) |
167 |
| - analyzedIn := time.Since(startedAt) |
168 |
| - if analyzedIn > time.Millisecond*10 { |
169 |
| - debugf("%s: run analyzer in %s", act, analyzedIn) |
170 |
| - } |
171 |
| - } |
172 |
| - |
173 |
| - // disallow calls after Run |
174 |
| - pass.ExportObjectFact = nil |
175 |
| - pass.ExportPackageFact = nil |
176 |
| - |
177 |
| - if err := act.persistFactsToCache(); err != nil { |
178 |
| - act.r.log.Warnf("Failed to persist facts to cache: %s", err) |
179 |
| - } |
180 |
| -} |
181 |
| - |
182 | 89 | // importPackageFact implements Pass.ImportPackageFact.
|
183 | 90 | // Given a non-nil pointer ptr of type *T, where *T satisfies Fact,
|
184 | 91 | // fact copies the fact value to *ptr.
|
|
0 commit comments