diff

package
v4.1.0 Latest Latest
Warning

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

Go to latest
Published: May 24, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const MaxCandidates = 100
View Source
const MaxFunctionBlocks = 5000

Variables

This section is empty.

Functions

func FingerprintTree added in v4.1.0

func FingerprintTree(rootDir string, fileFilter func(string) bool, policy ir.LiteralPolicy) ([]FingerprintResult, LoadMeta, error)

FingerprintTree fingerprints Go source under rootDir using a tree-mode load. If a real go.mod is found at or above rootDir, it's used directly. Otherwise a synthetic go.mod is supplied via packages.Config.Overlay (no disk write) so the loader has a canonical module path to resolve through — this fixes the qualifier-corruption case where types.Type.String() would otherwise carry a temp-dir-synthesized path.

fileFilter, if non-nil, keeps only function fingerprints whose source file satisfies the predicate. Use it to avoid fingerprinting the whole tree when the caller only cares about a subset (e.g., changed files in a diff).

GOPROXY=off is preserved via GetHardenedEnv(); files that import external modules without resolvable deps will still parse-fail by design.

KNOWN LIMITATION — same-module sub-package imports in real multi-package trees: when no real go.mod is found, the synthetic go.mod declares module "synthetic.local/anonymous" (see syntheticModulePath). For self-contained single-package trees (the synthetic-corpus shape this code was first validated against) this is fine — no imports need to resolve through the module path. For real multi-package modules whose internal files import other sub-packages of the same module (e.g., github.com/google/go-cmp's cmp/compare.go importing github.com/google/go-cmp/cmp/internal/diff), the synthetic module identity does NOT match the import paths declared in source, so the sub-package lookup fails with "cannot find module providing package <real-module-path>/<subpath>" even though the sub-package's source is present on disk in the tree.

Verified by real-corpus triage of the 3 genuine same-package-sibling commits in the pilot (go-cmp 8ebdfab3, x/text c8872a1a, x/text db455d00): in each case the failing sub-package directory EXISTS at the worktree- root-relative path that the real import declares, so a synthesized go.mod declaring the REAL module name placed at the worktree root would resolve the imports correctly. The fix shape — adding a moduleNameHint parameter and loading the target package(s) by module-relative path from the tree root — is mechanism-verified but implementation-deferred. Affected corpus: pre-modules-era multi-package trees (modern commits carry their own go.mod and don't go through this synthesis path).

func FingerprintTreeAdvanced added in v4.1.0

func FingerprintTreeAdvanced(rootDir string, fileFilter func(string) bool, policy ir.LiteralPolicy, strictMode bool) ([]FingerprintResult, LoadMeta, error)

FingerprintTreeAdvanced is the strict-mode variant of FingerprintTree.

func GetHardenedEnv

func GetHardenedEnv() []string

func IsCommutativeOp

func IsCommutativeOp(op token.Token) bool

func MatchFunctionsByTopology

func MatchFunctionsByTopology(oldResults, newResults []FingerprintResult, threshold float64) (
	matched []TopologyMatch,
	addedFuncs []FingerprintResult,
	removedFuncs []FingerprintResult,
)

func ShortFuncName

func ShortFuncName(fullName string) string

Types

type FingerprintResult

type FingerprintResult struct {
	FunctionName string
	Fingerprint  string
	CanonicalIR  string
	Pos          token.Pos
	Line         int
	Filename     string
	// contains filtered or unexported fields
}

func FingerprintPackages

func FingerprintPackages(initialPkgs []*packages.Package, policy ir.LiteralPolicy, strictMode bool) ([]FingerprintResult, error)

func FingerprintSource

func FingerprintSource(filename string, src string, policy ir.LiteralPolicy) ([]FingerprintResult, error)

func FingerprintSourceAdvanced

func FingerprintSourceAdvanced(filename string, src string, policy ir.LiteralPolicy, strictMode bool) ([]FingerprintResult, error)

func GenerateFingerprint

func GenerateFingerprint(fn *ssa.Function, policy ir.LiteralPolicy, strictMode bool) FingerprintResult

func (FingerprintResult) GetSSAFunction

func (r FingerprintResult) GetSSAFunction() *ssa.Function

type LoadMeta added in v4.1.0

type LoadMeta struct {
	HadGoMod         bool     // real go.mod found at or above rootDir
	SynthesizedGoMod bool     // loader supplied a synthetic go.mod via overlay
	ModulePath       string   // module path used for resolution (real or synthetic)
	LoadErrors       []string // per-package errors encountered during Load
}

LoadMeta records what the tree loader did for a particular FingerprintTree invocation. Carried alongside results so callers can tag analysis output with whether a real go.mod was found or whether one was synthesized.

type TopologyMatch

type TopologyMatch struct {
	OldResult   FingerprintResult
	NewResult   FingerprintResult
	OldTopology *topology.FunctionTopology
	NewTopology *topology.FunctionTopology
	Similarity  float64
	ByName      bool
}

type Zipper

type Zipper struct {
	// contains filtered or unexported fields
}

Zipper implements the semantic delta analysis algorithm.

func NewZipper

func NewZipper(oldFn, newFn *ssa.Function, policy ir.LiteralPolicy) (*Zipper, error)

func (*Zipper) ComputeDiff

func (z *Zipper) ComputeDiff() (*ZipperArtifacts, error)

type ZipperArtifacts

type ZipperArtifacts struct {
	OldFunction  string
	NewFunction  string
	MatchedNodes int
	Added        []string
	Removed      []string
	Preserved    bool
}

ZipperArtifacts contains the results of the semantic delta analysis.

Jump to

Keyboard shortcuts

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