64. Mapping AST -> IR (practical view) (pocket version)

TL;DR (5 lines)

  • Stages are ownership boundaries.
  • Data movement matters as much as stage names.
  • Small compiler examples should still show multiple layers.
  • Broken stage structure should remain visible in invalid examples.
  • A mental model is a data-flow model.

Concrete Problem

Compiler-facing chapters become vague when they talk about stages but never show how data crosses stage boundaries.

Coherent example

space demo/compiler

pick ParseState {
  case Parsed(nodes: int)
  case Failed(code: int)
}

proc parse(size: int) -> ParseState {
  if size <= 0 { give ParseState.Failed(11) }
  give ParseState.Parsed(size)
}

proc lower(state: ParseState) -> int {
  match state {
    case Parsed(nodes) { give nodes }
    case Failed(code) { give code }
    otherwise { give 70 }
  }
}

Global explanation

Pipeline chapters are most useful when they keep stage ownership explicit. The reader should know what the parse stage owns, what the transform stage owns, and where errors cross boundaries.

Short exercise

Add one extra stage to the example and explain what data it receives and what it returns.

Next best action

Keep the example small, reproduce it locally, then continue to the full chapter if you need the broader context.