diff --git a/drawfence_test.go b/drawfence_test.go index c426bc4..03dca96 100644 --- a/drawfence_test.go +++ b/drawfence_test.go @@ -62,7 +62,7 @@ func TestEveryReadARenderMakesIsGathered(t *testing.T) { f := fenceCorpus(t) roots, tables := fenceRoots(t, f) for _, root := range roots { - wantGathered(t, f.rand, tables, root.label, renderDraws(root.t).reads, func() { renderRoot(f.rand, root.t) }) + wantGathered(t, tables, root.label, renderDraws(root.t).reads, func(trace renderTrace) { renderRoot(f.rand, root.t, trace) }) if !root.t.isRecord || len(root.t.fields) == 0 { continue } @@ -70,11 +70,11 @@ func TestEveryReadARenderMakesIsGathered(t *testing.T) { if err != nil { t.Fatalf("%s: recordOf = %v", root.label, err) } - wantGathered(t, f.rand, tables, root.label+" as a record", columnDraws(root.t, sortedNames(root.t.fields)).reads, func() { renderRecordRoot(f.rand, root.t, columns) }) + wantGathered(t, tables, root.label+" as a record", columnDraws(root.t, sortedNames(root.t.fields)).reads, func(trace renderTrace) { renderRecordRoot(f.rand, root.t, columns, trace) }) } } -func wantGathered(t *testing.T, s *session, tables map[string]*table, label string, gathered []pathRead, renderOnce func()) { +func wantGathered(t *testing.T, tables map[string]*table, label string, gathered []pathRead, renderOnce func(renderTrace)) { t.Helper() var reads []pathRead type traceKey struct { @@ -82,8 +82,8 @@ func wantGathered(t *testing.T, s *session, tables map[string]*table, label stri row int } seen := map[traceKey]bool{} - s.trace = &renderTrace{read: func(group, table string, row int, a arm) { - if s.trace.repeatDepth != 0 || !isRef(a.key) { + trace := func(group, table string, row int, a arm) { + if !isRef(a.key) { return } r := pathRead{at: drawAt{group: group}, a: a} @@ -94,10 +94,9 @@ func wantGathered(t *testing.T, s *session, tables map[string]*table, label stri seen[k] = true reads = append(reads, r) } - }} - defer func() { s.trace = nil }() + } for i := 0; i < 5; i++ { - renderOnce() + renderOnce(trace) } for _, r := range reads { if !gathers(gathered, r) { @@ -124,14 +123,14 @@ func spellPins(p *pinSet) string { return "row " + strings.Join(rows, ", ") } -func renderRoot(s *session, t *template) { - var set holdSet +func renderRoot(s *session, t *template, trace renderTrace) { + set := holdSet{trace: trace} sc := renderScope{set: &set} switch { case t.table != nil: render(s, t.table, sc) for r := 0; r < t.table.rowCount(); r++ { - var set holdSet + set := holdSet{trace: trace} sc := renderScope{set: &set} sc.groupHold().pins.pin(t.table, r) render(s, t.table.pinnedRow, sc.at(t.table.pinnedRow, &sc.groupHold().pins)) @@ -143,8 +142,8 @@ func renderRoot(s *session, t *template) { } } -func renderRecordRoot(s *session, t *template, columns []Column) { - var set holdSet +func renderRecordRoot(s *session, t *template, columns []Column, trace renderTrace) { + set := holdSet{trace: trace} sc := renderScope{set: &set} if t.table != nil { t.table.drawIn(s, &sc.groupHold().pins) diff --git a/fejkdata.go b/fejkdata.go index 41672d7..c47e10e 100644 --- a/fejkdata.go +++ b/fejkdata.go @@ -45,7 +45,6 @@ type Generator struct { type session struct { *rand.Rand counters map[string]uint64 - trace *renderTrace } func (s *session) next(key string) uint64 { diff --git a/hold.go b/hold.go index 54b553b..0b30533 100644 --- a/hold.go +++ b/hold.go @@ -34,8 +34,8 @@ type readValue struct { // render's hold for its group, so its draw spans the render; every other held name in // held, the expansion's. func readField(s *session, t *template, held *hold, sc renderScope, a arm) readValue { - if s.trace != nil { - traceRead(s.trace, t, sc, a) + if sc.set.trace != nil { + traceRead(sc.set.trace, t, sc, a) } if !t.compiled.held[a.key] { if len(a.tail) > 0 { @@ -64,12 +64,9 @@ func readField(s *session, t *template, held *hold, sc renderScope, a arm) readV } // renderTrace is a test's view of the fields a render reads; nil outside a test. -type renderTrace struct { - read func(group, table string, row int, a arm) - repeatDepth int -} +type renderTrace func(group, table string, row int, a arm) -func traceRead(trace *renderTrace, t *template, sc renderScope, a arm) { +func traceRead(trace renderTrace, t *template, sc renderScope, a arm) { var table string var row int switch { @@ -78,7 +75,7 @@ func traceRead(trace *renderTrace, t *template, sc renderScope, a arm) { case t.table != nil: table, row = t.table.path, sc.rowOf(t.table) } - trace.read(strings.Clone(sc.group), strings.Clone(table), row, a) + trace(strings.Clone(sc.group), strings.Clone(table), row, a) } // renderLeaf draws and renders what a read lands on: null on a null item, or on a column of one diff --git a/holdset.go b/holdset.go index 93be3fa..810b8d2 100644 --- a/holdset.go +++ b/holdset.go @@ -5,10 +5,12 @@ import ( "strings" ) -// holdSet is one render's reference draws: the unnamed draw group's, and each named one's. +// holdSet is one render's reference draws: the unnamed draw group's, and each named one's; and a +// test's trace of its reads. type holdSet struct { unnamed groupHold named map[string]*groupHold + trace renderTrace } // renderScope is where a render reads its reference paths: a hold set, in the draw group of the @@ -33,10 +35,6 @@ func renderOnce(s *session, n node) string { //go:noinline func expandAnew(s *session, t *template) string { var set holdSet - if s.trace != nil { - s.trace.repeatDepth++ - defer func() { s.trace.repeatDepth-- }() - } return expand(s, t, renderScope{set: &set}) } diff --git a/todo.md b/todo.md index d5139ba..f0027c2 100644 --- a/todo.md +++ b/todo.md @@ -23,8 +23,6 @@ Shape 5.8, Self-sufficiency 5.7), every seat capped by Locality, all nine naming This round, in order: -- Move `session.trace` and `renderTrace.repeatDepth` off the render path: they serve - `drawfence_test.go` alone. - Give `Fake` a local hold set like `FakeRecord`, `RecordTemplate.Fake` and `FakeStruct`, or state at `Generator.set` why it alone needs one: four seats read the field's heap claim as contradicted by the other three.