elaborate

package
v0.14.1 Latest Latest
Warning

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

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

Documentation

Overview

Package elaborate provides SCC detection for mutual recursion

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildInterface

func BuildInterface(prog *core.Program, modulePath string, typeEnv *types.TypeEnv) *iface.Iface

BuildInterface extracts a module interface from an elaborated Core program

func ElaborateWithDictionaries

func ElaborateWithDictionaries(prog *core.Program, resolved map[uint64]*types.ResolvedConstraint) (*core.Program, error)

ElaborateWithDictionaries transforms operators to dictionary calls This is the second pass after type checking

func VerifyANF

func VerifyANF(prog *core.Program) error

VerifyANF checks that a Core program is in A-Normal Form. In ANF: - Complex expressions must be let-bound - Arguments to functions and operators must be atomic - Scrutinees of if/match must be atomic - Fields in record construction must be atomic - Elements in list construction must be atomic

Returns nil if valid ANF, error describing violation otherwise.

func VerifyIdempotence

func VerifyIdempotence(prog *core.Program, resolved map[uint64]*types.ResolvedConstraint) error

VerifyIdempotence checks that running ElaborateWithDictionaries twice produces the same result This ensures our transformation is idempotent and safe for REPL usage

Types

type CallGraph

type CallGraph struct {
	// contains filtered or unexported fields
}

CallGraph represents a dependency graph between functions

func BuildCallGraph

func BuildCallGraph(funcs []*FuncSig, symbols map[string]*FuncSig, imports map[string]string) *CallGraph

BuildCallGraph analyzes functions to build a call graph

func NewCallGraph

func NewCallGraph() *CallGraph

NewCallGraph creates a new call graph

func (*CallGraph) AddEdge

func (g *CallGraph) AddEdge(caller, callee string)

AddEdge adds a dependency from caller to callee

func (*CallGraph) AddNode

func (g *CallGraph) AddNode(name string)

AddNode adds a function to the graph

func (*CallGraph) SCCs

func (g *CallGraph) SCCs() [][]string

SCCs computes strongly connected components using Tarjan's algorithm

type ConstructorInfo

type ConstructorInfo struct {
	TypeName       string       // The ADT type name (e.g., "Option")
	CtorName       string       // Constructor name (e.g., "Some")
	Arity          int          // Number of fields
	IsImported     bool         // Whether this constructor is imported
	TypeParamCount int          // M-TAPP-FIX: Number of type parameters (e.g., Option[a] = 1)
	TypeParamNames []string     // M-POLY-ADT: Type parameter names (e.g., ["a"] for Result[a])
	FieldTypes     []types.Type // M-POLY-ADT: Actual field types from AST (e.g., [string] for Err(string))
}

ConstructorInfo holds information about an available constructor

type DictElaborator

type DictElaborator struct {
	// contains filtered or unexported fields
}

DictElaborator handles dictionary transformation

type Elaborator

type Elaborator struct {
	// contains filtered or unexported fields
}

Elaborator transforms surface AST to Core ANF

func NewElaborator

func NewElaborator() *Elaborator

NewElaborator creates a new elaborator

func NewElaboratorWithPath

func NewElaboratorWithPath(filePath string) *Elaborator

NewElaboratorWithPath creates a new elaborator with file path for imports

func (*Elaborator) AddBuiltinsToGlobalEnv

func (e *Elaborator) AddBuiltinsToGlobalEnv()

AddBuiltinsToGlobalEnv adds all builtin functions to the global environment

func (*Elaborator) ClearWarnings

func (e *Elaborator) ClearWarnings()

ClearWarnings clears accumulated warnings

func (*Elaborator) Elaborate

func (e *Elaborator) Elaborate(prog *ast.Program) (*core.Program, error)

Elaborate transforms a surface program to Core ANF

func (*Elaborator) ElaborateExpr

func (e *Elaborator) ElaborateExpr(expr ast.Expr) (core.CoreExpr, error)

ElaborateExpr transforms a single expression to Core ANF (for testing)

func (*Elaborator) ElaborateFile

func (e *Elaborator) ElaborateFile(file *ast.File) (*core.Program, error)

ElaborateFile transforms a complete file with module structure to Core ANF

func (*Elaborator) GetConstructors

func (e *Elaborator) GetConstructors() map[string]*ConstructorInfo

GetConstructors returns all constructors defined in this module (not imported)

func (*Elaborator) GetDerivedEqTypes

func (e *Elaborator) GetDerivedEqTypes() []string

GetDerivedEqTypes returns all types that have `deriving (Eq)` clause M-DX19: Used to register Eq instances for derived types in the type checker

func (*Elaborator) GetEffectAnnotation

func (e *Elaborator) GetEffectAnnotation(nodeID uint64) []string

GetEffectAnnotation returns the effect annotation for a Core node ID

func (*Elaborator) GetEffectAnnotationsFull

func (e *Elaborator) GetEffectAnnotationsFull() map[uint64][]ast.EffectAnnotation

