32. Profiling and coverage (§8 tooling, 2026-11-21)
- 32.1 A profile counts statements, keyed by their span in the user's file.
cpl profileandcpl coverread one tally: how many times each statement began and the time until the next one began (a sampler's attribution). The interpreter keeps it incpl_interp::profile;cpl_codegen::emit_profiledwrites the same books into the C++ as a counter call before each statement, so the two agree on every count (native_profile_counts_what_the_interpreter_counts_*). Reason: one model serves both engines and coverage, and parity is testable. Reverse: dropemit_profiledand sample the native binary withperf.
- 32.2 Library code is the caller's line. Imported modules' fns (
Program.library_fns) and the closures they make are not counted; their time lands on the user's statement that called them, which is the line the contestant can change. Reverse: count them under their own module's file.
- 32.3 A statement inside an expression, or an
ifthat is the next arm of a chain, is not its own site. Statements ofExprKind::Doblocks are how an expression is lowered and the C++ may write it another way; aneliformatcharm may become oneswitch. Counting them made the two engines disagree on 126 of 183 programs. Reverse: give lowered blocks their own spans and mark them in codegen.
- 32.4 Branch coverage comes from the same counts. An
ifthat ran and whose first statement ran every time, or never, went one way. No separate instrumentation. Reverse: count arms explicitly.