analysis

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package analysis loads Go packages, builds the SSA program, constructs the call graph, and pre-computes loop information that mem-guard heuristics consume.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnalyzedFunctions

func AnalyzedFunctions(ctx *Context) []*ssa.Function

AnalyzedFunctions returns all functions in the analyzed packages, including methods on named types and anonymous closures defined inside them.

Types

type Boundedness

type Boundedness int

Boundedness classifies whether a loop is provably bounded.

const (
	BoundUnknown   Boundedness = iota // assume unbounded (fail-open)
	BoundBounded                      // provably bounded
	BoundUnbounded                    // provably unbounded
)

func (Boundedness) String

func (b Boundedness) String() string

type Context

type Context struct {
	Prog      *ssa.Program
	Packages  []*ssa.Package
	CallGraph *callgraph.Graph
	LoopInfo  *LoopAnalysis
	Fset      *token.FileSet
}

Context bundles everything a heuristic needs to inspect a program.

func BuildContext

func BuildContext(patterns []string, dir string) (*Context, error)

BuildContext loads packages, builds SSA, constructs the call graph, and pre-computes loop information.

type LoopAnalysis

type LoopAnalysis struct {
	FuncLoops map[*ssa.Function][]*LoopDesc
}

LoopAnalysis stores pre-computed loop information for all functions.

func AnalyzeLoops

func AnalyzeLoops(prog *ssa.Program, pkgs []*ssa.Package) *LoopAnalysis

AnalyzeLoops detects and classifies all natural loops in the given packages.

func (*LoopAnalysis) InLoop

func (la *LoopAnalysis) InLoop(fn *ssa.Function, block *ssa.BasicBlock) []*LoopDesc

InLoop returns the loops that contain the given block in the given function.

type LoopDesc

type LoopDesc struct {
	Header    *ssa.BasicBlock
	BackEdges []*ssa.BasicBlock // blocks with back-edges to Header
	Body      blockSet          // all blocks in the loop body
	Bounded   Boundedness
	Kind      string // human-readable classification
}

LoopDesc describes a single natural loop detected in the CFG.

func (*LoopDesc) HasExitFromBlock

func (loop *LoopDesc) HasExitFromBlock(block *ssa.BasicBlock) bool

HasExitFromBlock checks if there's a conditional exit path from the given block that leads outside the loop. Used to check if a break/return guards a growth site.

func (*LoopDesc) IsUnbounded

func (loop *LoopDesc) IsUnbounded() bool

IsUnbounded returns true if the loop is not provably bounded.

Jump to

Keyboard shortcuts

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