Have the draw fence query the read fold, deleting hasRead and its helpers
This commit is contained in:
@@ -115,5 +115,4 @@ In [docs/decisions.md](docs/decisions.md):
|
|||||||
- The Swedish ids draw Skatteverket's test series
|
- The Swedish ids draw Skatteverket's test series
|
||||||
- The US given names come from a mirror of the SSA file
|
- The US given names come from a mirror of the SSA file
|
||||||
- `List` advertises direct descents only
|
- `List` advertises direct descents only
|
||||||
- Each entry point to `drawFence.hasRead` says what its caller gets
|
|
||||||
- The four path walks are four loops
|
- The four path walks are four loops
|
||||||
|
|||||||
@@ -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 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.
|
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
|
## The four path walks are four loops
|
||||||
|
|
||||||
2026-09-28, larv-review on systems-architect's finding; approved 2026-09-28 by lilleman.
|
2026-09-28, larv-review on systems-architect's finding; approved 2026-09-28 by lilleman.
|
||||||
|
|||||||
+31
-66
@@ -6,26 +6,34 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// drawFence fences each template of a scope as a render of its own, remembering which nodes read a
|
// drawFence fences each template of a scope as a render of its own, over one fold of what every
|
||||||
// reference path.
|
// node reads.
|
||||||
// docs/decisions.md#a-render-shares-one-reference-draw-per-category-per-group
|
// 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
|
// docs/decisions.md#the-expansion-hold-and-the-renders-draws-are-two-fences
|
||||||
type drawFence struct {
|
type drawFence struct {
|
||||||
memo map[hasReadMemo]bool
|
fold *readFold
|
||||||
}
|
}
|
||||||
|
|
||||||
type hasReadMemo struct {
|
func (f *drawFence) reads() *readFold {
|
||||||
n node
|
if f.fold == nil {
|
||||||
stopAtGroup bool
|
f.fold = newReadFold()
|
||||||
|
}
|
||||||
|
return f.fold
|
||||||
}
|
}
|
||||||
|
|
||||||
// checkDrawGroup refuses a draw group that splits nothing: one whose render reads every reference
|
// 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.
|
// 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 {
|
func (f *drawFence) checkDrawGroup(path string, n node) error {
|
||||||
if t, ok := n.(*template); ok && t.drawGroup != "" && !f.splitsDraws(t) {
|
t, ok := n.(*template)
|
||||||
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)
|
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 {
|
func (f *drawFence) checkDraws(path string, n node) error {
|
||||||
@@ -33,10 +41,11 @@ func (f *drawFence) checkDraws(path string, n node) error {
|
|||||||
if !ok {
|
if !ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if !f.readsPath(t) {
|
reads := f.reads().rootReads(t)
|
||||||
|
if !anyDraws(reads) {
|
||||||
return nil
|
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 fmt.Errorf("%s: %w", path, err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@@ -50,15 +59,11 @@ func (f *drawFence) checkRecordDraws(path string, n node) error {
|
|||||||
if !ok || !t.isRecord {
|
if !ok || !t.isRecord {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
columns := sortedNames(t.fields)
|
reads := f.reads().columnReads(t, sortedNames(t.fields))
|
||||||
reads := false
|
if !anyDraws(reads) {
|
||||||
for _, name := range columns {
|
|
||||||
reads = reads || f.readsPath(t.fields[name])
|
|
||||||
}
|
|
||||||
if !reads {
|
|
||||||
return nil
|
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 fmt.Errorf("%s: %w", path, err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@@ -100,41 +105,17 @@ func checkOwnFamily(path string, n node) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// readsPath reports whether rendering n reads a reference path, short of a repeat, which renders
|
// draws reports whether a read's draw is its group's to answer for: a path, or a table read whole,
|
||||||
// over draws of its own.
|
// whose row the group draws.
|
||||||
func (f *drawFence) readsPath(n node) bool { return f.hasRead(n, false) }
|
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
|
func anyDraws(reads []pathRead) bool {
|
||||||
// for: one outside a repeat and outside a nested draw group, which hold their own draws.
|
for _, r := range reads {
|
||||||
func (f *drawFence) splitsDraws(n node) bool { return f.hasRead(n, true) }
|
if r.draws() {
|
||||||
|
return 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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if f.memo == nil {
|
return false
|
||||||
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))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func repeats(n node) bool {
|
func repeats(n node) bool {
|
||||||
@@ -142,22 +123,6 @@ func repeats(n node) bool {
|
|||||||
return isTemplate && t.repeat > 1
|
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
|
// 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
|
// 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.
|
// table family that select different rows.
|
||||||
|
|||||||
@@ -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:
|
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
|
- 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
|
`readsurvey.go`; name a read's context its `group`, `route` and `branches`, deleting
|
||||||
`surveyAt`, and let the README's Layout and `doc.go` follow.
|
`surveyAt`, and let the README's Layout and `doc.go` follow.
|
||||||
|
|||||||
Reference in New Issue
Block a user