Skip to content

Commit

Permalink
internal/core/dep: dereference node in dynamic mode
Browse files Browse the repository at this point in the history
With eval V3, as more structure sharing is implemented,
we will need to do more dereferencing. This change
prevents a bug as more sharing is supported in an
upcoming CL.

This also adds some testing infrastructure to select
the evaluator version and to enable logging by
default.

Issue #2854

Signed-off-by: Marcel van Lohuizen <[email protected]>
Change-Id: I7f15f8d1955d9ff9c0cafa1ed6e5196b44d02f1f
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1202234
Reviewed-by: Matthew Sackman <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
Unity-Result: CUE porcuepine <[email protected]>
  • Loading branch information
mpvl committed Oct 10, 2024
1 parent 1eb6216 commit 8399737
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
38 changes: 31 additions & 7 deletions internal/core/dep/dep_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,41 @@ import (
"text/tabwriter"

"cuelang.org/go/cue"
"cuelang.org/go/cue/cuecontext"
"cuelang.org/go/cue/format"
"cuelang.org/go/internal"
"cuelang.org/go/internal/core/adt"
"cuelang.org/go/internal/core/debug"
"cuelang.org/go/internal/core/dep"
"cuelang.org/go/internal/core/eval"
"cuelang.org/go/internal/core/runtime"
"cuelang.org/go/internal/cuedebug"
"cuelang.org/go/internal/cuetdtest"
"cuelang.org/go/internal/cuetxtar"
"cuelang.org/go/internal/value"
)

func TestVisit(t *testing.T) {
test := cuetxtar.TxTarTest{
Root: "./testdata",
Name: "dependencies",
Matrix: cuetdtest.SmallMatrix,
Root: "./testdata",
Name: "dependencies",
// Matrix: cuetdtest.SmallMatrix,
Matrix: cuetdtest.DevOnlyMatrix,

ToDo: map[string]string{
"dependencies-v3/inline": "error",
},
}

test.Run(t, func(t *cuetxtar.Test) {
val := t.CueContext().BuildInstance(t.Instance())
flags := cuedebug.Config{
Sharing: true,
// LogEval: 1,
}
ctx := t.CueContext()
r := (*runtime.Runtime)(ctx)
r.SetDebugOptions(&flags)

val := ctx.BuildInstance(t.Instance())
if val.Err() != nil {
t.Fatal(val.Err())
}
Expand Down Expand Up @@ -117,9 +128,16 @@ func testVisit(t *testing.T, w io.Writer, ctxt *adt.OpContext, v *adt.Vertex, cf

// DO NOT REMOVE: for Testing purposes.
func TestX(t *testing.T) {
version := internal.DefaultVersion
version = internal.DevVersion
flags := cuedebug.Config{
Sharing: true,
LogEval: 1,
}

cfg := &dep.Config{
Dynamic: true,
// Recurse: true,
// Descend: true,
}

in := `
Expand All @@ -129,7 +147,10 @@ func TestX(t *testing.T) {
t.Skip()
}

v := cuecontext.New().CompileString(in)
r := runtime.NewWithSettings(version, flags)
ctx := (*cue.Context)(r)

v := ctx.CompileString(in)
if err := v.Err(); err != nil {
t.Fatal(err)
}
Expand All @@ -138,6 +159,9 @@ func TestX(t *testing.T) {

r, n := value.ToInternal(aVal)

out := debug.NodeString(r, n, nil)
t.Error(out)

ctxt := eval.NewContext(r, n)

n.VisitLeafConjuncts(func(c adt.Conjunct) bool {
Expand Down
3 changes: 3 additions & 0 deletions internal/core/dep/mixed.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import (
// and comprehension sources.
func (v *visitor) dynamic(n *adt.Vertex, top bool) {
found := false
// TODO: Consider if we should only visit the conjuncts of the disjunction
// for dynamic mode.
n.VisitLeafConjuncts(func(c adt.Conjunct) bool {
if v.marked[c.Expr()] {
found = true
Expand All @@ -45,6 +47,7 @@ func (v *visitor) dynamic(n *adt.Vertex, top bool) {
return
}

n = n.DerefValue()
for _, a := range n.Arcs {
if !a.IsDefined(v.ctxt) || a.Label.IsLet() {
continue
Expand Down

0 comments on commit 8399737

Please sign in to comment.