Skip to main content

Module coverage

Module coverage 

Source
Expand description

Line coverage for executed Harn programs.

Harn already stores a source line for every emitted instruction (Chunk::lines), so line coverage needs no separate debug-info pass: the denominator is the set of distinct non-zero lines a chunk (and its nested function bodies) emit, and the numerator is the subset whose instructions actually ran.

§How it is wired

Coverage is opt-in and process-global so it captures every VM isolate a run spins up (imports, parallel branches, spawned agents) without threading a flag through every constructor:

§File attribution

A chunk compiled from an imported module carries its own source_file; the entry file’s top-level chunk and its same-file function bodies carry None. We attribute a None chunk to the VM’s primary file (the script under execution), and otherwise to the chunk’s source_file. Nested function chunks inherit their parent’s effective file when they carry no source_file of their own, so a module’s uncalled helpers are still counted against the module — not misattributed to the entry script.

Render filters to files that exist on disk, which drops the synthetic paths the embedded stdlib and in-memory eval chunks report.

Structs§

Coverage
Accumulated line coverage. Used both as a per-VM accumulator and, after merging, as the whole-run report.

Functions§

begin_session
Start a coverage session: clear the merged report and enable recording on every VM constructed until end_session.
end_session
End the coverage session and return the merged report.
is_enabled
True while a coverage session is active. Read once per VM construction and once per executed instruction, so it is a relaxed atomic load — effectively free and branch-predicted “off” when no session is running.