checkers/analyzer: remove concurrency from go/analysis
analyzer
#1416
+10
−40
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There are currently several concurrency issues with the analyzer:
ctx.SetFileInfo
andc.Check
can be called concurrently. However, go-critic does not support multiple operations on the same context at once.This issue also means that checkers may be called with a context containing the wrong file, because the checker being run in a goroutine may not be complete before
ctx.SetFileInfo
is called for the next file.The same checker is called multiple times in parallel. This is not supported by go-critic, because checkers rely on non-synchronized local state.
It is also worth noting that these issues currently exist even if the
concurrency
flag is set to 1. This is because registering files and running checkers are still executed in parallel, even when concurrency is disabled.Ultimately, I do not see a good way to integrate concurrency, go-critic and the
go/analysis
framework together, and the current implementation is unsound. Therefore, I have removed theconcurrency
flag and changed both the registration of files and running of checkers to run sequentially.One potential way to improve this in the future would be to provide a separate
go/analysis
analyzer for each checker, similar to how staticcheck does. This would allow several go-critic analyzers to be run in parallel using thego/analysis
framework. However, this would be a much greater breaking change to go-critic'sgo/analysis
API, so I have not attempted this for now.Closes #1414