Have the draw fence query the read fold, deleting hasRead and its helpers

This commit is contained in:
2026-09-29 21:16:50 +02:00
committed by Lillem4n
parent 8d5c7e0adf
commit 78b08b699f
4 changed files with 31 additions and 76 deletions
-1
View File
@@ -115,5 +115,4 @@ In [docs/decisions.md](docs/decisions.md):
- The Swedish ids draw Skatteverket's test series
- The US given names come from a mirror of the SSA file
- `List` advertises direct descents only
- Each entry point to `drawFence.hasRead` says what its caller gets
- The four path walks are four loops
-6
View File
@@ -834,12 +834,6 @@ import drops them by name rather than by a rank a regeneration would move.
the set of every descent through a chain of five tables is every subsequence of it, and
the direct chain is the one a reader can predict from the tables' parents.
## Each entry point to `drawFence.hasRead` says what its caller gets
2026-09-25, larv-review; approved 2026-09-25 by lilleman. Goal 2: a reader lands on
`readsPath` or `splitsDraws` from its caller, so each doc states where that walk stops,
though `hasRead` states the same stop rule. Valid while the two differ in where they stop.
## The four path walks are four loops
2026-09-28, larv-review on systems-architect's finding; approved 2026-09-28 by lilleman.
+31 -66
View File
@@ -6,26 +6,34 @@ import (
"strings"
)
// drawFence fences each template of a scope as a render of its own, remembering which nodes read a
// reference path.
// drawFence fences each template of a scope as a render of its own, over one fold of what every
// node reads.
// docs/decisions.md#a-render-shares-one-reference-draw-per-category-per-group
// docs/decisions.md#the-expansion-hold-and-the-renders-draws-are-two-fences
type drawFence struct {
memo map[hasReadMemo]bool
fold *readFold
}
type hasReadMemo struct {
n node
stopAtGroup bool
func (f *drawFence) reads() *readFold {
if f.fold == nil {
f.fold = newReadFold()
}
return f.fold
}
// checkDrawGroup refuses a draw group that splits nothing: one whose render reads every reference
// path inside a repeat or a nested draw group, which draw apart from it whatever it names.
func (f *drawFence) checkDrawGroup(path string, n node) error {
if t, ok := n.(*template); ok && t.drawGroup != "" && !f.splitsDraws(t) {
return fmt.Errorf("%s: drawGroup %q splits nothing, since nothing it renders reads a reference path outside a repeat or a nested drawGroup; drop it", path, t.drawGroup)
t, ok := n.(*template)
if !ok || t.drawGroup == "" {
return nil
}
return nil
for _, r := range f.reads().rootReads(t) {
if r.at.group == "" && r.draws() {
return nil
}
}
return fmt.Errorf("%s: drawGroup %q splits nothing, since nothing it renders reads a reference path outside a repeat or a nested drawGroup; drop it", path, t.drawGroup)
}
func (f *drawFence) checkDraws(path string, n node) error {
@@ -33,10 +41,11 @@ func (f *drawFence) checkDraws(path string, n node) error {
if !ok {
return nil
}
if !f.readsPath(t) {
reads := f.reads().rootReads(t)
if !anyDraws(reads) {
return nil
}
if err := surveyRender(t).check(); err != nil {
if err := survey(reads, t.link.drawGroupKey).check(); err != nil {
return fmt.Errorf("%s: %w", path, err)
}
return nil
@@ -50,15 +59,11 @@ func (f *drawFence) checkRecordDraws(path string, n node) error {
if !ok || !t.isRecord {
return nil
}
columns := sortedNames(t.fields)
reads := false
for _, name := range columns {
reads = reads || f.readsPath(t.fields[name])
}
if !reads {
reads := f.reads().columnReads(t, sortedNames(t.fields))
if !anyDraws(reads) {
return nil
}
if err := surveyColumns(t, columns).check(); err != nil {
if err := survey(reads, t.link.drawGroupKey).check(); err != nil {
return fmt.Errorf("%s: %w", path, err)
}
return nil
@@ -100,41 +105,17 @@ func checkOwnFamily(path string, n node) error {
return nil
}
// readsPath reports whether rendering n reads a reference path, short of a repeat, which renders
// over draws of its own.
func (f *drawFence) readsPath(n node) bool { return f.hasRead(n, false) }
// draws reports whether a read's draw is its group's to answer for: a path, or a table read whole,
// whose row the group draws.
func (r pathRead) draws() bool { return len(r.a.tail) > 0 || r.tr != nil }
// splitsDraws reports whether rendering n reads a reference path that n's own draw group answers
// for: one outside a repeat and outside a nested draw group, which hold their own draws.
func (f *drawFence) splitsDraws(n node) bool { return f.hasRead(n, true) }
// hasRead walks what rendering n renders for a reference path, stopping at a repeat — and at a nested
// draw group when stopAtGroup — since each holds draws of its own.
func (f *drawFence) hasRead(n node, stopAtGroup bool) bool {
k := hasReadMemo{n, stopAtGroup}
if r, done := f.memo[k]; done {
return r
}
r := false
for _, e := range renderEdges(n) {
if readsOnEdge(n, e) || (walksInto(e.to, stopAtGroup) && f.hasRead(e.to, stopAtGroup)) {
r = true
break
func anyDraws(reads []pathRead) bool {
for _, r := range reads {
if r.draws() {
return true
}
}
if f.memo == nil {
f.memo = map[hasReadMemo]bool{}
}
f.memo[k] = r
return r
}
func readsOnEdge(n node, e renderEdge) bool {
return e.readsRef() && (len(e.read.tail) > 0 || readsTable(n, e.read))
}
func walksInto(to node, stopAtGroup bool) bool {
return !repeats(to) && !(stopAtGroup && grouped(to))
return false
}
func repeats(n node) bool {
@@ -142,22 +123,6 @@ func repeats(n node) bool {
return isTemplate && t.repeat > 1
}
func grouped(n node) bool {
t, isTemplate := n.(*template)
return isTemplate && t.link.drawGroupKey != ""
}
// readsTable reports whether a reference of n names a table, whose draw the render's
// group answers for even when read whole.
func readsTable(n node, a arm) bool {
t, isTemplate := n.(*template)
if !isTemplate {
return false
}
_, isTable := t.head(a.head).(*table)
return isTable
}
// check refuses what one draw per reference path cannot answer for: a read selecting a row its route
// pinned another of, a read of a level beside a path another read takes into it, and two reads of one
// table family that select different rows.
-3
View File
@@ -36,9 +36,6 @@ on 2026-09-29 a fifth time (Navigation 6.9, Locality 5.2, Shape 6.1, Self-suffic
This round, in order:
- Have `checkDrawGroup`, `checkDraws` and `checkRecordDraws` query the fold, deleting
`drawFence.hasRead`, its helpers and the decision "Each entry point to
`drawFence.hasRead` says what its caller gets".
- Move the fold to `reads.go` and the verdicts to `drawfence.go`, deleting
`readsurvey.go`; name a read's context its `group`, `route` and `branches`, deleting
`surveyAt`, and let the README's Layout and `doc.go` follow.