Correct the comments and decision around link-time compilation
This commit is contained in:
+4
-4
@@ -123,10 +123,10 @@ wording improves in a minor.
|
|||||||
|
|
||||||
## Every format is fenced at link, and its errors name its path
|
## Every format is fenced at link, and its errors name its path
|
||||||
|
|
||||||
2026-09-28, larv-review; approval pending. Goal 2: every format compiles in one phase,
|
2026-09-28, larv-review; approval pending. Goal 2. Every format compiles once, at
|
||||||
at link, since one holding a reference can compile only once bound, so no check reads
|
link: one holding a reference compiles only once bound, and compiling all there
|
||||||
compiled ops a format lacks yet. Its fences name the category path as every link error
|
leaves no check reading ops a format lacks yet. A link error names the category
|
||||||
does, a cell's with its line. Valid while compilation needs the bound references.
|
path, a table cell's with its line. Valid while compilation needs the bound references.
|
||||||
|
|
||||||
## Raising the lowest supported Go is a major
|
## Raising the lowest supported Go is a major
|
||||||
|
|
||||||
|
|||||||
@@ -55,11 +55,11 @@ type template struct {
|
|||||||
isRecord bool // compiled at the top without a repeat, so its fields are record columns
|
isRecord bool // compiled at the top without a repeat, so its fields are record columns
|
||||||
table *table // the table whose format this is, whose columns are the fields
|
table *table // the table whose format this is, whose columns are the fields
|
||||||
|
|
||||||
// Filled by `checkCells`, after the cell's own format has compiled:
|
// Filled by `checkCells`:
|
||||||
cellOf *table // the table whose cell this is
|
cellOf *table // the table whose cell this is
|
||||||
cellRow int // the row the cell sits in
|
cellRow int // the row the cell sits in
|
||||||
|
|
||||||
// Filled by `template.compileFormat`, from `template.format` and `template.refs`:
|
// Filled by `template.compileFormat` at link, from `template.tokens` and `template.refs`:
|
||||||
ops []op // what expand walks
|
ops []op // what expand walks
|
||||||
grow int // minimum output size, to size the render buffer
|
grow int // minimum output size, to size the render buffer
|
||||||
// bound maps each field the format addresses by dotted path to one path token
|
// bound maps each field the format addresses by dotted path to one path token
|
||||||
@@ -209,7 +209,7 @@ func compileString(s string) (node, error) {
|
|||||||
return &template{format: s, tokens: toks, repeat: 1, fromString: true}, nil
|
return &template{format: s, tokens: toks, repeat: 1, fromString: true}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// fixedText is the whole output of a format holding no token, which every render is.
|
// fixedText is one render's output when the format holds no token; repeat is the caller's.
|
||||||
func (t *template) fixedText() (string, bool) {
|
func (t *template) fixedText() (string, bool) {
|
||||||
switch {
|
switch {
|
||||||
case len(t.tokens) == 0:
|
case len(t.tokens) == 0:
|
||||||
|
|||||||
+5
-10
@@ -67,14 +67,10 @@ func refSegments(name string, folder []string) ([]string, error) {
|
|||||||
return append(append([]string{}, base...), segs...), nil
|
return append(append([]string{}, base...), segs...), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// linkRefs resolves every reference in the assembled tree and compiles every format.
|
// linkRefs binds every reference and compiles every format, once all data is merged,
|
||||||
// The head of the path — up to the category it names — is bound into the referring
|
// so a reference sees the override-resolved tree. A reference's head binds into
|
||||||
// template's refHeads under its root path, and the rest reads into it the way a
|
// refHeads under its root path and its tail reads like a sibling path, so two
|
||||||
// sibling path does, so a reference is held like a sibling and two spellings of one
|
// spellings of one target are one draw.
|
||||||
// target are one draw. It runs once, after all data is merged, so a reference sees
|
|
||||||
// the final (override-resolved) tree. A path that is unknown, names a folder, or
|
|
||||||
// reads a field not every variant carries fails here, keeping a bad reference a
|
|
||||||
// New-time error, never a random render-time one.
|
|
||||||
func linkRefs(root map[string]node) error {
|
func linkRefs(root map[string]node) error {
|
||||||
return eachTemplate(root, func(folder []string, path string, t *template) error {
|
return eachTemplate(root, func(folder []string, path string, t *template) error {
|
||||||
category := strings.Join(strings.Split(path, ".")[:len(folder)+1], ".")
|
category := strings.Join(strings.Split(path, ".")[:len(folder)+1], ".")
|
||||||
@@ -83,7 +79,6 @@ func linkRefs(root map[string]node) error {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// linkTemplateRefs binds one template's references against root, then compiles its format.
|
|
||||||
func linkTemplateRefs(folder []string, path, category string, t *template, root map[string]node) error {
|
func linkTemplateRefs(folder []string, path, category string, t *template, root map[string]node) error {
|
||||||
if t.cellOf != nil {
|
if t.cellOf != nil {
|
||||||
path = fmt.Sprintf("%s, line %d", path, t.cellRow+2)
|
path = fmt.Sprintf("%s, line %d", path, t.cellRow+2)
|
||||||
@@ -100,7 +95,7 @@ func linkTemplateRefs(folder []string, path, category string, t *template, root
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// bindRefs refuses a reference naming the category t sits in.
|
// bindRefs fills refs and refHeads, refusing a reference to t's own category:
|
||||||
// docs/decisions.md#a-category-never-references-itself-and-a-records-fences-run-at-load
|
// docs/decisions.md#a-category-never-references-itself-and-a-records-fences-run-at-load
|
||||||
func (t *template) bindRefs(folder []string, path, category string, names []string, root map[string]node) error {
|
func (t *template) bindRefs(folder []string, path, category string, names []string, root map[string]node) error {
|
||||||
t.refs = make(map[string]refBinding, len(names))
|
t.refs = make(map[string]refBinding, len(names))
|
||||||
|
|||||||
Reference in New Issue
Block a user