GetEffectAnnotationsFull returns all full effect annotations (Lambda NodeID -> full annotations) M-CAPABILITY-BUDGETS: Used to pass budget annotations from func declarations to type checker

func (*Elaborator) GetParamTypeAnnotations

func (e *Elaborator) GetParamTypeAnnotations() map[uint64][]types.Type

GetParamTypeAnnotations returns all parameter type annotations (Lambda NodeID -> param types) M-FIX-FLOAT-OP: Used to pass float annotations from func declarations to type checker

func (*Elaborator) GetReturnTypeAnnotations

func (e *Elaborator) GetReturnTypeAnnotations() map[uint64]types.Type

GetReturnTypeAnnotations returns all return type annotations (Lambda NodeID -> return type) M-FIX-FLOAT-OP: Used to ensure PI() -> float actually returns float

func (*Elaborator) GetSurfaceSpan

func (e *Elaborator) GetSurfaceSpan(nodeID uint64) (ast.Pos, bool)

GetSurfaceSpan retrieves the original surface span for a Core node ID

func (*Elaborator) GetTypeAliases

func (e *Elaborator) GetTypeAliases() map[string]types.Type

GetTypeAliases returns all type aliases registered during elaboration M-BUGFIX: Used to pass aliases to the type checker for expansion during unification

func (*Elaborator) GetWarnings

func (e *Elaborator) GetWarnings() []*ExhaustivenessWarning

GetWarnings returns accumulated exhaustiveness warnings

func (*Elaborator) MergeGlobalEnv

func (e *Elaborator) MergeGlobalEnv(env map[string]core.GlobalRef)

MergeGlobalEnv adds entries to the existing global environment Use this after AddBuiltinsToGlobalEnv() to preserve builtin references while adding import aliases and direct symbol imports.

func (*Elaborator) RegisterConstructor

func (e *Elaborator) RegisterConstructor(typeName, ctorName string, arity int, isImported bool, typeParamCount int)

RegisterConstructor adds a constructor to the elaborator's constructor map M-TAPP-FIX: Added typeParamCount to track ADT type parameters M-POLY-ADT: For backward compatibility, calls RegisterConstructorWithFields with nil fieldTypes

func (*Elaborator) RegisterConstructorWithFields

func (e *Elaborator) RegisterConstructorWithFields(typeName, ctorName string, arity int, isImported bool, typeParamCount int, typeParamNames []string, fieldTypes []types.Type)

RegisterConstructorWithFields adds a constructor with actual field types M-POLY-ADT: Stores field types to correctly build constructor type schemes This fixes the bug where Err(string) in Result[a] was incorrectly typed as ∀a. a -> Result[a]

func (*Elaborator) RegisterTypeAlias

func (e *Elaborator) RegisterTypeAlias(name string, target types.Type)

RegisterTypeAlias registers a type alias for expansion during type checking M-BUGFIX: This allows `type Coord = {x: int, y: int}` to work with ADT variants M-TYPENAME-NESTED-PROPAGATION: Set TypeName on TRecord so unification can propagate it

func (*Elaborator) SetGlobalEnv

func (e *Elaborator) SetGlobalEnv(env map[string]core.GlobalRef)

SetGlobalEnv sets the global environment for import resolution WARNING: This REPLACES the entire globalEnv map. If you've already called AddBuiltinsToGlobalEnv(), use MergeGlobalEnv() instead to avoid losing builtins.

func (*Elaborator) SetModuleLoader

func (e *Elaborator) SetModuleLoader(ml *loader.ModuleLoader)

SetModuleLoader sets the module loader for import resolution

type ExhaustivenessChecker

type ExhaustivenessChecker struct {
}

ExhaustivenessChecker analyzes match expressions for completeness

func NewExhaustivenessChecker

func NewExhaustivenessChecker() *ExhaustivenessChecker

NewExhaustivenessChecker creates a new checker

func (*ExhaustivenessChecker) CheckExhaustiveness

func (ec *ExhaustivenessChecker) CheckExhaustiveness(match *core.Match, scrutineeType types.Type) (bool, []string)

CheckExhaustiveness checks if a match expression is exhaustive Returns true if exhaustive, false with missing patterns if not

type ExhaustivenessWarning

type ExhaustivenessWarning struct {
	Location       string   // Source location
	MissingPattern []string // Missing patterns
}

ExhaustivenessWarning represents a non-exhaustive match warning

func (*ExhaustivenessWarning) String

func (w *ExhaustivenessWarning) String() string

type FuncSig

type FuncSig struct {
	Name     string
	NodeSID  string // Surface SID
	Body     ast.Expr
	Params   []string
	IsPure   bool
	IsExport bool
	Tests    []*ast.TestCase
	Props    []*ast.Property
	FuncDecl *ast.FuncDecl // Original declaration
}

FuncSig represents a function signature for call graph analysis

type ModuleLet

type ModuleLet struct {
	Name  string
	Value ast.Expr
	Pos   ast.Pos
}

ModuleLet represents a module-level let binding

type PatternSet

type PatternSet []core.CorePattern

PatternSet represents a set of concrete patterns

Jump to

Keyboard shortcuts

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