Hasty Briefsbeta

Bilingual

Zig AstGen: AST => ZIR

2 days ago
  • After building the AST, the next step in Zig compiler is generating the Zig Intermediate Representation (ZIR) using the AstGen stage.
  • ZIR is an untyped intermediate representation, meaning types are not fully evaluated until later comptime analysis.
  • ZIR consists of a sequence of instructions, each with a tag and data, often referencing other instructions or static values.
  • AstGen introduces scope awareness, identifier resolution, and string interning, storing strings in a continuous array to free AST and source.
  • ZIR instructions can embed static values, reference other instructions via index, or use tagged references for well-known primitives.
  • Variable assignments in ZIR do not generate explicit instructions; instead, they are tracked via scopes that reference the value's instruction index.
  • AstGen is run once per file, converting the entire AST into ZIR eagerly, and is the first stage to perform semantic validation like identifier checks.