Skip to content

Commit

Permalink
Support unused's whole program mode
Browse files Browse the repository at this point in the history
Unused required some changes to have a correctly working whole program
mode. We had to let go of using *ssa.Functions to identify functions,
as we cannot persist them across packages anymore. Instead, we
switched to strings for deduplication and finding the "owning"
types.Object of functions, even those that do not have a types.Object
recorded in the SSA graph.

To enable whole program mode, staticcheck accepts the new
-unused.whole-program flag. An alternative approach we tried was to
run two instances of unused, one in normal mode and one in exported
mode. However, the cost of whole program mode is significant and we
don't want to subject all users to it.

When unused runs in whole program mode, its check name changes to
U1001. This is so that linter directives and configuration files can
address both modes separately.
  • Loading branch information
dominikh committed Apr 27, 2019
1 parent 16ee8ce commit 00c4802
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 69 deletions.
8 changes: 6 additions & 2 deletions cmd/staticcheck/staticcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

func main() {
fs := lintutil.FlagSet("staticcheck")
wholeProgram := fs.Bool("unused.whole-program", false, "Run unused in whole program mode")
fs.Parse(os.Args[1:])

var cs []*analysis.Analyzer
Expand All @@ -28,7 +29,10 @@ func main() {
cs = append(cs, v)
}

cums := []lint.CumulativeChecker{unused.NewChecker()}

u := unused.NewChecker()
if *wholeProgram {
u.WholeProgram = true
}
cums := []lint.CumulativeChecker{u}
lintutil.ProcessFlagSet(cs, cums, fs)
}
Loading

0 comments on commit 00c4802

Please sign in to comment.