analysis

package
v1.19.0-beta2 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2025 License: BSD-2-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BoolValue

func BoolValue(expr ast.Expr, info *types.Info) (bool, bool)

func EscapingObjects

func EscapingObjects(n ast.Node, info *types.Info) []*types.Var

func HasBreak

func HasBreak(n ast.Node) bool

func HasSideEffect

func HasSideEffect(n ast.Node, info *types.Info) bool

func PropagateAnalysis

func PropagateAnalysis(allInfo []*Info)

PropagateAnalysis will propagate analysis information across package boundaries to finish the analysis of a whole project.

Types

type FuncInfo

type FuncInfo struct {
	// HasDefer indicates if any defer statement exists in the function.
	HasDefer bool
	// Nodes are "flattened" into a switch-case statement when we need to be able
	// to jump into an arbitrary position in the code with a GOTO statement, or
	// resume a goroutine after a blocking call unblocks.
	Flattened map[ast.Node]bool
	// Blocking indicates that either the AST node itself or its descendant may
	// block goroutine execution (for example, a channel operation).
	Blocking map[ast.Node]bool
	// GotoLabel indicates a label referenced by a goto statement, rather than a
	// named loop.
	GotoLabel map[*types.Label]bool
	// contains filtered or unexported fields
}

func (*FuncInfo) IsBlocking

func (fi *FuncInfo) IsBlocking() bool

IsBlocking indicates if this function may block goroutine execution.

For example, a channel operation in a function or a call to another possibly blocking function may block the function.

func (*FuncInfo) TypeArgs

func (fi *FuncInfo) TypeArgs() typesutil.TypeList

TypeArgs gets the type arguments of this inside of a function instance or empty if not in a function instance.

func (*FuncInfo) Visit

func (fi *FuncInfo) Visit(node ast.Node) ast.Visitor

type Info

type Info struct {
	*types.Info
	Pkg *types.Package

	InstanceSets *typeparams.PackageInstanceSets
	HasPointer   map[*types.Var]bool

	InitFuncInfo *FuncInfo // Context for package variable initialization.
	// contains filtered or unexported fields
}

func AnalyzePkg

func AnalyzePkg(files []*ast.File, fileSet *token.FileSet, typesInfo *types.Info, typeCtx *types.Context, typesPkg *types.Package, instanceSets *typeparams.PackageInstanceSets, infoImporter InfoImporter) *Info

AnalyzePkg analyzes the given package for blocking calls, defers, etc.

Note that at the end of this call the analysis information has NOT been propagated across packages yet. Once all the packages have been analyzed, call PropagateAnalysis to propagate the information.

func (*Info) FuncInfo

func (info *Info) FuncInfo(inst typeparams.Instance) *FuncInfo

FuncInfo returns information about the given function declaration instance, or nil if not found.

func (*Info) FuncLitInfo

func (info *Info) FuncLitInfo(fun *ast.FuncLit, typeArgs typesutil.TypeList) *FuncInfo

FuncLitInfo returns information about the given function literal, or nil if not found. The given type arguments are used to identify the correct instance of the function literal in the case the literal was defined inside a generic function.

func (*Info) IsBlocking

func (info *Info) IsBlocking(inst typeparams.Instance) bool

IsBlocking returns true if the function may contain blocking calls or operations. If inst is from a different package, this will use the getImportInfo function to lookup the information from the other package.

func (*Info) VarsWithInitializers

func (info *Info) VarsWithInitializers() map[*types.Var]bool

VarsWithInitializers returns a set of package-level variables that have explicit initializers.

type InfoImporter

type InfoImporter func(path string) (*Info, error)

InfoImporter is used to get the `Info` for another package. The path is the resolved import path of the package to get the `Info` for.

Jump to

Keyboard shortcuts

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