Skip to content

Reference compiler — executable trace

This trace keeps the program small enough to hold in your head. It lets the compiler show three visible products: a successful check, generated Go source, and program output.

When you set TYPE_RB_TRB, you choose a different local compiler identity. That is useful while developing, but its output matches this pinned clinic only when you built the same revision.

  • a trb command on your PATH; and
  • a Go toolchain, because the trace uses the default Go mode.

You can point the script at another compiler binary with TYPE_RB_TRB.

From the contributor-guide repository:

Terminal window
./scripts/trace-reference.sh
  1. Read the source

    The script prints traces/reference/answer.trb.

  2. Check it

    trb check runs parsing, name resolution, and type checking. It does not generate target source.

  3. Generate Go

    trb build --stdout runs the complete frontend, lowers the checked program, and asks the Go backend for source. The script shows only the beginning; the complete temporary file is deleted when the trace ends.

  4. Run it

    trb run generates, compiles, and starts the program. The final line is:

    answer=42
answer.trb
-> cmd/trb selects standalone Go mode
-> compiler parses, resolves, and checks
-> lower.Program creates typed IR
-> codegen.Generate emits Go
-> Go toolchain builds and runs the program

The script cannot print every in-memory compiler value, and that is useful: the normal command-line boundary stays stable while internal structures can improve. Follow the same expression through a few highlighted implementation decisions in the reference code clinic. Use the big map later when you need more source addresses.

Change the return value in answer() from Integer to a string:

return "forty-two"

Run the trace again. It should stop during checking, before Go generation. Read the diagnostic as a compact report of the checker’s job: expected type, actual type, and source location.

The diagnostic guide shows how to trace that failure backward from the visible result without depending on current checker helper names.