| 1 | // Copyright 2023 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | package callgraph_testscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph_test`/ |
| 5 | |
| 6 | import ( |
| 7 | "syncscip-go gomod github.com/golang/go/src go1.25.0 sync/" |
| 8 | "testingscip-go gomod github.com/golang/go/src go1.25.0 testing/" |
| 9 | |
| 10 | "golang.org/x/tools/go/callgraphscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph`/" |
| 11 | "golang.org/x/tools/go/callgraph/chascip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/cha`/" |
| 12 | "golang.org/x/tools/go/callgraph/rtascip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/rta`/" |
| 13 | "golang.org/x/tools/go/callgraph/staticscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/static`/" |
| 14 | "golang.org/x/tools/go/callgraph/vtascip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta`/" |
| 15 | "golang.org/x/tools/go/ssascip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/" |
| 16 | "golang.org/x/tools/go/ssa/ssautilscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa/ssautil`/" |
| 17 | "golang.org/x/tools/internal/testfilesscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/testfiles`/" |
| 18 | "golang.org/x/tools/txtarscip-go gomod golang.org/x/tools . `golang.org/x/tools/txtar`/" |
| 19 | ) |
| 20 | |
| 21 | // Benchmarks comparing different callgraph algorithms implemented in |
| 22 | // x/tools/go/callgraph. Comparison is on both speed, memory and precision. |
| 23 | // Fewer edges and fewer reachable nodes implies a more precise result. |
| 24 | // Comparison is done on a hello world http server using net/http. |
| 25 | // |
| 26 | // Current results were on an i7 macbook on go version devel go1.20-2730. |
| 27 | // Number of nodes, edges, and reachable function are expected to vary between |
| 28 | // go versions. Timing results are expected to vary between machines. |
| 29 | // BenchmarkStatic-12 53 ms/op 6 MB/op 12113 nodes 37355 edges 1522 reachable |
| 30 | // BenchmarkCHA-12 86 ms/op 16 MB/op 12113 nodes 131717 edges 7640 reachable |
| 31 | // BenchmarkRTA-12 110 ms/op 12 MB/op 6566 nodes 42291 edges 5099 reachable |
| 32 | // BenchmarkPTA-12 1427 ms/op 600 MB/op 8714 nodes 28244 edges 4184 reachable |
| 33 | // BenchmarkVTA-12 600 ms/op 78 MB/op 12114 nodes 44861 edges 4919 reachable |
| 34 | // BenchmarkVTA2-12 793 ms/op 104 MB/op 5450 nodes 22208 edges 4042 reachable |
| 35 | // BenchmarkVTA3-12 977 ms/op 124 MB/op 4621 nodes 19331 edges 3700 reachable |
| 36 | // BenchmarkVTAAlt-12 372 ms/op 57 MB/op 7763 nodes 29912 edges 4258 reachable |
| 37 | // BenchmarkVTAAlt2-12 570 ms/op 78 MB/op 4838 nodes 20169 edges 3737 reachable |
| 38 | // |
| 39 | // Note: |
| 40 | // * Static is unsound and may miss real edges. |
| 41 | // * RTA starts from a main function and only includes reachable functions. |
| 42 | // * CHA starts from all functions. |
| 43 | // * VTA, VTA2, and VTA3 are starting from all functions and the CHA callgraph. |
| 44 | // VTA2 and VTA3 are the result of re-applying VTA to the functions reachable |
| 45 | // from main() via the callgraph of the previous stage. |
| 46 | // * VTAAlt, and VTAAlt2 start from the functions reachable from main via the |
| 47 | // CHA callgraph. |
| 48 | // * All algorithms are unsound w.r.t. reflection. |
| 49 | |
| 50 | const httpExscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph_test`/httpEx. = ` |
| 51 | -- go.mod -- |
| 52 | module x.io |
| 53 | |
| 54 | -- main.go -- |
| 55 | package main |
| 56 | |
| 57 | import ( |
| 58 | "fmt" |
| 59 | "net/http" |
| 60 | ) |
| 61 | |
| 62 | func hello(w http.ResponseWriter, req *http.Request) { |
| 63 | fmt.Fprintf(w, "hello world\n") |
| 64 | } |
| 65 | |
| 66 | func main() { |
| 67 | http.HandleFunc("/hello", hello) |
| 68 | http.ListenAndServe(":8090", nil) |
| 69 | } |
| 70 | ` |
| 71 | |
| 72 | var ( |
| 73 | oncescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph_test`/once. syncscip-go gomod github.com/golang/go/src go1.25.0 sync/.Oncescip-go gomod github.com/golang/go/src go1.25.0 sync/Once# |
| 74 | mainscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph_test`/main. *ssascip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/.Functionscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/Function# |
| 75 | ) |
| 76 | |
| 77 | func examplescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph_test`/example().(t testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.TBscip-go gomod github.com/golang/go/src go1.25.0 testing/TB#) (*ssascip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/.Programscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/Program#, *ssascip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/.Functionscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/Function#) { |
| 78 | oncescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph_test`/once..Doscip-go gomod github.com/golang/go/src go1.25.0 sync/Once#Do().(func() { |
| 79 | pkgs := testfilesscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/testfiles`/.LoadPackagesscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/testfiles`/LoadPackages().(t, txtarscip-go gomod golang.org/x/tools . `golang.org/x/tools/txtar`/.Parsescip-go gomod golang.org/x/tools . `golang.org/x/tools/txtar`/Parse().([]byte(httpExscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph_test`/httpEx.)), ".") |
| 80 | prog, ssapkgs := ssautilscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa/ssautil`/.Packagesscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa/ssautil`/Packages().(pkgs, ssascip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/.InstantiateGenericsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/InstantiateGenerics.) |
| 81 | prog.Buildscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/Program#Build().() |
| 82 | mainscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph_test`/main. = ssapkgs[0].Membersscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/Package#Members.["main"].(*ssascip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/.Functionscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/Function#) |
| 83 | }) |
| 84 | return mainscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph_test`/main..Progscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/Function#Prog., mainscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph_test`/main. |
| 85 | } |
| 86 | |
| 87 | var statsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph_test`/stats. bool = false // print stats? |
| 88 | |
| 89 | func logStatsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph_test`/logStats().(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#, cnd bool, name string, cg *callgraphscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph`/.Graphscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph`/Graph#, main *ssascip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/.Functionscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/Function#) { |
| 90 | if cnd && statsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph_test`/stats. { |
| 91 | e := 0 |
| 92 | for _, n := range cg.Nodesscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph`/Graph#Nodes. { |
| 93 | e += len(n.Outscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph`/Node#Out.) |
| 94 | } |
| 95 | r := len(reachesscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph_test`/reaches().(main, cg, false)) |
| 96 | b.Logfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Logf().("%s:\t%d nodes\t%d edges\t%d reachable", name, len(cg.Nodesscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph`/Graph#Nodes.), e, r) |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | func BenchmarkStaticscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph_test`/BenchmarkStatic().(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) { |
| 101 | |
| 102 | prog, main := examplescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph_test`/example().(b) |
| 103 | |
| 104 | for i := 0; b.Loopscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Loop().(); i++ { |
| 105 | cg := staticscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/static`/.CallGraphscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/static`/CallGraph().(prog) |
| 106 | logStatsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph_test`/logStats().(b, i == 0, "static", cg, main) |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | func BenchmarkCHAscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph_test`/BenchmarkCHA().(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) { |
| 111 | |
| 112 | prog, main := examplescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph_test`/example().(b) |
| 113 | |
| 114 | for i := 0; b.Loopscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Loop().(); i++ { |
| 115 | cg := chascip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/cha`/.CallGraphscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/cha`/CallGraph().(prog) |
| 116 | logStatsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph_test`/logStats().(b, i == 0, "cha", cg, main) |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | func BenchmarkRTAscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph_test`/BenchmarkRTA().(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) { |
| 121 | |
| 122 | _, main := examplescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph_test`/example().(b) |
| 123 | |
| 124 | for i := 0; b.Loopscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Loop().(); i++ { |
| 125 | res := rtascip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/rta`/.Analyzescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/rta`/Analyze().([]*ssascip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/.Functionscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/Function#{main}, true) |
| 126 | cg := res.CallGraphscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/rta`/Result#CallGraph. |
| 127 | logStatsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph_test`/logStats().(b, i == 0, "rta", cg, main) |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | func BenchmarkVTAscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph_test`/BenchmarkVTA().(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) { |
| 132 | |
| 133 | prog, main := examplescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph_test`/example().(b) |
| 134 | |
| 135 | for i := 0; b.Loopscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Loop().(); i++ { |
| 136 | cg := vtascip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta`/.CallGraphscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta`/CallGraph().(ssautilscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa/ssautil`/.AllFunctionsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa/ssautil`/AllFunctions().(prog), chascip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/cha`/.CallGraphscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/cha`/CallGraph().(prog)) |
| 137 | logStatsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph_test`/logStats().(b, i == 0, "vta", cg, main) |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | func BenchmarkVTA2scip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph_test`/BenchmarkVTA2().(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) { |
| 142 | |
| 143 | prog, main := examplescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph_test`/example().(b) |
| 144 | |
| 145 | for i := 0; b.Loopscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Loop().(); i++ { |
| 146 | vta1 := vtascip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta`/.CallGraphscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta`/CallGraph().(ssautilscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa/ssautil`/.AllFunctionsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa/ssautil`/AllFunctions().(prog), chascip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/cha`/.CallGraphscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/cha`/CallGraph().(prog)) |
| 147 | cg := vtascip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta`/.CallGraphscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta`/CallGraph().(reachesscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph_test`/reaches().(main, vta1, true), vta1) |
| 148 | logStatsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph_test`/logStats().(b, i == 0, "vta2", cg, main) |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | func BenchmarkVTA3scip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph_test`/BenchmarkVTA3().(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) { |
| 153 | |
| 154 | prog, main := examplescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph_test`/example().(b) |
| 155 | |
| 156 | for i := 0; b.Loopscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Loop().(); i++ { |
| 157 | vta1 := vtascip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta`/.CallGraphscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta`/CallGraph().(ssautilscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa/ssautil`/.AllFunctionsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa/ssautil`/AllFunctions().(prog), chascip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/cha`/.CallGraphscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/cha`/CallGraph().(prog)) |
| 158 | vta2 := vtascip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta`/.CallGraphscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta`/CallGraph().(reachesscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph_test`/reaches().(main, vta1, true), vta1) |
| 159 | cg := vtascip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta`/.CallGraphscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta`/CallGraph().(reachesscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph_test`/reaches().(main, vta2, true), vta2) |
| 160 | logStatsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph_test`/logStats().(b, i == 0, "vta3", cg, main) |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | func BenchmarkVTAAltscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph_test`/BenchmarkVTAAlt().(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) { |
| 165 | |
| 166 | prog, main := examplescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph_test`/example().(b) |
| 167 | |
| 168 | for i := 0; b.Loopscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Loop().(); i++ { |
| 169 | cha := chascip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/cha`/.CallGraphscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/cha`/CallGraph().(prog) |
| 170 | cg := vtascip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta`/.CallGraphscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta`/CallGraph().(reachesscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph_test`/reaches().(main, cha, true), cha) // start from only functions reachable by CHA. |
| 171 | logStatsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph_test`/logStats().(b, i == 0, "vta-alt", cg, main) |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | func BenchmarkVTAAlt2scip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph_test`/BenchmarkVTAAlt2().(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) { |
| 176 | |
| 177 | prog, main := examplescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph_test`/example().(b) |
| 178 | |
| 179 | for i := 0; b.Loopscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Loop().(); i++ { |
| 180 | cha := chascip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/cha`/.CallGraphscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/cha`/CallGraph().(prog) |
| 181 | vta1 := vtascip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta`/.CallGraphscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta`/CallGraph().(reachesscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph_test`/reaches().(main, cha, true), cha) |
| 182 | cg := vtascip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta`/.CallGraphscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta`/CallGraph().(reachesscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph_test`/reaches().(main, vta1, true), vta1) |
| 183 | logStatsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph_test`/logStats().(b, i == 0, "vta-alt2", cg, main) |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | // reaches computes the transitive closure of functions forward reachable |
| 188 | // via calls in cg starting from `sources`. If refs is true, include |
| 189 | // functions referred to in an instruction. |
| 190 | func reachesscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph_test`/reaches().(source *ssascip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/.Functionscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/Function#, cg *callgraphscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph`/.Graphscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph`/Graph#, refs bool) map[*ssascip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/.Functionscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/Function#]bool { |
| 191 | seen := make(map[*ssascip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/.Functionscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/Function#]bool) |
| 192 | var visit func(f *ssascip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/.Functionscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/Function#) |
| 193 | visit = func(f *ssascip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/.Functionscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/Function#) { |
| 194 | if seen[f] { |
| 195 | return |
| 196 | } |
| 197 | seen[f] = true |
| 198 | |
| 199 | if n := cg.Nodesscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph`/Graph#Nodes.[f]; n != nil { |
| 200 | for _, e := range n.Outscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph`/Node#Out. { |
| 201 | if e.Sitescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph`/Edge#Site. != nil { |
| 202 | visit(e.Calleescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph`/Edge#Callee..Funcscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph`/Node#Func.) |
| 203 | } |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | if refs { |
| 208 | var buf [10]*ssascip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/.Valuescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/Value# // avoid alloc in common case |
| 209 | for _, b := range f.Blocksscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/Function#Blocks. { |
| 210 | for _, instr := range b.Instrsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/BasicBlock#Instrs. { |
| 211 | for _, op := range instr.Operandsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/Instruction#Operands.(buf[:0]) { |
| 212 | if fn, ok := (*op).(*ssascip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/.Functionscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/ssa`/Function#); ok { |
| 213 | visit(fn) |
| 214 | } |
| 215 | } |
| 216 | } |
| 217 | } |
| 218 | } |
| 219 | } |
| 220 | visit(source) |
| 221 | return seen |
| 222 | } |