Tracing means following references, so first we need the references leaving a single object. Today you build children - the ids an object points at through its non-nil fields - the one step every trace repeats.
Return the ids an object references, skipping nil fields, in field order.
A trace is just this one move repeated: stand on an object, look at everything it
references, step to each of those, and keep going. Children is that one move - it
returns the ids in an object’s fields, skipping any field that holds the nil
reference because nil points at nothing. Preserving field order keeps results
deterministic and easy to assert.
This tiny helper is the seam between the object model and every algorithm to come. The reachable-set trace calls it; the mark phase greys the children it returns; the copying collector forwards each child. Keeping “which objects does this one point at” in one place means the rest of the collector never touches the field layout directly. Next lesson you follow these edges from a root to compute a whole reachable set.
// the objects reachable in one step from obj: its non-nil fields, in orderfunc (h *Heap) Children(obj Ref) []Ref {var out []Reffor _, f := range h.slots[obj].fields {if f != Nil { out = append(out, f) } // skip the dead-end fields}return out}