Documentation
¶
Index ¶
- Variables
- func AnalyzeSCEV(info *LoopInfo)
- func BuildSSAFromPackages(initialPkgs []*packages.Package) (*ssa.Program, *ssa.Package, error)
- func ReleaseCanonicalizer(c *Canonicalizer)
- type Canonicalizer
- type FingerprintResult
- func FingerprintPackages(initialPkgs []*packages.Package, policy LiteralPolicy, strictMode bool) ([]FingerprintResult, error)
- func FingerprintSource(filename string, src string, policy LiteralPolicy) ([]FingerprintResult, error)
- func FingerprintSourceAdvanced(filename string, src string, policy LiteralPolicy, strictMode bool) ([]FingerprintResult, error)
- func GenerateFingerprint(fn *ssa.Function, policy LiteralPolicy, strictMode bool) FingerprintResult
- type IVType
- type InductionVariable
- type LiteralPolicy
- type Loop
- type LoopInfo
- type Renamer
- type SCEV
- type SCEVAddRec
- func (s *SCEVAddRec) EvaluateAt(k *big.Int) *big.Int
- func (s *SCEVAddRec) IsLoopInvariant(loop *Loop) bool
- func (s *SCEVAddRec) Name() string
- func (s *SCEVAddRec) Parent() *ssa.Function
- func (s *SCEVAddRec) Pos() token.Pos
- func (s *SCEVAddRec) Referrers() *[]ssa.Instruction
- func (s *SCEVAddRec) String() string
- func (s *SCEVAddRec) StringWithRenamer(r Renamer) string
- func (s *SCEVAddRec) Type() types.Type
- type SCEVConstant
- func (s *SCEVConstant) EvaluateAt(k *big.Int) *big.Int
- func (s *SCEVConstant) IsLoopInvariant(loop *Loop) bool
- func (s *SCEVConstant) Name() string
- func (s *SCEVConstant) Parent() *ssa.Function
- func (s *SCEVConstant) Pos() token.Pos
- func (s *SCEVConstant) Referrers() *[]ssa.Instruction
- func (s *SCEVConstant) String() string
- func (s *SCEVConstant) StringWithRenamer(r Renamer) string
- func (s *SCEVConstant) Type() types.Type
- type SCEVGenericExpr
- func (s *SCEVGenericExpr) EvaluateAt(k *big.Int) *big.Int
- func (s *SCEVGenericExpr) IsLoopInvariant(loop *Loop) bool
- func (s *SCEVGenericExpr) Name() string
- func (s *SCEVGenericExpr) Parent() *ssa.Function
- func (s *SCEVGenericExpr) Pos() token.Pos
- func (s *SCEVGenericExpr) Referrers() *[]ssa.Instruction
- func (s *SCEVGenericExpr) String() string
- func (s *SCEVGenericExpr) StringWithRenamer(r Renamer) string
- func (s *SCEVGenericExpr) Type() types.Type
- type SCEVUnknown
- func (s *SCEVUnknown) EvaluateAt(k *big.Int) *big.Int
- func (s *SCEVUnknown) IsLoopInvariant(loop *Loop) bool
- func (s *SCEVUnknown) Name() string
- func (s *SCEVUnknown) Parent() *ssa.Function
- func (s *SCEVUnknown) Pos() token.Pos
- func (s *SCEVUnknown) Referrers() *[]ssa.Instruction
- func (s *SCEVUnknown) String() string
- func (s *SCEVUnknown) StringWithRenamer(r Renamer) string
- func (s *SCEVUnknown) Type() types.Type
- type Zipper
- type ZipperArtifacts
Constants ¶
This section is empty.
Variables ¶
var DefaultLiteralPolicy = LiteralPolicy{ AbstractControlFlowComparisons: true, KeepSmallIntegerIndices: true, KeepReturnStatusValues: true, KeepStringLiterals: false, SmallIntMin: -16, SmallIntMax: 16, AbstractOtherTypes: true, }
DefaultLiteralPolicy represents the standard policy for fingerprinting; it preserves small integers used for indexing and status codes while masking magic numbers and large constants.
var KeepAllLiteralsPolicy = LiteralPolicy{ AbstractControlFlowComparisons: false, KeepSmallIntegerIndices: true, KeepReturnStatusValues: true, KeepStringLiterals: true, SmallIntMin: math.MinInt64, SmallIntMax: math.MaxInt64, AbstractOtherTypes: false, }
KeepAllLiteralsPolicy is designed for testing or exact matching by disabling most abstractions and expanding the "small" integer range to the full int64 spectrum.
Functions ¶
func AnalyzeSCEV ¶
func AnalyzeSCEV(info *LoopInfo)
AnalyzeSCEV is the main entry point for SCEV analysis on a LoopInfo.
func BuildSSAFromPackages ¶
Constructs the Static Single Assignment form from loaded Go packages. Provides the complete program and the target package for analysis.
func ReleaseCanonicalizer ¶
func ReleaseCanonicalizer(c *Canonicalizer)
Types ¶
type Canonicalizer ¶
type Canonicalizer struct {
Policy LiteralPolicy
StrictMode bool
// contains filtered or unexported fields
}
Canonicalizer transforms an SSA function into a deterministic string representation.
func AcquireCanonicalizer ¶
func AcquireCanonicalizer(policy LiteralPolicy) *Canonicalizer
func NewCanonicalizer ¶
func NewCanonicalizer(policy LiteralPolicy) *Canonicalizer
func (*Canonicalizer) ApplyVirtualControlFlowFromState ¶
func (c *Canonicalizer) ApplyVirtualControlFlowFromState(swappedBlocks map[*ssa.BasicBlock]bool, virtualBinOps map[*ssa.BinOp]token.Token)
func (*Canonicalizer) CanonicalizeFunction ¶
func (c *Canonicalizer) CanonicalizeFunction(fn *ssa.Function) string
type FingerprintResult ¶
type FingerprintResult struct {
FunctionName string
Fingerprint string
CanonicalIR string
Pos token.Pos
Line int
Filename string
// contains filtered or unexported fields
}
Encapsulates the output of the semantic fingerprinting process for a function.
func FingerprintPackages ¶
func FingerprintPackages(initialPkgs []*packages.Package, policy LiteralPolicy, strictMode bool) ([]FingerprintResult, error)
FingerprintPackages iterates over loaded packages to construct SSA and generate results.
func FingerprintSource ¶
func FingerprintSource(filename string, src string, policy LiteralPolicy) ([]FingerprintResult, error)
FingerprintSource analyzes a single Go source file provided as a string. This is the primary entry point for verifying code snippets or patch hunks.
func FingerprintSourceAdvanced ¶
func FingerprintSourceAdvanced(filename string, src string, policy LiteralPolicy, strictMode bool) ([]FingerprintResult, error)
FingerprintSourceAdvanced provides an extended interface for source analysis with strict mode control.
func GenerateFingerprint ¶
func GenerateFingerprint(fn *ssa.Function, policy LiteralPolicy, strictMode bool) FingerprintResult
GenerateFingerprint generates the hash and canonical string representation for an SSA function. This function uses a pooled Canonicalizer to ensure high throughput and low allocation overhead.
func (FingerprintResult) GetSSAFunction ¶ added in v1.1.0
func (r FingerprintResult) GetSSAFunction() *ssa.Function
GetSSAFunction returns the underlying SSA function for advanced analysis workflows such as semantic diffing with the Zipper algorithm. Returns nil if not available.
type InductionVariable ¶
type InductionVariable struct {
Phi *ssa.Phi
Type IVType
Start SCEV // Value at iteration 0
Step SCEV // Update stride
}
InductionVariable describes a detected IV. Reference: Section 3.2 Classification Taxonomy.
type LiteralPolicy ¶
type LiteralPolicy struct {
AbstractControlFlowComparisons bool
KeepSmallIntegerIndices bool
KeepReturnStatusValues bool
// FIX: Added flag to keep string literals.
KeepStringLiterals bool
SmallIntMin int64
SmallIntMax int64
AbstractOtherTypes bool
}
LiteralPolicy defines the configurable strategy for determining which literal values should be abstracted into placeholders during canonicalization. It allows fine grained control over integer abstraction in different contexts.
func (*LiteralPolicy) ShouldAbstract ¶
func (p *LiteralPolicy) ShouldAbstract(c *ssa.Const, usageContext ssa.Instruction) bool
decides whether a given constant should be replaced by a generic placeholder. It analyzes the constant's type, value, and immediate usage context in the SSA graph.
type Loop ¶
type Loop struct {
Header *ssa.BasicBlock
Latch *ssa.BasicBlock // Primary source of the backedge
// Blocks contains all basic blocks within the loop body.
Blocks map[*ssa.BasicBlock]bool
// Exits contains blocks inside the loop that have successors outside.
Exits []*ssa.BasicBlock
// Hierarchy
Parent *Loop
Children []*Loop
// Semantic Analysis (populated in scev.go)
Inductions map[*ssa.Phi]*InductionVariable
TripCount SCEV // Symbolic expression
}
Loop represents a natural loop in the SSA graph. Reference: Section 2.3 Natural Loops.
type LoopInfo ¶
type LoopInfo struct {
Function *ssa.Function
Loops []*Loop // Top-level loops (roots of the hierarchy)
// Map from Header block to Loop object for O(1) lookup
LoopMap map[*ssa.BasicBlock]*Loop
}
LoopInfo summarizes loop analysis for a single function.
func DetectLoops ¶
DetectLoops reconstructs the loop hierarchy using dominance relations. Reference: Section 2.3.1 Algorithm: Detecting Natural Loops.
type Renamer ¶
Renamer is a function that maps an SSA value to its canonical name. This is used to ensure deterministic output regardless of SSA register naming.
type SCEV ¶
type SCEV interface {
ssa.Value
EvaluateAt(k *big.Int) *big.Int
IsLoopInvariant(loop *Loop) bool
String() string
// StringWithRenamer returns a canonical string using the provided renamer
// function to map SSA values to their canonical names (e.g., v0, v1).
// This is critical for determinism: without it, raw SSA names (t0, t1)
// would leak into fingerprints, breaking semantic equivalence.
StringWithRenamer(r Renamer) string
}
SCEV represents a scalar expression.
type SCEVAddRec ¶
SCEVAddRec represents an Add Recurrence: {Start, +, Step}_L Reference: Section 4.1 The Add Recurrence Abstraction.
func (*SCEVAddRec) EvaluateAt ¶
func (s *SCEVAddRec) EvaluateAt(k *big.Int) *big.Int
func (*SCEVAddRec) IsLoopInvariant ¶
func (s *SCEVAddRec) IsLoopInvariant(loop *Loop) bool
func (*SCEVAddRec) Parent ¶
func (s *SCEVAddRec) Parent() *ssa.Function
func (*SCEVAddRec) Pos ¶
func (s *SCEVAddRec) Pos() token.Pos
func (*SCEVAddRec) Referrers ¶
func (s *SCEVAddRec) Referrers() *[]ssa.Instruction
func (*SCEVAddRec) String ¶
func (s *SCEVAddRec) String() string
func (*SCEVAddRec) StringWithRenamer ¶
func (s *SCEVAddRec) StringWithRenamer(r Renamer) string
func (*SCEVAddRec) Type ¶
func (s *SCEVAddRec) Type() types.Type
type SCEVConstant ¶
SCEVConstant represents a literal integer constant.
func SCEVFromConst ¶
func SCEVFromConst(c *ssa.Const) *SCEVConstant
func (*SCEVConstant) EvaluateAt ¶
func (s *SCEVConstant) EvaluateAt(k *big.Int) *big.Int
func (*SCEVConstant) IsLoopInvariant ¶
func (s *SCEVConstant) IsLoopInvariant(loop *Loop) bool
func (*SCEVConstant) Parent ¶
func (s *SCEVConstant) Parent() *ssa.Function
func (*SCEVConstant) Pos ¶
func (s *SCEVConstant) Pos() token.Pos
func (*SCEVConstant) Referrers ¶
func (s *SCEVConstant) Referrers() *[]ssa.Instruction
func (*SCEVConstant) String ¶
func (s *SCEVConstant) String() string
func (*SCEVConstant) StringWithRenamer ¶
func (s *SCEVConstant) StringWithRenamer(r Renamer) string
func (*SCEVConstant) Type ¶
func (s *SCEVConstant) Type() types.Type
type SCEVGenericExpr ¶
SCEVGenericExpr represents binary operations like Add/Mul for formulas.
func (*SCEVGenericExpr) EvaluateAt ¶
func (s *SCEVGenericExpr) EvaluateAt(k *big.Int) *big.Int
func (*SCEVGenericExpr) IsLoopInvariant ¶
func (s *SCEVGenericExpr) IsLoopInvariant(loop *Loop) bool
func (*SCEVGenericExpr) Parent ¶
func (s *SCEVGenericExpr) Parent() *ssa.Function
func (*SCEVGenericExpr) Pos ¶
func (s *SCEVGenericExpr) Pos() token.Pos
func (*SCEVGenericExpr) Referrers ¶
func (s *SCEVGenericExpr) Referrers() *[]ssa.Instruction
func (*SCEVGenericExpr) String ¶
func (s *SCEVGenericExpr) String() string
func (*SCEVGenericExpr) StringWithRenamer ¶
func (s *SCEVGenericExpr) StringWithRenamer(r Renamer) string
func (*SCEVGenericExpr) Type ¶
func (s *SCEVGenericExpr) Type() types.Type
type SCEVUnknown ¶
type SCEVUnknown struct {
Value ssa.Value
IsInvariant bool // Explicitly tracks invariance relative to the analysis loop scope
}
SCEVUnknown represents a symbolic value (e.g., parameter or unanalyzable instr).
func (*SCEVUnknown) EvaluateAt ¶
func (s *SCEVUnknown) EvaluateAt(k *big.Int) *big.Int
func (*SCEVUnknown) IsLoopInvariant ¶
func (s *SCEVUnknown) IsLoopInvariant(loop *Loop) bool
func (*SCEVUnknown) Parent ¶
func (s *SCEVUnknown) Parent() *ssa.Function
func (*SCEVUnknown) Pos ¶
func (s *SCEVUnknown) Pos() token.Pos
func (*SCEVUnknown) Referrers ¶
func (s *SCEVUnknown) Referrers() *[]ssa.Instruction
func (*SCEVUnknown) String ¶
func (s *SCEVUnknown) String() string
func (*SCEVUnknown) StringWithRenamer ¶
func (s *SCEVUnknown) StringWithRenamer(r Renamer) string
func (*SCEVUnknown) Type ¶
func (s *SCEVUnknown) Type() types.Type
type Zipper ¶ added in v1.1.0
type Zipper struct {
// contains filtered or unexported fields
}
Zipper implements the semantic delta analysis algorithm.
func NewZipper ¶ added in v1.1.0
func NewZipper(oldFn, newFn *ssa.Function, policy LiteralPolicy) (*Zipper, error)
NewZipper creates a new analysis session.
func (*Zipper) ComputeDiff ¶ added in v1.1.0
func (z *Zipper) ComputeDiff() (*ZipperArtifacts, error)
ComputeDiff executes the Zipper Algorithm Phases.