go.tools/go/pointer: remove context-sensitivity from API.
Previously, each {Indirect,}Query would return a set of Pointers, one per context; now it returns (at most) one Pointer combining information from all contexts.
The old API was more faithful to the implementation concepts, but the analysis is not sufficiently context-sensitive that it makes sense: all existing clients simply throw away the context information---so now we do that for them.
(I may remove the context-sensitivity from the callgraph too, but I'll benchmark that first to see if it reduces precision.)
LGTM=crawshaw
R=crawshaw
CC=golang-codereviews
https://golang.org/cl/66130044
diff --git a/go/pointer/gen.go b/go/pointer/gen.go
index dcaf76c..1a2bfcf 100644
--- a/go/pointer/gen.go
+++ b/go/pointer/gen.go
@@ -79,28 +79,33 @@
fmt.Fprintf(a.log, "\tval[%s] = n%d (%T)\n", v.Name(), id, v)
}
- // TODO(adonovan): due to context-sensitivity, we may
- // encounter the same Value in many contexts. In a follow-up,
- // let's merge them to a canonical node, since that's what all
- // clients want.
- // ptr, ok := a.result.Queries[v]
- // if !ok {
- // // First time? Create the canonical probe node.
- // ptr = Pointer{a, nil, a.addNodes(t, "query")}
- // a.result.Queries[v] = ptr
- // }
- // a.copy(ptr.n, id, a.sizeof(v.Type()))
+ // Due to context-sensitivity, we may encounter the same Value
+ // in many contexts. We merge them to a canonical node, since
+ // that's what all clients want.
// Record the (v, id) relation if the client has queried pts(v).
if _, ok := a.config.Queries[v]; ok {
- a.result.Queries[v] = append(a.result.Queries[v], Pointer{a, cgn, id})
+ t := v.Type()
+ ptr, ok := a.result.Queries[v]
+ if !ok {
+ // First time? Create the canonical query node.
+ ptr = Pointer{a, a.addNodes(t, "query")}
+ a.result.Queries[v] = ptr
+ }
+ a.result.Queries[v] = ptr
+ a.copy(ptr.n, id, a.sizeof(t))
}
// Record the (*v, id) relation if the client has queried pts(*v).
if _, ok := a.config.IndirectQueries[v]; ok {
- indirect := a.addNodes(v.Type(), "query.indirect")
- a.genLoad(cgn, indirect, v, 0, a.sizeof(v.Type()))
- a.result.IndirectQueries[v] = append(a.result.IndirectQueries[v], Pointer{a, cgn, indirect})
+ t := v.Type()
+ ptr, ok := a.result.IndirectQueries[v]
+ if !ok {
+ // First time? Create the canonical indirect query node.
+ ptr = Pointer{a, a.addNodes(v.Type(), "query.indirect")}
+ a.result.IndirectQueries[v] = ptr
+ }
+ a.genLoad(cgn, ptr.n, v, 0, a.sizeof(t))
}
}