ssax

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package ssax holds small shared helpers for inspecting SSA values and call sites: callee identification, best-effort string-constant resolution, and variadic-argument extraction. Used by entrypoint discovery and effect detection.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConcreteMethod

func ConcreteMethod(prog *ssa.Program, v ssa.Value, name string) *ssa.Function

ConcreteMethod finds the named method on the concrete type behind an interface-typed value (the operand of its MakeInterface), e.g. the ServeHTTP of a handler passed to http.Handle.

func ConstString

func ConstString(v ssa.Value) (string, bool)

ConstString resolves v to a string constant if it is one, a conversion of one, or a package-level variable stored exactly once (in init) with one. Returns "", false when the value is dynamic.

func Declared

func Declared(prog *ssa.Program, fn *ssa.Function) *ssa.Function

Declared maps synthetic wrappers (indirection/promotion/bound wrappers) to the declared function they forward to.

func FieldStore added in v0.2.0

func FieldStore(fa *ssa.FieldAddr) ssa.Value

FieldStore is packageFieldStore for callers outside this package: the value stored into the struct field fa addresses, when exactly one such store exists program-wide. It resolves the field a constructor assigned once, for values that reach a call site through a struct rather than a local.

func FuncDisplayName

func FuncDisplayName(fn *ssa.Function) string

FuncDisplayName returns the stable qualified name of fn, using the generic origin so instantiations do not multiply identities.

func IsErrorType

func IsErrorType(t types.Type) bool

func NormalizePkg

func NormalizePkg(path string) string

NormalizePkg strips a trailing /vN major-version suffix so matchers cover all major versions of a library with one entry.

func ReachingStore

func ReachingStore(load *ssa.UnOp, addr ssa.Value) ssa.Value

ReachingStore finds the store to addr nearest before the load, walking backwards through the load's block and then through single-predecessor blocks. Sound for the return-site pattern (store result; maybe rundefers; load result; return); gives up on merges rather than guessing.

func ResolveFuncValue

func ResolveFuncValue(v ssa.Value) *ssa.Function

ResolveFuncValue chases a function-typed value to its *ssa.Function: direct references, closures, and conversions such as http.HandlerFunc(f).

func SentinelErrors

func SentinelErrors(fn *ssa.Function) []string

SentinelErrors reports the named error outcomes fn can return: sentinel globals (return nil, ErrOrderNotFound), methods chained on sentinel globals (errs.OrderNotFound.WithDetails(...)), and constant errors.New / fmt.Errorf messages. Propagated errors from callees are deliberately ignored - they surface on the callee's own node. These are the business branch points a flow reader cares about.

func SingleStore

func SingleStore(addr ssa.Value) ssa.Value

SingleStore returns the value stored to addr if exactly one store to it exists in the enclosing function (for locals/field addresses) or in the package init (for globals). Returns nil otherwise.

func SliceStrings

func SliceStrings(v ssa.Value) ([]string, bool)

SliceStrings resolves a []string-typed value built from constants (either a vararg pack or a literal) to its elements. ok is false if any element is dynamic.

func StructFieldString

func StructFieldString(v ssa.Value, field string) (string, bool)

StructFieldString resolves the named field of a struct-typed value to a string constant. It handles the common composite-literal shape: a load of an *ssa.Alloc whose FieldAddrs were stored exactly once. This is how Kafka writer/reader topics configured via config structs resolve.

func TrimModule

func TrimModule(name, module string) string

TrimModule shortens a qualified function name relative to a module path: "(*example.com/m/svc.Service).Create" -> "(*svc.Service).Create".

func VarargValues

func VarargValues(v ssa.Value) []ssa.Value

VarargValues unpacks the values passed through a final variadic argument (an *ssa.Slice over an *ssa.Alloc), in index order. Returns nil when the slice is not a literal vararg pack (e.g. a forwarded []T).

Types

type CalleeInfo

type CalleeInfo struct {
	Pkg    string        // package path of the callee (or its interface)
	Type   string        // receiver or interface type name, "" for package funcs
	Name   string        // function or method name
	Invoke bool          // true for interface dispatch
	Static *ssa.Function // non-nil for statically resolved callees
	// ArgOffset is the index of the first non-receiver argument in
	// site.Common().Args.
	ArgOffset int
}

CalleeInfo identifies what a call site calls, uniformly for static calls and interface (invoke-mode) calls.

func Callee

func Callee(site ssa.CallInstruction) *CalleeInfo

Callee extracts CalleeInfo from a call site. Returns nil for calls to builtins and for dynamic calls of function values.

Jump to

Keyboard shortcuts

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