Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port staticcheck to the go/analysis framework
This change ports all static analysis checks to the go/analysis framework and turns cmd/staticcheck into a sophisticated runner for analyses. Since our previous framework was built around the idea of having all data in memory at once, some changes had to be made to accomodate the modular go/analysis framework. All information about dependencies have to be serialized as facts. This includes information such as which objects are deprecated and which functions are pure. We have thus converted the 'functions' package to act as analyses instead of generating a global set of information. SSA packages are built per package under analysis no single SSA program exists. This also means that nodes in the SSA graph aren't canonical; the same function in a dependency may be represented by many different objects. We no longer store anything SSA related across analyses. go/analysis is designed around the idea of enabling caching of facts, and thus cmd/staticcheck was designed to utilize caching. We rely on the Go build cache to avoid loading packages from source, and we implement our own cache of facts to avoid reanalyzing packages that haven't changed. This combination can greatly reduce memory use as well as runtime. For smaller packages, it even allows real-time checking in something like a language server. We've replaced our own testing utilities with go/analysis/analysistest, primarily for the sake of consistency with other analyses. Reimplementing 'unused' in the new framework required extra work, and special knowledge in the runner. Unused cannot analyze packages in isolation, since files may be shared between test variants and identifiers may only be used in some variations of a package. Unused still exposes an entry-point matching the go/analysis framework, but it doesn't compute any facts nor report any diagnostics. Instead, it incrementally builds a view of all packages it sees. After all packages have been analyzed, the result can be queried and processed. While all other analyses can be reused by other runners directly, using unused will require special code in the runner. We've deleted the gosimple, unused and megacheck binaries. They had already been deprecated and there was little point in porting them to the new framework. With the removal of the unused binary there is currently no way to use its whole program mode. This will be rectified in a follow-up commit which adds said mode as its own check in staticcheck.
- Loading branch information