Package cha computes the call graph of a Go program using the Class Hierarchy Analysis (CHA) algorithm.
CHA was first described in "Optimization of Object-Oriented Programs Using Static Class Hierarchy Analysis", Jeffrey Dean, David Grove, and Craig Chambers, ECOOP'95.
CHA is related to RTA (see go/callgraph/rta); the difference is that CHA conservatively computes the entire "implements" relation between interfaces and concrete types ahead of time, whereas RTA uses dynamic programming to construct it on the fly as it encounters new functions reachable from main. CHA may thus include spurious call edges for types that haven't been instantiated yet, or types that are never instantiated.
Since CHA conservatively assumes that all functions are address-taken and all concrete types are put into interfaces, it is sound to run on partial programs, such as libraries without a main or test function.
// partial programs, such as libraries without a main or test function. // package cha // import "golang.org/x/tools/go/callgraph/cha" import (
"golang.org/x/tools/go/buildutil" "golang.org/x/tools/go/callgraph" "golang.org/x/tools/go/callgraph/cha" "golang.org/x/tools/go/callgraph/rta" "golang.org/x/tools/go/callgraph/static"
case "cha": cg = cha.CallGraph(prog) case "pta":
cha is referenced in 10 repositoriesgithub.com/golang/tools
- 2 references in cmd/callgraph/main.go
- 2 references in go/callgraph/cha/cha_test.go
- 1 reference in go/callgraph/cha/cha.go
- 2 references in src/code.google.com/p/go.tools/cmd/callgraph/main.go
- 2 references in src/code.google.com/p/go.tools/go/callgraph/cha/cha_test.go
- 2 references in src/golang.org/x/tools/cmd/callgraph/main.go
- 2 references in src/golang.org/x/tools/go/callgraph/cha/cha_test.go