Help us shape the future of Go! Take the 2026 Go Developer Survey

ir

package
v5.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const MaxLoopAnalysisDepth = 64

MaxLoopAnalysisDepth prevents stack overflow attacks from deeply nested loops during IV normalization.

View Source
const MaxRenamerDepth = 20

Variables

View Source
var DefaultLiteralPolicy = LiteralPolicy{
	AbstractControlFlowComparisons: true,
	KeepSmallIntegerIndices:        true,
	KeepReturnStatusValues:         true,
	KeepStringLiterals:             false,
	SmallIntMin:                    -16,
	SmallIntMax:                    16,
	AbstractOtherTypes:             true,
}

DefaultLiteralPolicy preserves small integers used for indexing and status codes while masking magic numbers and large constants.

View Source
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.

Functions

func BuildSSAFromPackages

func BuildSSAFromPackages(initialPkgs []*packages.Package) (*ssa.Program, *ssa.Package, error)

BuildSSAFromPackages constructs Static Single Assignment form from loaded Go packages.

func FieldName added in v5.2.0

func FieldName(x ssa.Value, index int) string

FieldName names field index of x's struct type, where x is a struct or a pointer to one, as Field and FieldAddr select it. A field is identified by its name, not its position: reordering a struct's fields must not change a function that reads them, and reading a different field that moved into the old one's position must. Falls back to "#index" when x's type is not a struct.

func IsComparisonOp

func IsComparisonOp(op token.Token) bool

IsComparisonOp identifies strict comparison operators.

func IsConst

func IsConst(v ssa.Value, target constant.Value) bool

IsConst verifies if an ssa.Value is a constant equal to a given target.

func ReleaseCanonicalizer

func ReleaseCanonicalizer(c *Canonicalizer)

Types

type Canonicalizer

type Canonicalizer struct {
	Policy     LiteralPolicy
	StrictMode bool

	VirtualizedInstrs map[ssa.Instruction]bool
	// contains filtered or unexported fields
}

func AcquireCanonicalizer

func AcquireCanonicalizer(policy LiteralPolicy) *Canonicalizer

func NewCanonicalizer

func NewCanonicalizer(policy LiteralPolicy) *Canonicalizer

func (*Canonicalizer) AnalyzeLoops

func (c *Canonicalizer) AnalyzeLoops(fn *ssa.Function)

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

func (*Canonicalizer) NormalizeInductionVariables

func (c *Canonicalizer) NormalizeInductionVariables()

func (*Canonicalizer) NormalizeOperand

func (c *Canonicalizer) NormalizeOperand(v ssa.Value, context ssa.Instruction) string

type LiteralPolicy

type LiteralPolicy struct {
	AbstractControlFlowComparisons bool
	KeepSmallIntegerIndices        bool
	KeepReturnStatusValues         bool
	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.

func (*LiteralPolicy) IsSmallInt

func (p *LiteralPolicy) IsSmallInt(c constant.Value) bool

IsSmallInt checks if the constant fits within the configured small integer range.

func (*LiteralPolicy) ShouldAbstract

func (p *LiteralPolicy) ShouldAbstract(c *ssa.Const, usageContext ssa.Instruction) bool

ShouldAbstract decides whether a given constant should be replaced by a placeholder.

type TypeParamRenamer added in v5.2.0

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

TypeParamRenamer rewrites the type parameters in scope in a generic function, its receiver's and its enclosing functions', to placeholders named by position ("$0", "$1"), so a type-parameter rename such as List[T] to List[E] does not change how the function's types are rendered. It substitutes type objects rather than text, so a field, method or package-level type that shares a type parameter's name is left as is.

func NewTypeParamRenamer added in v5.2.0

func NewTypeParamRenamer(fn *ssa.Function) *TypeParamRenamer

NewTypeParamRenamer returns the renamer for fn, or nil when no type parameter is in scope; a nil renamer leaves every type unchanged.

func (*TypeParamRenamer) FuncName added in v5.2.0

func (r *TypeParamRenamer) FuncName(fn *ssa.Function, from *types.Package) string

FuncName is fn.RelString(from), except that the receiver type and type arguments in it are rendered from their types, so the type parameters r renames appear by position.

func (*TypeParamRenamer) Rename added in v5.2.0

func (r *TypeParamRenamer) Rename(t types.Type) types.Type

Rename returns t with every in-scope type parameter replaced by its placeholder, or t itself when it mentions none.

Jump to

Keyboard shortcuts

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