analyzer

package
v0.2.0 Latest Latest
Warning

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

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

Documentation

Overview

Package analyzer loads Go packages with full type information and builds the internal representation used by the rest of the WASM compilation pipeline: call graph construction, closure computation, and AST transformation.

Key types:

  • AnalysisResult — loaded packages with all functions and entry points
  • Package — a loaded Go package with its ASTs and type information
  • FuncDecl — a function or method with resolved type information

Key functions:

  • LoadPackages — loads packages matching a pattern with full type info

Package analyzer loads Go packages, resolves types, and builds the internal representation used by the rest of the transformer pipeline.

Index

Constants

View Source
const (
	WasmTargetGOOS   = "wasip1"
	WasmTargetGOARCH = "wasm"
)

WASM build target constants.

LoadMode is the set of package load flags needed for full analysis.

Variables

This section is empty.

Functions

func ContainsNode

func ContainsNode(root, target ast.Node) bool

ContainsNode reports whether the AST subtree root contains the target node.

func FilenameConstrainedOut

func FilenameConstrainedOut(filename string) bool

FilenameConstrainedOut reports whether the given filename would be excluded for the WASM target based on its suffix alone. It is used by the closure validator to skip functions in platform-specific files.

func FindEnclosingFuncName

func FindEnclosingFuncName(files []*ast.File, target ast.Node) string

FindEnclosingFuncName returns the simple name of the function containing the given AST node, or "".

func FuncFQName

func FuncFQName(fn *types.Func) string

FuncFQName returns the fully-qualified name of a *types.Func in the same format used as keys in AnalysisResult.Funcs. For generic instantiations, it uses Origin() to return the type-parameter form (e.g., "*Container[T].Process" instead of "(*Container[string]).Process").

func HostCallsMethod

func HostCallsMethod(sel *types.Selection) bool

HostCallsMethod reports whether the given selection is a method call on a HostCalls value.

func ImplementsPluginCaller

func ImplementsPluginCaller(t types.Type) bool

ImplementsPluginCaller reports whether the given type implements the cleat.PluginCaller marker interface (has a cleatPlugin() method with no parameters and no return values).

func IsEntryPoint

func IsEntryPoint(fd *FuncDecl) bool

IsEntryPoint checks if a function is a workflow entry point. It must be exported, not a method, and have cleat.HostCalls as its first parameter.

func IsHostCallsType

func IsHostCallsType(t types.Type) bool

IsHostCallsType reports whether t is cleat.HostCalls (interface) or *cleat.HostCalls (pointer to struct, for backward compatibility).

func LastComponent

func LastComponent(path string) string

LastComponent returns the last component of a path (after the last '/').

func MatchWasmBuildConstraint

func MatchWasmBuildConstraint(filename string, content []byte) (bool, error)

MatchWasmBuildConstraint checks whether a Go source file should be included when building for the WASM target (GOOS=wasip1 GOARCH=wasm). It evaluates both filename-based constraints (e.g., *_linux.go, *_amd64.go) and //go:build constraints embedded in the file content.

filename is used for suffix-based constraint matching (e.g., foo_linux.go implies a GOOS=linux constraint). content is scanned for a //go:build line. Returns true if the file passes all constraints for the WASM target.

func PluginCallerMethod

func PluginCallerMethod(sel *types.Selection) bool

PluginCallerMethod reports whether the given selection is a method call on a type that implements the cleat.PluginCaller marker interface.

func ShortName

func ShortName(fqname string) string

ShortName returns the short function name from a fully-qualified name. "pkg.Func" → "Func", "(*pkg.Type).Method" → "Method".

func WasmFilenameWarnings

func WasmFilenameWarnings(filename string) []string

WasmFilenameWarnings inspects a .go filename and returns a non-empty suggestion string when the file is likely excluded by the compiler due to its suffix for the WASM target.

Types

type AnalysisResult

type AnalysisResult struct {
	TargetPkg   *Package
	UserPkgs    []*Package
	Funcs       map[string]*FuncDecl // keyed by fully-qualified name
	EntryPoints []string             // fully-qualified names of entry points

	// Module information.
	ModulePath string // e.g., "github.com/cleat-team/cleat"
	ModuleDir  string // absolute path to module root (where go.mod lives)
	GoVersion  string // e.g., "1.26" from go.mod

	// Statistics
	NumFuncs          int
	NumExported       int
	NumDurableLeaves  int
	NumDurableClosure int
	NumPure           int
}

AnalysisResult holds the complete analysis of a workflow package.

func LoadPackages

func LoadPackages(pattern string, fset *token.FileSet) (*AnalysisResult, error)

LoadPackages loads the packages matching the given pattern and returns the analysis result with all functions, types, and entry points identified.

type FuncDecl

type FuncDecl struct {
	Name     string           // simple name (e.g. "PlaceOrder")
	Pkg      *Package         // the package this function belongs to
	Ast      *ast.FuncDecl    // the AST node
	Type     *types.Signature // the type-checked signature
	RecvType types.Type       // non-nil for methods (the receiver type)

	// IsExported is true for capitalized function names.
	IsExported bool

	// IsEntryPoint is true if this function is a workflow entry point
	// (exported, first param is cleat.HostCalls, in root of target package).
	IsEntryPoint bool

	// IsDurableLeaf is true if this function directly calls a HostCalls method.
	IsDurableLeaf bool

	// InDurableClosure is true if this function transitively calls a cleat leaf.
	InDurableClosure bool

	// DurabilityTag is one of "DurableLeaf", "DurableClosure", or "Pure".
	DurabilityTag string

	// AutoThreaded is true if the transform added h cleat.HostCalls as
	// the first parameter to this function.
	AutoThreaded bool
}

FuncDecl represents a function or method with its resolved type information.

func (*FuncDecl) FullyQualifiedName

func (f *FuncDecl) FullyQualifiedName() string

FullyQualifiedName returns the fully-qualified name for a function, e.g. "workflows.PlaceOrder" or "(*workflows.OrderProcessor).Process".

type Package

type Package struct {
	Name  string
	Path  string
	Dir   string
	Files []*ast.File
	Fset  *token.FileSet
	Types *types.Package
	Info  *types.Info
}

Package represents a loaded Go package with its ASTs and type information.

Jump to

Keyboard shortcuts

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