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

ir

package
v7.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 14 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 BuildProgram added in v7.5.0

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

BuildProgram builds the SSA program of the loaded packages: their bodies, and their dependencies' members without bodies. Package errors don't stop it, since SSA skips ill-typed packages, but it fails when the first package could not be built, with the packages' errors in the message.

func BuildSSAFromPackages deprecated

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

BuildSSAFromPackages is BuildProgram that also returns the first package's SSA package.

Deprecated: Use BuildProgram, and prog.Package(initialPkgs[0].Types) for the package.

func FieldName

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)

func StableFuncName

func StableFuncName(fn *ssa.Function) string

StableFuncName is fn.RelString(nil), except that a generic instance's receiver and type arguments are rendered as instanceType renders them, so the name does not depend on which caller SSA built the instance for first.

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

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

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

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, and an instance's as instanceType renders them.

func (*TypeParamRenamer) Rename

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