AST/HIR/MIR Pipeline Overview

Lexer

The lexer tokenizes the source code into a stream of tokens, which are the basic units of syntax.

Parser

The parser processes tokens according to grammar rules to produce an abstract syntax tree (AST).

AST

The Abstract Syntax Tree represents the syntactic structure of the source code in a tree form.

HIR

The High-level Intermediate Representation (HIR) is a semantic representation derived from the AST.

Semantic Analysis

This phase analyzes the HIR to check for semantic correctness like scope and type usage.

Type Checking

Type checking ensures that operations in the code are performed on compatible types.

Borrow Checking

Borrow checking enforces rules about ownership and lifetimes of references.

MIR

The Mid-level Intermediate Representation (MIR) is a lowered form of HIR optimized for analysis and transformation.

Backend

The backend generates executable code or other output formats from the MIR.