Skip to content

Commit 96844c3

Browse files
committed
cmd/{guru,callgraph}: stop using go/pointer
This change removes the -algo=pta option from cmd/callgraph, and all the subcommands of cmd/guru, that use pointer analysis. These features have been poorly supported for a long time, and the pointer analysis package is about to be tagged and deleted. Updates golang/go#59676 Change-Id: Id4ded651b8385c588991d01377b2f087d14ae191 Reviewed-on: https://go-review.googlesource.com/c/tools/+/499696 gopls-CI: kokoro <[email protected]> Reviewed-by: Bryan Mills <[email protected]> Run-TryBot: Alan Donovan <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent cd694d8 commit 96844c3

37 files changed

+24
-2553
lines changed

cmd/callgraph/main.go

+6-45
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,12 @@ package main // import "golang.org/x/tools/cmd/callgraph"
2020
// callee file/line/col
2121

2222
import (
23-
"bufio"
2423
"bytes"
2524
"flag"
2625
"fmt"
2726
"go/build"
2827
"go/token"
2928
"io"
30-
"log"
3129
"os"
3230
"runtime"
3331
"text/template"
@@ -39,25 +37,21 @@ import (
3937
"golang.org/x/tools/go/callgraph/static"
4038
"golang.org/x/tools/go/callgraph/vta"
4139
"golang.org/x/tools/go/packages"
42-
"golang.org/x/tools/go/pointer"
4340
"golang.org/x/tools/go/ssa"
4441
"golang.org/x/tools/go/ssa/ssautil"
4542
)
4643

4744
// flags
4845
var (
4946
algoFlag = flag.String("algo", "rta",
50-
`Call graph construction algorithm (static, cha, rta, vta, pta)`)
47+
`Call graph construction algorithm (static, cha, rta, vta)`)
5148

5249
testFlag = flag.Bool("test", false,
5350
"Loads test code (*_test.go) for imported packages")
5451

5552
formatFlag = flag.String("format",
5653
"{{.Caller}}\t--{{.Dynamic}}-{{.Line}}:{{.Column}}-->\t{{.Callee}}",
5754
"A template expression specifying how to format an edge")
58-
59-
ptalogFlag = flag.String("ptalog", "",
60-
"Location of the points-to analysis log file, or empty to disable logging.")
6155
)
6256

6357
func init() {
@@ -68,7 +62,7 @@ const Usage = `callgraph: display the call graph of a Go program.
6862
6963
Usage:
7064
71-
callgraph [-algo=static|cha|rta|vta|pta] [-test] [-format=...] package...
65+
callgraph [-algo=static|cha|rta|vta] [-test] [-format=...] package...
7266
7367
Flags:
7468
@@ -78,11 +72,10 @@ Flags:
7872
cha Class Hierarchy Analysis
7973
rta Rapid Type Analysis
8074
vta Variable Type Analysis
81-
pta inclusion-based Points-To Analysis
8275
8376
The algorithms are ordered by increasing precision in their
8477
treatment of dynamic calls (and thus also computational cost).
85-
RTA and PTA require a whole program (main or test), and
78+
RTA requires a whole program (main or test), and
8679
include only functions reachable from main.
8780
8881
-test Include the package's tests in the analysis.
@@ -132,9 +125,9 @@ Examples:
132125
$GOROOT/src/net/http/triv.go | sort | uniq
133126
134127
Show functions that make dynamic calls into the 'fmt' test package,
135-
using the pointer analysis algorithm:
128+
using the Rapid Type Analysis algorithm:
136129
137-
callgraph -format='{{.Caller}} -{{.Dynamic}}-> {{.Callee}}' -test -algo=pta fmt |
130+
callgraph -format='{{.Caller}} -{{.Dynamic}}-> {{.Callee}}' -test -algo=rta fmt |
138131
sed -ne 's/-dynamic-/--/p' |
139132
sed -ne 's/-->.*fmt_test.*$//p' | sort | uniq
140133
@@ -205,39 +198,7 @@ func doCallgraph(dir, gopath, algo, format string, tests bool, args []string) er
205198
cg = cha.CallGraph(prog)
206199

207200
case "pta":
208-
// Set up points-to analysis log file.
209-
var ptalog io.Writer
210-
if *ptalogFlag != "" {
211-
if f, err := os.Create(*ptalogFlag); err != nil {
212-
log.Fatalf("Failed to create PTA log file: %s", err)
213-
} else {
214-
buf := bufio.NewWriter(f)
215-
ptalog = buf
216-
defer func() {
217-
if err := buf.Flush(); err != nil {
218-
log.Printf("flush: %s", err)
219-
}
220-
if err := f.Close(); err != nil {
221-
log.Printf("close: %s", err)
222-
}
223-
}()
224-
}
225-
}
226-
227-
mains, err := mainPackages(pkgs)
228-
if err != nil {
229-
return err
230-
}
231-
config := &pointer.Config{
232-
Mains: mains,
233-
BuildCallGraph: true,
234-
Log: ptalog,
235-
}
236-
ptares, err := pointer.Analyze(config)
237-
if err != nil {
238-
return err // internal error in pointer analysis
239-
}
240-
cg = ptares.CallGraph
201+
return fmt.Errorf("pointer analysis is no longer supported (see Go issue #59676)")
241202

242203
case "rta":
243204
mains, err := mainPackages(pkgs)

cmd/callgraph/main_test.go

-16
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,6 @@ func TestCallgraph(t *testing.T) {
6565
"pkg.main --> pkg.main2",
6666
"pkg.main2 --> (pkg.D).f",
6767
}},
68-
{"pta", false, []string{
69-
// pta distinguishes main->C, main2->D. Also has a root node.
70-
`<root> --> pkg.init`,
71-
`<root> --> pkg.main`,
72-
`pkg.main --> (pkg.C).f`,
73-
`pkg.main --> pkg.main2`,
74-
`pkg.main2 --> (pkg.D).f`,
75-
}},
7668
// tests: both the package's main and the test's main are called.
7769
// The callgraph includes all the guts of the "testing" package.
7870
{"rta", true, []string{
@@ -87,14 +79,6 @@ func TestCallgraph(t *testing.T) {
8779
`pkg.Example --> (pkg.C).f`,
8880
`pkg.main --> (pkg.C).f`,
8981
}},
90-
{"pta", true, []string{
91-
`<root> --> pkg.test.main`,
92-
`<root> --> pkg.main`,
93-
`pkg.test.main --> testing.MainStart`,
94-
`testing.runExample --> pkg.Example`,
95-
`pkg.Example --> (pkg.C).f`,
96-
`pkg.main --> (pkg.C).f`,
97-
}},
9882
} {
9983
const format = "{{.Caller}} --> {{.Callee}}"
10084
stdout = new(bytes.Buffer)

0 commit comments

Comments
 (0)