Introduce #leaf record

Substantially based on Bob Dionne's work in a452a4a.

We can't currently test this patch at this stage of the merge fest but
we'll come back and modify this commit to fix errors.