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
- func ContainsNode(root, target ast.Node) bool
- func FilenameConstrainedOut(filename string) bool
- func FindEnclosingFuncName(files []*ast.File, target ast.Node) string
- func FuncFQName(fn *types.Func) string
- func HostCallsMethod(sel *types.Selection) bool
- func ImplementsPluginCaller(t types.Type) bool
- func IsEntryPoint(fd *FuncDecl) bool
- func IsHostCallsType(t types.Type) bool
- func LastComponent(path string) string
- func MatchWasmBuildConstraint(filename string, content []byte) (bool, error)
- func PluginCallerMethod(sel *types.Selection) bool
- func ShortName(fqname string) string
- func WasmFilenameWarnings(filename string) []string
- type AnalysisResult
- type FuncDecl
- type Package
Constants ¶
const ( WasmTargetGOOS = "wasip1" WasmTargetGOARCH = "wasm" )
WASM build target constants.
const LoadMode = packages.NeedName | packages.NeedFiles | packages.NeedCompiledGoFiles | packages.NeedTypes | packages.NeedTypesInfo | packages.NeedSyntax | packages.NeedDeps | packages.NeedImports | packages.NeedModule
LoadMode is the set of package load flags needed for full analysis.
Variables ¶
This section is empty.
Functions ¶
func ContainsNode ¶
ContainsNode reports whether the AST subtree root contains the target node.
func FilenameConstrainedOut ¶
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 ¶
FindEnclosingFuncName returns the simple name of the function containing the given AST node, or "".
func FuncFQName ¶
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 ¶
HostCallsMethod reports whether the given selection is a method call on a HostCalls value.
func ImplementsPluginCaller ¶
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 ¶
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 ¶
IsHostCallsType reports whether t is cleat.HostCalls (interface) or *cleat.HostCalls (pointer to struct, for backward compatibility).
func LastComponent ¶
LastComponent returns the last component of a path (after the last '/').
func MatchWasmBuildConstraint ¶
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 ¶
PluginCallerMethod reports whether the given selection is a method call on a type that implements the cleat.PluginCaller marker interface.
func ShortName ¶
ShortName returns the short function name from a fully-qualified name. "pkg.Func" → "Func", "(*pkg.Type).Method" → "Method".
func WasmFilenameWarnings ¶
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 ¶
FullyQualifiedName returns the fully-qualified name for a function, e.g. "workflows.PlaceOrder" or "(*workflows.OrderProcessor).Process".