Skip to content

Commit

Permalink
internal/core/adt: add methods for accessing Conjuncts
Browse files Browse the repository at this point in the history
The new evaluator uses a tree of conjuncts, instead of
a list. Much of the existing code does not handle this
properly.

The plan is to replace access to Conjuncts with the
use of visitor methods.

Issue #2886

Signed-off-by: Marcel van Lohuizen <[email protected]>
Change-Id: Idba1f3af0ede1184932c6152b4e5a2cd92e510c5
  • Loading branch information
mpvl committed Apr 11, 2024
1 parent 7327c83 commit f21553f
Show file tree
Hide file tree
Showing 14 changed files with 188 additions and 327 deletions.
14 changes: 10 additions & 4 deletions cmd/cue/cmd/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"cuelang.org/go/cue"
"cuelang.org/go/cue/errors"
"cuelang.org/go/cue/token"
"cuelang.org/go/internal/core/adt"
itask "cuelang.org/go/internal/task"
"cuelang.org/go/internal/value"
_ "cuelang.org/go/pkg/tool/cli" // Register tasks
Expand Down Expand Up @@ -92,17 +93,22 @@ func customCommand(c *Command, typ, name string, tools *cue.Instance) (*cobra.Co

// Ensure there is at least one tool file.
// TODO: remove this block to allow commands to be defined in any file.
outer:
for _, v := range []cue.Value{tools.Lookup(typ), o} {
_, w := value.ToInternal(v)
for _, c := range w.Conjuncts {
hasToolFile := false
w.VisitLeafConjuncts(func(c adt.Conjunct) bool {
src := c.Source()
if src == nil {
continue
return true
}
if strings.HasSuffix(src.Pos().Filename(), "_tool.cue") {
break outer
hasToolFile = true
return false
}
return true
})
if hasToolFile {
break
}
if err := v.Err(); err != nil {
return nil, err
Expand Down
43 changes: 0 additions & 43 deletions cue/testdata/builtins/056_issue314.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -85,49 +85,6 @@ Retain: 17
Unifications: 45
Conjuncts: 77
Disjuncts: 62
-- out/evalalpha --
(struct){
x: (#struct){
s: (string){ "myname" }
out: (string){ "myname" }
}
#T: (#struct){
s: (string){ string }
out: (_|_){
// [incomplete] #T.out: error in call to text/template.Execute: cannot convert non-concrete value string:
// ./in.cue:14:7
}
}
#V: (#struct){
s: (string){ string }
out: (_|_){
// [incomplete] cannot convert incomplete value "string" to JSON:
// ./in.cue:20:7
}
}
#U: (#struct){
s: (string){ string }
out: (_|_){
// [incomplete] #U.out: error in call to encoding/yaml.Marshal: incomplete value string:
// ./in.cue:26:7
// ./in.cue:25:7
}
}
}
-- diff/-out/evalalpha<==>+out/eval --
diff old new
--- old
+++ new
@@ -8,7 +8,6 @@
out: (_|_){
// [incomplete] #T.out: error in call to text/template.Execute: cannot convert non-concrete value string:
// ./in.cue:14:7
- // ./in.cue:15:3
}
}
#V: (#struct){
-- diff/todo/p2 --
error positions
-- out/eval --
(struct){
x: (#struct){
Expand Down
201 changes: 0 additions & 201 deletions cue/testdata/builtins/incomplete.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -110,207 +110,6 @@ Retain: 61
Unifications: 109
Conjuncts: 264
Disjuncts: 156
-- out/evalalpha --
Errors:
badListType.decimal: cannot use 2 (type int) as list in argument 1 to list.Max:
./in.cue:79:11
badListType.str: cannot use 2 (type int) as list in argument 1 to strings.Join:
./in.cue:79:11
badListError.x: invalid operands 2 and "foo" to '+' (type int and string):
./in.cue:85:11
./in.cue:86:11

Result:
(_|_){
// [eval]
list1: (struct){
Out1: (#list){
0: (_|_){
// [incomplete] list1._Sub: undefined field: b:
// ./in.cue:19:10
}
}
Out2: (#list){
0: (_|_){
// [incomplete] list1._Sub: undefined field: b:
// ./in.cue:19:10
}
}
Out3: (#list){
0: (_|_){
// [incomplete] list1._Sub: undefined field: b:
// ./in.cue:19:10
}
}
Top: (#list){
0: (_|_){
// [incomplete] list1._Sub: undefined field: b:
// ./in.cue:19:10
}
}
_Sub: (_|_){
// [incomplete] list1._Sub: undefined field: b:
// ./in.cue:19:10
}
a: (struct){
}
}
list2: (struct){
Out1: (_|_){
// [incomplete] list2.#Sub: undefined field: b:
// ./in.cue:33:10
}
Out2: (_|_){
// [incomplete] list2.#Sub: undefined field: b:
// ./in.cue:33:10
}
Out3: (_|_){
// [incomplete] list2.#Sub: undefined field: b:
// ./in.cue:33:10
}
_Top: (_|_){
// [incomplete] list2.#Sub: undefined field: b:
// ./in.cue:33:10
}
#Sub: (_|_){
// [incomplete] list2.#Sub: undefined field: b:
// ./in.cue:33:10
}
a: (struct){
}
}
value1: (struct){
a: (_|_){
// [incomplete] value1.a: unresolved disjunction 'sf' | 'dd' (type bytes):
// ./in.cue:39:5
}
}
value2: (_|_){
// [incomplete] value2: unresolved disjunction 'sf' | 'dd' (type bytes):
// ./in.cue:43:2
}
incompleteArgDecimalList: (struct){
a: (#struct){
param: (int){ 123 }
transformed: (int){ 123 }
max: (int){ 123 }
}
#a: (#struct){
param: (int){ int }
transformed: (_|_){
// [incomplete] incompleteArgDecimalList.#a.transformed: operand param of '+' not concrete (was int):
// ./in.cue:50:17
}
max: (_|_){
// [incomplete] incompleteArgDecimalList.#a.0: operand param of '+' not concrete (was int):
// ./in.cue:50:17
}
}
}
incompleteArgStringList: (struct){
a: (#struct){
param: (string){ "123" }
transformed: (string){ "123" }
joined: (string){ "123" }
}
#a: (#struct){
param: (string){ string }
transformed: (_|_){
// [incomplete] incompleteArgStringList.#a.transformed: non-concrete value string in operand to +:
// ./in.cue:59:16
// ./in.cue:58:16
}
joined: (_|_){
// [incomplete] incompleteArgStringList.#a.0: non-concrete value string in operand to +:
// ./in.cue:59:16
// ./in.cue:58:16
}
}
}
incompleteList: (struct){
x: (_){ _ }
decimal: (_|_){
// [incomplete] incompleteList.decimal: non-concrete list for argument 0:
// ./in.cue:66:11
}
str: (_|_){
// [incomplete] incompleteList.str: non-concrete list for argument 0:
// ./in.cue:67:11
}
}
incompleteListError: (struct){
x: (_|_){
// [incomplete] incompleteListError.x: non-concrete value _ in operand to +:
// ./in.cue:72:11
}
y: (_){ _ }
decimal: (_|_){
// [incomplete] incompleteListError.x: non-concrete value _ in operand to +:
// ./in.cue:72:11
}
str: (_|_){
// [incomplete] incompleteListError.x: non-concrete value _ in operand to +:
// ./in.cue:72:11
}
}
badListType: (_|_){
// [eval]
x: (int){ 2 }
decimal: (_|_){
// [eval] badListType.decimal: cannot use 2 (type int) as list in argument 1 to list.Max:
// ./in.cue:79:11
}
str: (_|_){
// [eval] badListType.str: cannot use 2 (type int) as list in argument 1 to strings.Join:
// ./in.cue:79:11
}
}
badListError: (_|_){
// [eval]
x: (_|_){
// [eval] badListError.x: invalid operands 2 and "foo" to '+' (type int and string):
// ./in.cue:85:11
// ./in.cue:86:11
}
y: (string){ "foo" }
decimal: (_|_){
// [eval] badListError.x: invalid operands 2 and "foo" to '+' (type int and string):
// ./in.cue:85:11
// ./in.cue:86:11
}
str: (_|_){
// [eval] badListError.x: invalid operands 2 and "foo" to '+' (type int and string):
// ./in.cue:85:11
// ./in.cue:86:11
}
}
multipleErrors: (struct){
#T: (#struct){
params: (#struct){
x: (string){ string }
y: (string){ string }
}
out: (_|_){
// [incomplete] multipleErrors.#T.out: error in call to text/template.Execute: cannot convert non-concrete value string:
// ./in.cue:99:8
}
}
}
}
-- diff/-out/evalalpha<==>+out/eval --
diff old new
--- old
+++ new
@@ -180,7 +180,6 @@
out: (_|_){
// [incomplete] multipleErrors.#T.out: error in call to text/template.Execute: cannot convert non-concrete value string:
// ./in.cue:99:8
- // ./in.cue:96:4
}
}
}
-- diff/todo/p3 --
Error position
-- out/eval --
Errors:
badListType.decimal: cannot use 2 (type int) as list in argument 1 to list.Max:
Expand Down
Loading

0 comments on commit f21553f

Please sign in to comment.