Documentation
¶
Overview ¶
Package analyzer builds a precise call graph for a Go monorepo using golang.org/x/tools. It uses:
- go/packages — load packages with full type information
- go/ssa — build SSA IR from the loaded packages
- callgraph/cha — Class Hierarchy Analysis to construct the call graph
CHA is chosen because it is conservative (never misses an edge), fast, and does not require a single main package — which is essential for a monorepo that contains multiple independent services.
Index ¶
- func HashGoMod(gomod *GoMod) string
- type Analyzer
- func (a *Analyzer) BuildGraph() (map[string]*types.Function, *types.CallGraph, error)
- func (a *Analyzer) ComputeHashes(functions map[string]*types.Function, prevSourceHashes map[string]string, ...) error
- func (a *Analyzer) ComputeSourceHashes() (map[string]string, error)
- func (a *Analyzer) ExtractExternalDeps() (map[string]string, string, error)
- func (a *Analyzer) Load() error
- type GoMod
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Analyzer ¶
type Analyzer struct {
// contains filtered or unexported fields
}
Analyzer loads a monorepo, builds a CHA call graph, and returns the structured data needed by the diff and impact packages.
func (*Analyzer) BuildGraph ¶
BuildGraph converts the CHA call graph into the types.CallGraph used by the rest of buildgraph.
Rules:
- Every function whose package path starts with rootModule is "internal".
- Everything else is "external" (stdlib or third-party); we record the call but stop traversal there.
func (*Analyzer) ComputeHashes ¶
func (a *Analyzer) ComputeHashes( functions map[string]*types.Function, prevSourceHashes map[string]string, prevFuncHashes map[string]types.HashInfo, ) error
ComputeHashes fills in ASTHash and TransitiveHash for every function.
If prevSourceHashes and prevFuncHashes are non-nil (from a stored baseline), functions whose source file hash is unchanged have their AST hash reused from the baseline instead of being recomputed — a significant speedup for large codebases where only a few files change per commit.
func (*Analyzer) ComputeSourceHashes ¶
ComputeSourceHashes returns a map of relative file path → SHA-256 hash for every Go source file that was loaded during this analysis run. The map is stored in the baseline so that subsequent runs can detect which files have not changed and skip re-hashing their functions.
func (*Analyzer) ExtractExternalDeps ¶
ExtractExternalDeps parses the root go.mod and returns the require map plus a hash of the require block.