Skip to main content

AILANG Architecture

This section documents the internal architecture of AILANG for contributors and those who want to understand how the language works.

Core Concepts​

Type System​

AILANG uses a Hindley-Milner type system with row polymorphism and effect tracking. Learn about:

  • Type inference pipeline (Surface AST → Core → Types → Evaluation)
  • CoreTypeInfo: type storage and validation
  • Row polymorphism for records and effects
  • Dictionary passing for type classes

A-Normal Form (ANF)​

All AILANG code is transformed to A-Normal Form before type checking and evaluation:

  • Every non-trivial expression bound to a name
  • Explicit sequencing
  • Easy instrumentation and type-guided lowering

Adding Operators​

Step-by-step guide for implementing new operators:

  • Parser and token definitions
  • Type checking rules
  • Type-guided lowering
  • Builtin registration

Debug Tools​

CLI tools for understanding the compilation pipeline:

  • ailang debug ast - Inspect Core AST (ANF)
  • ailang check -debug-compile - Compilation telemetry
  • ailang builtins list - Explore 128 registered builtins
  • ailang docs - Stdlib documentation

Compilation Pipeline​

Key Phases​

  1. Parsing: Source text → Surface AST
  2. Elaboration: Surface AST → Core AST (ANF normalization)
  3. Type Inference: Core AST → Typed AST + CoreTypeInfo
  4. Validation: Verify CoreTypeInfo completeness
  5. Lowering: Type-directed operator specialization
  6. Evaluation: Execute lowered Core AST

Implementation Files​

ComponentLocationDescription
Lexerinternal/lexer/Tokenization
Parserinternal/parser/Surface AST construction
Elaborationinternal/elaborate/Surface → Core
Type Systeminternal/types/Type inference
Core ASTinternal/core/ANF representation
Pipelineinternal/pipeline/Compilation orchestration
Evaluatorinternal/eval/Interpretation
Builtinsinternal/builtins/Built-in functions
Effectsinternal/effects/Effect runtime

Design Documents​

For detailed design decisions and implementation history, see:

See Also​