go.tools: various comments + doc tweaks.
No functional changes.
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/74270043
diff --git a/go/callgraph/callgraph.go b/go/callgraph/callgraph.go
index 5b4e348..7d78a05 100644
--- a/go/callgraph/callgraph.go
+++ b/go/callgraph/callgraph.go
@@ -100,6 +100,7 @@
}
// AddEdge adds the edge (caller, site, callee) to the call graph.
+// Elimination of duplicate edges is the caller's responsibility.
func AddEdge(caller *Node, site ssa.CallInstruction, callee *Node) {
e := &Edge{caller, site, callee}
callee.In = append(callee.In, e)
diff --git a/go/callgraph/util.go b/go/callgraph/util.go
index f807dfd..1003fcd 100644
--- a/go/callgraph/util.go
+++ b/go/callgraph/util.go
@@ -82,6 +82,10 @@
// synthetic functions (except g.Root and package initializers),
// preserving the topology.
func (g *Graph) DeleteSyntheticNodes() {
+ // TODO(adonovan): opt: this step results in duplicate
+ // edges---approx 10% of the total. I suspect this is due to
+ // some interface method calls dispatching to both (C).f and
+ // (*C).f where the latter is a wrapper.
for fn, cgn := range g.Nodes {
if cgn == g.Root || fn.Synthetic == "" || isInit(cgn.Func) {
continue // keep
diff --git a/go/pointer/gen.go b/go/pointer/gen.go
index 77cf159..fdd2370 100644
--- a/go/pointer/gen.go
+++ b/go/pointer/gen.go
@@ -1103,6 +1103,10 @@
r.String() // (asserts that it doesn't crash)
root := a.makeCGNode(r, 0, nil)
+ // TODO(adonovan): make an ssa utility to construct an actual
+ // root function so we don't need to special-case site-less
+ // call edges.
+
// For each main package, call main.init(), main.main().
for _, mainPkg := range a.config.Mains {
main := mainPkg.Func("main")
diff --git a/go/pointer/labels.go b/go/pointer/labels.go
index 25f6492..3fd8681 100644
--- a/go/pointer/labels.go
+++ b/go/pointer/labels.go
@@ -14,7 +14,7 @@
)
// A Label is an entity that may be pointed to by a pointer, map,
-// channel, 'func', slice or interface. Labels include:
+// channel, 'func', slice or interface.
//
// Labels include:
// - functions
@@ -79,8 +79,9 @@
// String returns the printed form of this label.
//
// Examples: Object type:
+// x (a variable)
// (sync.Mutex).Lock (a function)
-// "foo":[]byte (a slice constant)
+// convert (array created by conversion)
// makemap (map allocated via make)
// makechan (channel allocated via make)
// makeinterface (tagged object allocated by makeinterface)
diff --git a/go/ssa/const.go b/go/ssa/const.go
index bb1eb25..36ae99e 100644
--- a/go/ssa/const.go
+++ b/go/ssa/const.go
@@ -73,6 +73,7 @@
} else if c.Value.Kind() == exact.String {
s = exact.StringVal(c.Value)
const max = 20
+ // TODO(adonovan): don't cut a rune in half.
if len(s) > max {
s = s[:max-3] + "..." // abbreviate
}
diff --git a/go/ssa/create.go b/go/ssa/create.go
index cab8ba8..3317013 100644
--- a/go/ssa/create.go
+++ b/go/ssa/create.go
@@ -48,6 +48,8 @@
}
for _, info := range iprog.AllPackages {
+ // TODO(adonovan): relax this constraint if the
+ // program contains only "soft" errors.
if info.TransitivelyErrorFree {
prog.CreatePackage(info)
}
diff --git a/go/ssa/ssa.go b/go/ssa/ssa.go
index a9ace79..0b9deec 100644
--- a/go/ssa/ssa.go
+++ b/go/ssa/ssa.go
@@ -312,11 +312,11 @@
// The tree may be navigated using Idom()/Dominees() and queried using
// Dominates().
//
-// The order of Preds and Succs are significant (to Phi and If
+// The order of Preds and Succs is significant (to Phi and If
// instructions, respectively).
//
type BasicBlock struct {
- Index int // index of this block within Func.Blocks
+ Index int // index of this block within Parent().Blocks
Comment string // optional label; no semantic significance
parent *Function // parent function
Instrs []Instruction // instructions in order
@@ -521,6 +521,7 @@
// MUL is pointer indirection (load).
// XOR is bitwise complement.
// SUB is negation.
+// NOT is logical negation.
//
// If CommaOk and Op=ARROW, the result is a 2-tuple of the value above
// and a boolean indicating the success of the receive. The
@@ -689,7 +690,7 @@
// Both Len and Cap must be non-nil Values of integer type.
//
// (Alloc(types.Array) followed by Slice will not suffice because
-// Alloc can only create arrays of statically known length.)
+// Alloc can only create arrays of constant length.)
//
// Type() returns a (possibly named) *types.Slice.
//
diff --git a/go/types/methodset.go b/go/types/methodset.go
index 9ded496..77297ea 100644
--- a/go/types/methodset.go
+++ b/go/types/methodset.go
@@ -13,7 +13,7 @@
)
// A MethodSet is an ordered set of concrete or abstract (interface) methods;
-// a method is a MethodVal selection.
+// a method is a MethodVal selection, and they are ordered by ascending m.Obj().Id().
// The zero value for a MethodSet is a ready-to-use empty method set.
type MethodSet struct {
list []*Selection