Documentation
¶
Index ¶
- Constants
- func FingerprintTree(rootDir string, fileFilter func(string) bool, policy ir.LiteralPolicy) ([]FingerprintResult, LoadMeta, error)
- func FingerprintTreeAdvanced(rootDir string, fileFilter func(string) bool, policy ir.LiteralPolicy, ...) ([]FingerprintResult, LoadMeta, error)
- func FingerprintTreeWithOptions(rootDir string, fileFilter func(string) bool, policy ir.LiteralPolicy, ...) ([]FingerprintResult, LoadMeta, error)
- func GetHardenedEnv() []string
- func IsCommutativeOp(op token.Token) bool
- func MatchFunctionsByTopology(oldResults, newResults []FingerprintResult, threshold float64) (matched []TopologyMatch, addedFuncs []FingerprintResult, ...)
- func ShortFuncName(fullName string) string
- type FingerprintResult
- func FingerprintPackages(initialPkgs []*packages.Package, policy ir.LiteralPolicy, strictMode bool) ([]FingerprintResult, error)
- func FingerprintSource(filename string, src string, policy ir.LiteralPolicy) ([]FingerprintResult, error)
- func FingerprintSourceAdvanced(filename string, src string, policy ir.LiteralPolicy, strictMode bool) ([]FingerprintResult, error)
- func GenerateFingerprint(fn *ssa.Function, policy ir.LiteralPolicy, strictMode bool) FingerprintResult
- type LoadMeta
- type TopologyMatch
- type TreeLoadOptions
- type Zipper
- type ZipperArtifacts
Constants ¶
const MaxCandidates = 100
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 FingerprintTreeWithOptions ¶ added in v4.2.0
func FingerprintTreeWithOptions(rootDir string, fileFilter func(string) bool, policy ir.LiteralPolicy, opts TreeLoadOptions) ([]FingerprintResult, LoadMeta, error)
FingerprintTreeWithOptions is the options-driven variant of FingerprintTree. Use this to configure GOPROXY (e.g. to allow downloading missing dependencies) or to supply a module name hint for pre-modules-era source trees that have no go.mod. The zero TreeLoadOptions value is identical to calling FingerprintTree.
func GetHardenedEnv ¶
func GetHardenedEnv() []string
func IsCommutativeOp ¶
func MatchFunctionsByTopology ¶
func MatchFunctionsByTopology(oldResults, newResults []FingerprintResult, threshold float64) ( matched []TopologyMatch, addedFuncs []FingerprintResult, removedFuncs []FingerprintResult, )
func ShortFuncName ¶
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 TreeLoadOptions ¶ added in v4.2.0
type TreeLoadOptions struct {
// Proxy overrides the GOPROXY setting passed to the Go toolchain during
// tree loading. If empty, the hardened default ("off") is used, which
// prevents any external network access. Set to a proxy URL (e.g.
// "https://proxy.golang.org,direct") when analysing source trees whose
// declared dependencies are not yet cached in GOMODCACHE. All other
// hardening applied by GetHardenedEnv (CGO_ENABLED=0, GOWORK=off, etc.)
// remains in effect regardless of this field.
Proxy string
// ModuleNameHint is used as the module path in the synthesised go.mod
// when a source tree has no real go.mod. If empty, the stable default
// "synthetic.local/anonymous" is used. Setting this to the tree's actual
// module path (e.g. "github.com/spf13/cobra") resolves same-module
// sub-package imports correctly in pre-modules-era multi-package trees.
ModuleNameHint string
}
TreeLoadOptions customises the tree-mode loader. The zero value is safe and matches the behaviour of FingerprintTree/FingerprintTreeAdvanced (secure hardened defaults: GOPROXY=off, synthetic module path for no-go.mod trees).
type Zipper ¶
type Zipper struct {
// contains filtered or unexported fields
}
Zipper implements the semantic delta analysis algorithm.
func (*Zipper) ComputeDiff ¶
func (z *Zipper) ComputeDiff() (*ZipperArtifacts, error)