analyzer

package
v0.0.0-alpha.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 20, 2026 License: MIT Imports: 18 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func HashGoMod

func HashGoMod(gomod *GoMod) string

HashGoMod returns a sha256 of all require entries, sorted, so any version bump changes the hash.

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 New

func New(cfg *config.Config, rootModule, rootPath string) *Analyzer

func (*Analyzer) BuildGraph

func (a *Analyzer) BuildGraph() (map[string]*types.Function, *types.CallGraph, error)

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

func (a *Analyzer) ComputeSourceHashes() (map[string]string, error)

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

func (a *Analyzer) ExtractExternalDeps() (map[string]string, string, error)

ExtractExternalDeps parses the root go.mod and returns the require map plus a hash of the require block.

func (*Analyzer) Load

func (a *Analyzer) Load() error

Load discovers all packages under services/ and core/, loads them with full type information, builds SSA, and runs CHA to produce a call graph.

type GoMod

type GoMod struct {
	Module  string
	GoVer   string
	Require map[string]string // import path -> version
}

GoMod holds the parsed content of a go.mod file.

func ParseGoMod

func ParseGoMod(goModPath string) (*GoMod, error)

ParseGoMod parses a go.mod file and returns structured dependency info.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL