iface

package
v0.14.2 Latest Latest
Warning

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

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

Documentation

Overview

Package iface provides the frozen $builtin interface

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DumpBuiltinInterface

func DumpBuiltinInterface() ([]byte, error)

DumpBuiltinInterface exports the builtin interface as JSON

func GetBuiltinArity

func GetBuiltinArity(name string) (int, error)

GetBuiltinArity returns the arity of a builtin

func GetBuiltinType

func GetBuiltinType(name string) (string, error)

GetBuiltinType returns the type signature of a builtin

func ValidateBuiltin

func ValidateBuiltin(name string) error

ValidateBuiltin checks if a builtin reference is valid

Types

type Builder

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

Builder constructs module interfaces from typed Core programs

func NewBuilder

func NewBuilder(module string, typeEnv *types.TypeEnv) *Builder

NewBuilder creates a new interface builder

func (*Builder) Build

func (b *Builder) Build(prog *core.Program, constructors map[string]*ConstructorInfo, astFile interface{}) (*Iface, error)

Build constructs the interface from a Core program

type BuiltinExport

type BuiltinExport struct {
	Name     string `json:"name"`
	Type     string `json:"type"`
	Arity    int    `json:"arity"`
	Category string `json:"category"` // "arithmetic", "comparison", "string", "io", etc.
}

BuiltinExport represents a single builtin export

type BuiltinInterface

type BuiltinInterface struct {
	Module  string                   `json:"module"`
	Exports map[string]BuiltinExport `json:"exports"`
	Digest  string                   `json:"digest"`
}

BuiltinInterface represents the $builtin module interface

func FrozenBuiltinInterface

func FrozenBuiltinInterface() *BuiltinInterface

FrozenBuiltinInterface returns the deterministic $builtin interface This is the canonical source of truth for all builtins

type ConstructorInfo

type ConstructorInfo struct {
	TypeName       string
	CtorName       string
	Arity          int
	TypeParamCount int // M-TAPP-FIX: Number of type parameters (e.g., Option[a] = 1)
}

ConstructorInfo represents constructor information for interface building

type ConstructorScheme

type ConstructorScheme struct {
	TypeName   string       // The ADT name (e.g., "Option")
	CtorName   string       // Constructor name (e.g., "Some", "None")
	FieldTypes []types.Type // Field types (empty for nullary constructors)
	ResultType types.Type   // Result type after application
	Arity      int          // Number of fields
}

ConstructorScheme represents the type scheme of an ADT constructor

type FuncJSON

type FuncJSON struct {
	Name    string   `json:"name"`
	Type    string   `json:"type"`
	Effects []string `json:"effects"`
	Pure    bool     `json:"pure"`
}

FuncJSON represents an exported function in normalized form

type Iface

type Iface struct {
	Module       string                        // Module path, e.g., "math/gcd"
	Exports      map[string]*IfaceItem         // Exported symbols
	Constructors map[string]*ConstructorScheme // Exported ADT constructors
	Types        map[string]*TypeExport        // Exported type names
	TypeAliases  map[string]types.Type         // M-FIX-RECORD-UPDATE: Type alias expansions for record types
	Schema       string                        // Schema version, e.g., "ailang.iface/v1"
	Digest       string                        // Deterministic digest of interface
}

Iface represents a module's interface (its typed exports)

func BuildInterface

func BuildInterface(module string, prog *core.Program, typeEnv *types.TypeEnv) (*Iface, error)

BuildInterface extracts the typed interface from a Core program

func BuildInterfaceWithConstructors

func BuildInterfaceWithConstructors(module string, prog *core.Program, typeEnv *types.TypeEnv, constructors map[string]*ConstructorInfo) (*Iface, error)

BuildInterfaceWithConstructors builds an interface with constructor information

func BuildInterfaceWithTypesAndConstructors

func BuildInterfaceWithTypesAndConstructors(module string, prog *core.Program, typeEnv *types.TypeEnv, astFile interface{}, constructors map[string]*ConstructorInfo) (*Iface, error)

BuildInterfaceWithTypesAndConstructors builds an interface with type declarations and constructor information

func NewIface

func NewIface(module string) *Iface

NewIface creates a new module interface

func (*Iface) AddConstructor

func (i *Iface) AddConstructor(typeName, ctorName string, fieldTypes []types.Type, resultType types.Type)

AddConstructor adds an ADT constructor to the interface

func (*Iface) AddExport

func (i *Iface) AddExport(name string, typ *types.Scheme, purity bool)

AddExport adds an exported symbol to the interface

func (*Iface) AddType

func (i *Iface) AddType(name string, arity int)

AddType adds an exported type name to the interface

func (*Iface) AddTypeAlias

func (i *Iface) AddTypeAlias(name string, target types.Type)

AddTypeAlias adds a type alias expansion to the interface (M-FIX-RECORD-UPDATE) This is used for record type aliases like `type NPC = { pos: Pos, name: string }`

func (*Iface) GetConstructor

func (i *Iface) GetConstructor(name string) (*ConstructorScheme, bool)

GetConstructor retrieves a constructor scheme

func (*Iface) GetExport

func (i *Iface) GetExport(name string) (*IfaceItem, bool)

GetExport retrieves an exported symbol

func (*Iface) GetType

func (i *Iface) GetType(name string) (*TypeExport, bool)

GetType retrieves an exported type

func (*Iface) GetTypeAlias

func (i *Iface) GetTypeAlias(name string) (types.Type, bool)

GetTypeAlias retrieves a type alias expansion (M-FIX-RECORD-UPDATE)

func (*Iface) ToNormalizedJSON

func (i *Iface) ToNormalizedJSON() ([]byte, error)

ToNormalizedJSON converts an Iface to normalized JSON Normalization rules: - Sort all arrays alphabetically - Canonicalize type variables to a, b, c, ... - Sort effect rows alphabetically - Deterministic field ordering (via struct tags)

type IfaceItem

type IfaceItem struct {
	Name   string         // Symbol name
	Type   *types.Scheme  // Generalized type scheme
	Purity bool           // Whether the function is pure
	Ref    core.GlobalRef // Global reference to this item
}

IfaceItem represents a single exported symbol

type InterfaceJSON

type InterfaceJSON struct {
	Module string     `json:"module"`
	Types  []TypeJSON `json:"types"`
	Funcs  []FuncJSON `json:"funcs"`
	Schema string     `json:"schema"`
}

InterfaceJSON represents the normalized JSON format for module interfaces

type TypeExport

type TypeExport struct {
	Name  string // Type name (e.g., "Option", "Result")
	Arity int    // Number of type parameters
}

TypeExport represents an exported type name

type TypeJSON

type TypeJSON struct {
	Name   string   `json:"name"`
	Params []string `json:"params,omitempty"`
	Ctors  []string `json:"ctors,omitempty"`
}

TypeJSON represents an exported type in normalized form

Jump to

Keyboard shortcuts

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