concutils

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package concutils provides shared utilities for detecting and analyzing Go concurrency primitives (sync.Mutex, sync.WaitGroup, channels) in source code. It is used as a foundation by all gostall analyzers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Deref

func Deref(t types.Type) types.Type

Deref strips all pointer indirections from a type.

func ImportsSyncPackage

func ImportsSyncPackage(pkg *types.Package) bool

ImportsSyncPackage reports whether pkg directly imports "sync". Analyzers use this as an early-exit optimization.

func IsInGoStmt

func IsInGoStmt(stack []ast.Node) bool

IsInGoStmt reports whether any ancestor in the AST stack is a *ast.GoStmt.

func IsMutexType

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

IsMutexType reports whether the type of expr is sync.Mutex, sync.RWMutex, or a struct that embeds one of them (supporting s.Lock() via promotion).

func IsSyncMethod

func IsSyncMethod(info *types.Info, call *ast.CallExpr, typeName, methodName string) bool

IsSyncMethod checks whether call targets typeName.methodName from the "sync" package.

func IsWaitGroupType

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

IsWaitGroupType reports whether the receiver of expr is sync.WaitGroup.

func ResolveAddDelta

func ResolveAddDelta(info *types.Info, call *ast.CallExpr) int

ResolveAddDelta extracts the integer constant from a wg.Add(n) call. Returns 0 if the argument is not a compile-time constant.

func ResolveExprID

func ResolveExprID(info *types.Info, expr ast.Expr) string

ResolveExprID produces a best-effort stable string identifier for an expression. It handles identifiers, selectors (s.mu), dereferences (*p), and index expressions.

Limitation: array/slice index expressions are collapsed to "[i]", so arr[0].mu and arr[1].mu produce the same ID. This is a known trade-off for Phase 1; full points-to analysis is deferred to Phase 2.

Types

type ChanOp

type ChanOp struct {
	Node   ast.Node
	ChanID string
	IsSend bool
	InGo   bool // true if nested inside a go statement
}

ChanOp represents a channel send or receive operation.

func ExtractChanOps

func ExtractChanOps(insp *inspector.Inspector, info *types.Info) []ChanOp

ExtractChanOps traverses the AST and returns all channel send and receive operations, annotating whether each occurs inside a go statement.

type LockOp

type LockOp struct {
	Call    *ast.CallExpr
	MutexID string
	IsLock  bool      // true for Lock/RLock, false for Unlock/RUnlock
	IsRead  bool      // true for RLock/RUnlock
	Pos     token.Pos // position of the call expression
}

LockOp represents a mutex lock or unlock operation found in source code.

func ExtractLockOps

func ExtractLockOps(insp *inspector.Inspector, info *types.Info) []LockOp

ExtractLockOps traverses the AST via the inspector and returns all sync.Mutex / sync.RWMutex lock and unlock operations.

type WGOp

type WGOp struct {
	Call   *ast.CallExpr
	WGID   string
	Method string // "Add", "Done", or "Wait"
	InGo   bool   // true if nested inside a go statement
	Delta  int    // resolved integer argument for Add; -1 for Done; 0 if unknown
}

WGOp represents a sync.WaitGroup method call.

func ExtractWaitGroupOps

func ExtractWaitGroupOps(insp *inspector.Inspector, info *types.Info) []WGOp

ExtractWaitGroupOps traverses the AST and returns all sync.WaitGroup Add, Done, and Wait calls, annotating goroutine context.

Jump to

Keyboard shortcuts

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