Skip to content

Commit e6a6d1c

Browse files
committed
remove the ability to select a callgraph algorithm
We'll soon remove callgraph entirely, as it doesn't do all we need and requires analysing entire programs all at once. As a step in that direction, stop exposing callgraph options to the user.
1 parent d8f7154 commit e6a6d1c

File tree

2 files changed

+3
-44
lines changed

2 files changed

+3
-44
lines changed

check/check.go

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,21 @@ import (
2323

2424
"golang.org/x/tools/go/callgraph"
2525
"golang.org/x/tools/go/callgraph/cha"
26-
"golang.org/x/tools/go/callgraph/rta"
2726
"golang.org/x/tools/go/packages"
2827
"golang.org/x/tools/go/ssa"
2928
"golang.org/x/tools/go/ssa/ssautil"
3029
)
3130

3231
// UnusedParams returns a list of human-readable issues that point out unused
3332
// function parameters.
34-
func UnusedParams(tests bool, algo string, exported, debug bool, args ...string) ([]string, error) {
33+
func UnusedParams(tests bool, exported, debug bool, args ...string) ([]string, error) {
3534
wd, err := os.Getwd()
3635
if err != nil {
3736
return nil, err
3837
}
3938
c := &Checker{
4039
wd: wd,
4140
tests: tests,
42-
algo: algo,
4341
exported: exported,
4442
}
4543
if debug {
@@ -59,7 +57,6 @@ type Checker struct {
5957
wd string
6058

6159
tests bool
62-
algo string
6360
exported bool
6461
debugLog io.Writer
6562

@@ -143,11 +140,6 @@ func (c *Checker) ProgramSSA(prog *ssa.Program) {
143140
c.prog = prog
144141
}
145142

146-
// CallgraphAlgorithm supplies Checker with the call graph construction algorithm.
147-
func (c *Checker) CallgraphAlgorithm(algo string) {
148-
c.algo = algo
149-
}
150-
151143
// CheckExportedFuncs sets whether to inspect exported functions
152144
func (c *Checker) CheckExportedFuncs(exported bool) {
153145
c.exported = exported
@@ -213,23 +205,7 @@ func (c *Checker) Check() ([]Issue, error) {
213205
})
214206
}
215207
}
216-
switch c.algo {
217-
case "cha":
218-
c.graph = cha.CallGraph(c.prog)
219-
case "rta":
220-
mains, err := mainPackages(c.prog, wantPkg)
221-
if err != nil {
222-
return nil, err
223-
}
224-
var roots []*ssa.Function
225-
for _, main := range mains {
226-
roots = append(roots, main.Func("init"), main.Func("main"))
227-
}
228-
result := rta.Analyze(roots, true)
229-
c.graph = result.CallGraph
230-
default:
231-
return nil, fmt.Errorf("unknown call graph construction algorithm: %q", c.algo)
232-
}
208+
c.graph = cha.CallGraph(c.prog)
233209
c.graph.DeleteSyntheticNodes()
234210

235211
allFuncs := ssautil.AllFunctions(c.prog)
@@ -461,21 +437,6 @@ resLoop:
461437
}
462438
}
463439

464-
// mainPackages returns the subset of main packages within pkgSet.
465-
func mainPackages(prog *ssa.Program, pkgSet map[*types.Package]*packages.Package) ([]*ssa.Package, error) {
466-
mains := make([]*ssa.Package, 0, len(pkgSet))
467-
for tpkg := range pkgSet {
468-
pkg := prog.Package(tpkg)
469-
if tpkg.Name() == "main" && pkg.Func("main") != nil {
470-
mains = append(mains, pkg)
471-
}
472-
}
473-
if len(mains) == 0 {
474-
return nil, fmt.Errorf("no main packages")
475-
}
476-
return mains, nil
477-
}
478-
479440
// calledInReturn reports whether any of a function's inbound calls happened
480441
// directly as a return statement. That is, if function "foo" was used via
481442
// "return foo()". This means that the result parameters of the function cannot

main.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ import (
1717
var (
1818
flagSet = flag.NewFlagSet("unparam", flag.ContinueOnError)
1919

20-
algo = flagSet.String("algo", "cha", `call graph construction algorithm (cha, rta).
21-
in general, use cha for libraries, and rta for programs with main packages.`)
2220
tests = flagSet.Bool("tests", true, "include tests")
2321
exported = flagSet.Bool("exported", false, "inspect exported functions")
2422
debug = flagSet.Bool("debug", false, "debug prints")
@@ -44,7 +42,7 @@ func main1() int {
4442
}
4543
return 1
4644
}
47-
warns, err := check.UnusedParams(*tests, *algo, *exported, *debug, flagSet.Args()...)
45+
warns, err := check.UnusedParams(*tests, *exported, *debug, flagSet.Args()...)
4846
if err != nil {
4947
fmt.Fprintln(os.Stderr, err)
5048
return 1

0 commit comments

Comments
 (0)