Skip to content

Commit 569fcbd

Browse files
committed
internal/core/adt: add nested logging support
Signed-off-by: Marcel van Lohuizen <mpvl@golang.org> Change-Id: I635e702fe98135a4f81786f2158bdb705e991c00 Signed-off-by: Marcel van Lohuizen <mpvl@golang.org> Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/529513 Reviewed-by: Paul Jolly <paul@myitcv.io>
1 parent c561f1f commit 569fcbd

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

internal/core/adt/context.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"os"
2121
"reflect"
2222
"regexp"
23+
"strings"
2324

2425
"github.com/cockroachdb/apd/v2"
2526
"golang.org/x/text/encoding/unicode"
@@ -82,12 +83,18 @@ func (c *OpContext) Logf(v *Vertex, format string, args ...interface{}) {
8283
if Verbosity == 0 {
8384
return
8485
}
86+
if v == nil {
87+
s := fmt.Sprintf(strings.Repeat("..", c.nest)+format, args...)
88+
_ = log.Output(2, s)
89+
return
90+
}
8591
p := pMap[v]
8692
if p == 0 {
8793
p = len(pMap) + 1
8894
pMap[v] = p
8995
}
9096
a := append([]interface{}{
97+
strings.Repeat("..", c.nest),
9198
p,
9299
v.Label.SelectorString(c),
93100
v.Path(),
@@ -100,7 +107,7 @@ func (c *OpContext) Logf(v *Vertex, format string, args ...interface{}) {
100107
a[i] = x.SelectorString(c)
101108
}
102109
}
103-
s := fmt.Sprintf(" [%d] %s/%v"+format, a...)
110+
s := fmt.Sprintf("%s [%d] %s/%v"+format, a...)
104111
_ = log.Output(2, s)
105112
}
106113

@@ -153,6 +160,8 @@ type OpContext struct {
153160
Runtime
154161
Format func(Node) string
155162

163+
nest int
164+
156165
stats Stats
157166
freeListNode *nodeContext
158167

internal/core/adt/eval.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,14 @@ func (c *OpContext) evaluate(v *Vertex, state VertexStatus) Value {
166166
// the cached results.
167167
func (c *OpContext) Unify(v *Vertex, state VertexStatus) {
168168
// defer c.PopVertex(c.PushVertex(v))
169+
if Debug {
170+
c.nest++
171+
c.Logf(v, "Unify")
172+
defer func() {
173+
c.Logf(v, "END Unify")
174+
c.nest--
175+
}()
176+
}
169177

170178
// Ensure a node will always have a nodeContext after calling Unify if it is
171179
// not yet Finalized.

0 commit comments

Comments
 (0)