Skip to content

Commit

Permalink
internal/core/adt: do not delay processing of fields
Browse files Browse the repository at this point in the history
This causes tests to be reordered.

The main problem was that if an embedding is processed before
all fields are known, it might be marked inadvertently as
incomplete.

This is a preperatory CL that happens to fix two Issues.
It removes some variability in processing order by converting
conjuncts of the form `x: a&b` to fields of the form `x: a, x: b`.
This has the unfortunate consequence that it misses some position
information. The intention is to bring this back in the new
implementation.

The main contribution here is that conjunct processing is now
reentrant: when a node is recursively evaluated, computation
now resumes where it was. This avoids some conjuncts being missed
and others from being processed double.

Test changes:

There are various reorderings. Processing times should roughly be
the same, and at least not grow a lot for all files.

This fixes a bug that caused changes in cmd_cycle.txtar: it would
correctly detect that the schema is incorrect. Changes are
made to keep the spirit of the test intact.

This causes some failures to be undetected for the self-reference
tests. This is okay, as an error only needs to be reported in
one field. Ideally this is fixed again, though.

chain.txtar is now creating a smaller output, which I believe is
correct.

closedness.txtar: the failure is now correctly propagated up.

conjuncts.txtar: note that the conjunct.t3 test is still broken.
This is not reflected in any issue. We leave it for now, but it
should be fixed with the new evaluator.

let.txtar: let now reports an error. Technically not correct,
but not harmful.

Fixes #2351
Fixes #2355

Signed-off-by: Marcel van Lohuizen <[email protected]>
Change-Id: Ib6c50a38910f9a6029957676dcd56328691d0252
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/556545
TryBot-Result: CUEcueckoo <[email protected]>
Reviewed-by: Daniel Martí <[email protected]>
  • Loading branch information
