Trace a render's reads through the hold set the test makes, dropping session.trace and repeatDepth
This commit is contained in:
+12
-13
@@ -62,7 +62,7 @@ func TestEveryReadARenderMakesIsGathered(t *testing.T) {
|
|||||||
f := fenceCorpus(t)
|
f := fenceCorpus(t)
|
||||||
roots, tables := fenceRoots(t, f)
|
roots, tables := fenceRoots(t, f)
|
||||||
for _, root := range roots {
|
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 {
|
if !root.t.isRecord || len(root.t.fields) == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -70,11 +70,11 @@ func TestEveryReadARenderMakesIsGathered(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("%s: recordOf = %v", root.label, err)
|
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()
|
t.Helper()
|
||||||
var reads []pathRead
|
var reads []pathRead
|
||||||
type traceKey struct {
|
type traceKey struct {
|
||||||
@@ -82,8 +82,8 @@ func wantGathered(t *testing.T, s *session, tables map[string]*table, label stri
|
|||||||
row int
|
row int
|
||||||
}
|
}
|
||||||
seen := map[traceKey]bool{}
|
seen := map[traceKey]bool{}
|
||||||
s.trace = &renderTrace{read: func(group, table string, row int, a arm) {
|
trace := func(group, table string, row int, a arm) {
|
||||||
if s.trace.repeatDepth != 0 || !isRef(a.key) {
|
if !isRef(a.key) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
r := pathRead{at: drawAt{group: group}, a: a}
|
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
|
seen[k] = true
|
||||||
reads = append(reads, r)
|
reads = append(reads, r)
|
||||||
}
|
}
|
||||||
}}
|
}
|
||||||
defer func() { s.trace = nil }()
|
|
||||||
for i := 0; i < 5; i++ {
|
for i := 0; i < 5; i++ {
|
||||||
renderOnce()
|
renderOnce(trace)
|
||||||
}
|
}
|
||||||
for _, r := range reads {
|
for _, r := range reads {
|
||||||
if !gathers(gathered, r) {
|
if !gathers(gathered, r) {
|
||||||
@@ -124,14 +123,14 @@ func spellPins(p *pinSet) string {
|
|||||||
return "row " + strings.Join(rows, ", ")
|
return "row " + strings.Join(rows, ", ")
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderRoot(s *session, t *template) {
|
func renderRoot(s *session, t *template, trace renderTrace) {
|
||||||
var set holdSet
|
set := holdSet{trace: trace}
|
||||||
sc := renderScope{set: &set}
|
sc := renderScope{set: &set}
|
||||||
switch {
|
switch {
|
||||||
case t.table != nil:
|
case t.table != nil:
|
||||||
render(s, t.table, sc)
|
render(s, t.table, sc)
|
||||||
for r := 0; r < t.table.rowCount(); r++ {
|
for r := 0; r < t.table.rowCount(); r++ {
|
||||||
var set holdSet
|
set := holdSet{trace: trace}
|
||||||
sc := renderScope{set: &set}
|
sc := renderScope{set: &set}
|
||||||
sc.groupHold().pins.pin(t.table, r)
|
sc.groupHold().pins.pin(t.table, r)
|
||||||
render(s, t.table.pinnedRow, sc.at(t.table.pinnedRow, &sc.groupHold().pins))
|
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) {
|
func renderRecordRoot(s *session, t *template, columns []Column, trace renderTrace) {
|
||||||
var set holdSet
|
set := holdSet{trace: trace}
|
||||||
sc := renderScope{set: &set}
|
sc := renderScope{set: &set}
|
||||||
if t.table != nil {
|
if t.table != nil {
|
||||||
t.table.drawIn(s, &sc.groupHold().pins)
|
t.table.drawIn(s, &sc.groupHold().pins)
|
||||||
|
|||||||
@@ -45,7 +45,6 @@ type Generator struct {
|
|||||||
type session struct {
|
type session struct {
|
||||||
*rand.Rand
|
*rand.Rand
|
||||||
counters map[string]uint64
|
counters map[string]uint64
|
||||||
trace *renderTrace
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *session) next(key string) uint64 {
|
func (s *session) next(key string) uint64 {
|
||||||
|
|||||||
@@ -34,8 +34,8 @@ type readValue struct {
|
|||||||
// render's hold for its group, so its draw spans the render; every other held name in
|
// render's hold for its group, so its draw spans the render; every other held name in
|
||||||
// held, the expansion's.
|
// held, the expansion's.
|
||||||
func readField(s *session, t *template, held *hold, sc renderScope, a arm) readValue {
|
func readField(s *session, t *template, held *hold, sc renderScope, a arm) readValue {
|
||||||
if s.trace != nil {
|
if sc.set.trace != nil {
|
||||||
traceRead(s.trace, t, sc, a)
|
traceRead(sc.set.trace, t, sc, a)
|
||||||
}
|
}
|
||||||
if !t.compiled.held[a.key] {
|
if !t.compiled.held[a.key] {
|
||||||
if len(a.tail) > 0 {
|
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.
|
// renderTrace is a test's view of the fields a render reads; nil outside a test.
|
||||||
type renderTrace struct {
|
type renderTrace func(group, table string, row int, a arm)
|
||||||
read func(group, table string, row int, a arm)
|
|
||||||
repeatDepth int
|
|
||||||
}
|
|
||||||
|
|
||||||
func traceRead(trace *renderTrace, t *template, sc renderScope, a arm) {
|
func traceRead(trace renderTrace, t *template, sc renderScope, a arm) {
|
||||||
var table string
|
var table string
|
||||||
var row int
|
var row int
|
||||||
switch {
|
switch {
|
||||||
@@ -78,7 +75,7 @@ func traceRead(trace *renderTrace, t *template, sc renderScope, a arm) {
|
|||||||
case t.table != nil:
|
case t.table != nil:
|
||||||
table, row = t.table.path, sc.rowOf(t.table)
|
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
|
// renderLeaf draws and renders what a read lands on: null on a null item, or on a column of one
|
||||||
|
|||||||
+3
-5
@@ -5,10 +5,12 @@ import (
|
|||||||
"strings"
|
"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 {
|
type holdSet struct {
|
||||||
unnamed groupHold
|
unnamed groupHold
|
||||||
named map[string]*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
|
// 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
|
//go:noinline
|
||||||
func expandAnew(s *session, t *template) string {
|
func expandAnew(s *session, t *template) string {
|
||||||
var set holdSet
|
var set holdSet
|
||||||
if s.trace != nil {
|
|
||||||
s.trace.repeatDepth++
|
|
||||||
defer func() { s.trace.repeatDepth-- }()
|
|
||||||
}
|
|
||||||
return expand(s, t, renderScope{set: &set})
|
return expand(s, t, renderScope{set: &set})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,8 +23,6 @@ Shape 5.8, Self-sufficiency 5.7), every seat capped by Locality, all nine naming
|
|||||||
|
|
||||||
This round, in order:
|
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
|
- 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
|
`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.
|
field's heap claim as contradicted by the other three.
|
||||||
|
|||||||
Reference in New Issue
Block a user