Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checkers/analyzer: remove concurrency from go/analysis analyzer #1416

Merged
merged 2 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 5 additions & 10 deletions checkers/analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
package analyzer

import (
"runtime"

"github.com/go-critic/go-critic/linter"

"golang.org/x/tools/go/analysis"
Expand All @@ -23,12 +21,11 @@ var Analyzer = &analysis.Analyzer{
var DisableCache = false

var (
flagGoVersion string
flagEnable string
flagDisable string
flagEnableAll bool
flagDebugInit bool
flagConcurrency int
flagGoVersion string
flagEnable string
flagDisable string
flagEnableAll bool
flagDebugInit bool
)

var (
Expand All @@ -50,8 +47,6 @@ func init() {
`comma-separated list of checkers to be disabled. Can include #tags`)
Analyzer.Flags.StringVar(&flagGoVersion, "go", "",
`select the Go version to target. Leave as string for the latest`)
Analyzer.Flags.IntVar(&flagConcurrency, "concurrency", runtime.GOMAXPROCS(0),
`how many checks to run concurrently (defaults to runtime.GOMAXPROCS(0))`)

for _, info := range registeredCheckers {
for pname, param := range info.Params {
Expand Down
35 changes: 5 additions & 30 deletions checkers/analyzer/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,44 +39,19 @@ func runAnalyzer(pass *analysis.Pass) (interface{}, error) {
return nil, err
}

doneCh := make(chan struct{})
diagCh := make(chan analysis.Diagnostic)
go func() {
for diag := range diagCh {
pass.Report(diag)
}
close(doneCh)
}()

sema := make(chan struct{}, flagConcurrency)
var wg sync.WaitGroup
wg.Add(len(pass.Files))

for _, f := range pass.Files {
f := f
filename := filepath.Base(pass.Fset.Position(f.Pos()).Filename)
ctx.SetFileInfo(filename, f)

sema <- struct{}{}
go func() {
defer func() {
wg.Done()
<-sema
}()

for _, c := range checkers {
warnings := c.Check(f)
for _, warning := range warnings {
diagCh <- asDiag(c, warning)
}
for _, c := range checkers {
warnings := c.Check(f)
for _, warning := range warnings {
pass.Report(asDiag(c, warning))
}
}()
}
}

wg.Wait()
close(diagCh)
<-doneCh

return nil, nil
}

Expand Down