mpvl committed Jul 27, 2023
1 parent cabc1db commit e7cfb50
Show file tree
Hide file tree
Showing 99 changed files with 686 additions and 742 deletions.
4 changes: 2 additions & 2 deletions cmd/cue/cmd/testdata/script/cmd_cycle.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ command: kube: {
-- issue2416a_tool.cue --
package kubecluster

#Cluster: {}
Cluster: {}

m: x: #Cluster
m: x: Cluster
m: x: X={
foobar: X.name
name: "x"
Expand Down
2 changes: 1 addition & 1 deletion cmd/cue/cmd/testdata/script/cmd_embed.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ hello

command: hello1: task: hello: cli.Print & {
text: "hello, world"
}
}
15 changes: 15 additions & 0 deletions cmd/cue/cmd/testdata/script/cmd_order.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
exec cue cmd gen

-- task_tool.cue --
package ci

command: gen: {
$id: "tool/cli.Print"
text: {
#early: *"X" | string
#early
} & {// NEEDED
#early: *"X" | string
string
}
}
2 changes: 1 addition & 1 deletion cue/testdata/basicrewrite/009_reference.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Allocs: 4
Retain: 1

Unifications: 11
Conjuncts: 14
Conjuncts: 13
Disjuncts: 11
-- out/eval --
(struct){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Allocs: 5
Retain: 4

Unifications: 18
Conjuncts: 37
Conjuncts: 36
Disjuncts: 21
-- out/eval --
(struct){
Expand All @@ -105,18 +105,18 @@ Disjuncts: 21
1: (int){ 100 }
}
s1: (struct){
a: (int){ 1 }
c: (int){ 3 }
b: (int){ 2 }
a: (int){ 1 }
}
s2: (struct){
b: (int){ 2 }
a: (int){ 1 }
c: (int){ 3 }
b: (int){ 2 }
}
s3: (struct){
c: (int){ 3 }
b: (int){ 2 }
a: (int){ 1 }
c: (int){ 3 }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Allocs: 4
Retain: 3

Unifications: 6
Conjuncts: 8
Conjuncts: 6
Disjuncts: 8
-- out/eval --
(struct){
Expand Down
2 changes: 1 addition & 1 deletion cue/testdata/basicrewrite/aliases/aliases.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Allocs: 5
Retain: 3

Unifications: 9
Conjuncts: 15
Conjuncts: 14
Disjuncts: 10
-- out/eval --
(struct){
Expand Down
12 changes: 6 additions & 6 deletions cue/testdata/benchmarks/issue1684.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ out: #secrets & {
}
-- out/eval/stats --
Leaks: 0
Freed: 995025
Reused: 994976
Allocs: 49
Freed: 1064043
Reused: 1063992
Allocs: 51
Retain: 0

Unifications: 740771
Conjuncts: 2327328
Disjuncts: 995025
Unifications: 791999
Conjuncts: 2479541
Disjuncts: 1064043
-- out/eval --
(struct){
#Secret: (#struct){
Expand Down
12 changes: 6 additions & 6 deletions cue/testdata/benchmarks/issue2176.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ output: {
"2": (datastream & {marker: length: 14}).marker.position
}
-- out/eval/stats --
Leaks: 218
Leaks: 214
Freed: 5799
Reused: 5795
Allocs: 222
Retain: 1915
Allocs: 218
Retain: 1911

Unifications: 6009
Conjuncts: 14515
Disjuncts: 6868
Unifications: 6005
Conjuncts: 14507
Disjuncts: 6864
-- out/eval --
(struct){
#Datastream: (#struct){
Expand Down
2 changes: 1 addition & 1 deletion cue/testdata/builtins/incomplete.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ Allocs: 11
Retain: 53

Unifications: 109
Conjuncts: 267
Conjuncts: 266
Disjuncts: 156
-- out/eval --
Errors:
Expand Down
2 changes: 1 addition & 1 deletion cue/testdata/builtins/validators.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ Allocs: 5
Retain: 0

Unifications: 50
Conjuncts: 92
Conjuncts: 91
Disjuncts: 52
-- out/eval --
Errors:
Expand Down
2 changes: 1 addition & 1 deletion cue/testdata/compile/alias.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Allocs: 5
Retain: 2

Unifications: 10
Conjuncts: 13
Conjuncts: 11
Disjuncts: 10
-- out/eval --
(struct){
Expand Down
14 changes: 7 additions & 7 deletions cue/testdata/compile/scope.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,21 @@ let _schema_1 = schema
}
-- out/eval/stats --
Leaks: 2
Freed: 50
Reused: 47
Freed: 48
Reused: 45
Allocs: 5
Retain: 8

Unifications: 52
Conjuncts: 107
Disjuncts: 56
Unifications: 50
Conjuncts: 102
Disjuncts: 54
-- out/eval --
Errors:
schema.next: structural cycle

Result:
(_|_){
// [structural cycle]
e: (struct){
}
a: (struct){
d: (struct){
}
Expand All @@ -110,6 +108,8 @@ Result:
c: (string){ "foo" }
d: (struct){
}
e: (struct){
}
let B#1 = (struct){
open: (int){ int }
}
Expand Down
2 changes: 1 addition & 1 deletion cue/testdata/comprehensions/015_list_comprehension.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Allocs: 8
Retain: 14

Unifications: 19
Conjuncts: 39
Conjuncts: 35
Disjuncts: 23
-- out/eval --
(struct){
Expand Down
18 changes: 9 additions & 9 deletions cue/testdata/comprehensions/closed.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ dedupTodo: {
-- out/eval/stats --
Leaks: 2
Freed: 70
Reused: 63
Allocs: 9
Retain: 15
Reused: 64
Allocs: 8
Retain: 4

Unifications: 58
Conjuncts: 104
Disjuncts: 81
Conjuncts: 103
Disjuncts: 71
-- out/eval --
Errors:
disallowed.vErr.d: field not allowed:
Expand Down Expand Up @@ -207,19 +207,19 @@ Result:
}
dedupTodo: (struct){
#sub: (_|_){
// [incomplete] dedupTodo.#sub: c.n undefined (c is incomplete):
// [incomplete] dedupTodo.#sub: c.n undefined as c is incomplete (type _):
// ./in.cue:80:6
c: (_){ _ }
}
out: (#struct){
c: (struct){
n: (string){ "c" }
}
X: (#struct){
test: (#struct){
n: (string){ "c" }
}
}
c: (struct){
n: (string){ "c" }
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion cue/testdata/comprehensions/fields.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Allocs: 7
Retain: 2

Unifications: 33
Conjuncts: 41
Conjuncts: 40
Disjuncts: 33
-- out/eval --
(struct){
Expand Down
2 changes: 1 addition & 1 deletion cue/testdata/comprehensions/for.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Allocs: 8
Retain: 11

Unifications: 20
Conjuncts: 20
Conjuncts: 18
Disjuncts: 21
-- out/eval --
Errors:
Expand Down
12 changes: 6 additions & 6 deletions cue/testdata/comprehensions/iferror.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,11 @@ Leaks: 0
Freed: 43
Reused: 35
Allocs: 8
Retain: 22
Retain: 18

Unifications: 33
Conjuncts: 68
Disjuncts: 60
Conjuncts: 65
Disjuncts: 57
-- out/eval --
Errors:
issue1972.err1: conflicting values [] and {someCondition:_,patchs:[...{}],patchs,if someCondition {patchs:_}} (mismatched types list and struct):
Expand Down Expand Up @@ -200,8 +200,8 @@ Result:
}
useDefault: (struct){
a: (struct){
y: (string){ |(*(string){ "foo" }, (string){ string }) }
x: (string){ |(*(string){ "foo" }, (string){ string }) }
y: (string){ |(*(string){ "foo" }, (string){ string }) }
}
issue809: (struct){
#A: (#struct){
Expand Down Expand Up @@ -230,10 +230,10 @@ Result:
// ./in.cue:61:8
// issue1972.err1: invalid list index someCondition (type string):
// ./in.cue:65:6
patchs: (list){
#patchs: (#list){
}
someCondition: (_){ _ }
#patchs: (#list){
patchs: (list){
}
#someCondition: (_){ _ }
}
Expand Down
12 changes: 6 additions & 6 deletions cue/testdata/comprehensions/issue1732.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ foo: {
-- out/eval/stats --
Leaks: 4
Freed: 118
Reused: 105
Allocs: 17
Retain: 19
Reused: 103
Allocs: 19
Retain: 14

Unifications: 112
Conjuncts: 249
Disjuncts: 133
Disjuncts: 128
-- out/eval --
(struct){
networkingv1: (struct){
Expand Down Expand Up @@ -259,7 +259,7 @@ Disjuncts: 133
}
}
}
_outputs(:config): (#struct){
formatOutput: (#struct){
foo: (#struct){
}
"ns/network": (#struct){
Expand Down Expand Up @@ -293,7 +293,7 @@ Disjuncts: 133
}
}
}
formatOutput: (#struct){
_outputs(:config): (#struct){
foo: (#struct){
}
"ns/network": (#struct){
Expand Down
2 changes: 1 addition & 1 deletion cue/testdata/comprehensions/issue287.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Allocs: 4
Retain: 2

Unifications: 5
Conjuncts: 8
Conjuncts: 7
Disjuncts: 5
-- out/eval --
(struct){
Expand Down
2 changes: 1 addition & 1 deletion cue/testdata/comprehensions/nested.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Allocs: 19
Retain: 36

Unifications: 35
Conjuncts: 96
Conjuncts: 95
Disjuncts: 78
-- out/eval --
(struct){
Expand Down
6 changes: 3 additions & 3 deletions cue/testdata/comprehensions/nested2.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ Leaks: 0
Freed: 43
Reused: 38
Allocs: 5
Retain: 6
Retain: 4

Unifications: 43
Conjuncts: 78
Conjuncts: 74
Disjuncts: 43
-- out/eval --
(struct){
Expand Down Expand Up @@ -135,8 +135,8 @@ Disjuncts: 43
b: (int){ 20 }
}
indirectlyNested: (struct){
b: (bool){ true }
a: (bool){ true }
b: (bool){ true }
}
directlyNestedEmpty: (struct){
a: (bool){ true }
Expand Down
Loading

0 comments on commit e7cfb50

Please sign in to comment.