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.
What you need
Section titled “What you need”- a
trbcommand on yourPATH; 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.
Run it
Section titled “Run it”From the contributor-guide repository:
./scripts/trace-reference.sh-
Read the source
The script prints
traces/reference/answer.trb. -
Check it
trb checkruns parsing, name resolution, and type checking. It does not generate target source. -
Generate Go
trb build --stdoutruns 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. -
Run it
trb rungenerates, compiles, and starts the program. The final line is:answer=42
Connect the output to the map
Section titled “Connect the output to the map”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 programThe 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.
Make one safe experiment
Section titled “Make one safe experiment”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.