Skip to content

Commit 887f564

Browse files
committed
internal/core/adt: improve mechanism for conjunct insertion
Before this change it was possible for reference to be inserted into a vertex (possibly through embedding) while the conjunct list of the arc was still not completed. For instance, if a parent node was not yet done processing conjuncts, it may be that the child would also still get conjuncts. This would cause conjuncts to be dropped during evaluation. This change adds a mechanism to add conjuncts post hoc to nodes that included the respective referenced Vertex. Whenever a conjunct is added to an arc for which processing has already started, it will proactively evaluate the conjunct and add it to any nodes in the notify list. This will ensure, through a recursive process, that such a conjunct is immediately added to all nodes that require it. In addition, each node tracks whether all conjuncts are added. All conjuncts will have been added if both - all its conjuncts are processed, and - if all ancestor nodes have processed all their conjuncts. This is a consequence of the abovementioned recursive process. The changes in bulk.txtar are okay, as the uninitialized fields are below a field with a permanent error and do not necessarily have to be evaluated. A TODO has been added to remove the code that offends it. At the moment, though, removing this code has too many adverse consequences that will be mitigated by reworking the state model. Fixes #2169 Signed-off-by: Marcel van Lohuizen <[email protected]> Change-Id: I8e976f2b7c8dff73ac1520037bceed2c7d4f4d1c Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/548906 Unity-Result: CUEcueckoo <[email protected]> TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Daniel Martí <[email protected]> Reviewed-by: Roger Peppe <[email protected]>
1 parent 81e4cba commit 887f564

22 files changed

+193
-115
lines changed

cue/testdata/benchmarks/issue2176.txtar

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ output: {
5959
"2": (datastream & {marker: length: 14}).marker.position
6060
}
6161
-- out/eval/stats --
62-
Leaks: 214
63-
Freed: 5803
64-
Reused: 5798
65-
Allocs: 219
62+
Leaks: 218
63+
Freed: 5799
64+
Reused: 5795
65+
Allocs: 222
6666
Retain: 1077
6767

6868
Unifications: 6009
6969
Conjuncts: 14515
70-
Disjuncts: 6872
70+
Disjuncts: 6868
7171
-- out/eval --
7272
(struct){
7373
#Datastream: (#struct){

cue/testdata/cycle/chain.txtar

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,10 @@ Leaks: 123
212212
Freed: 4431
213213
Reused: 4412
214214
Allocs: 142
215-
Retain: 693
215+
Retain: 689
216216

217217
Unifications: 1799
218-
Conjuncts: 7513
218+
Conjuncts: 7509
219219
Disjuncts: 5078
220220
-- out/eval --
221221
(struct){

cue/testdata/cycle/evaluate.txtar

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ Leaks: 67
111111
Freed: 94
112112
Reused: 90
113113
Allocs: 71
114-
Retain: 127
114+
Retain: 119
115115

116116
Unifications: 149
117117
Conjuncts: 291

cue/testdata/cycle/inline_non_recursive.txtar

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ issue1708: {
6060
}
6161

6262
-- out/eval/stats --
63-
Leaks: 240
64-
Freed: 440
65-
Reused: 430
66-
Allocs: 250
63+
Leaks: 291
64+
Freed: 389
65+
Reused: 379
66+
Allocs: 301
6767
Retain: 1014
6868

6969
Unifications: 680
7070
Conjuncts: 2709
71-
Disjuncts: 1454
71+
Disjuncts: 1403
7272
-- out/eval --
7373
(struct){
7474
ok1: (struct){

cue/testdata/cycle/self.txtar

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,9 @@ Result:
344344
// [eval] list.error2.a: conflicting values "1" and "2":
345345
// ./in.cue:16:6
346346
// ./in.cue:16:11
347+
// list.error2.a: conflicting values "3" and "1":
348+
// ./in.cue:15:6
349+
// ./in.cue:16:6
347350
// list.error2.a: conflicting values "3" and "2":
348351
// ./in.cue:15:6
349352
// ./in.cue:16:11

cue/testdata/cycle/structural.txtar

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ Leaks: 17
536536
Freed: 791
537537
Reused: 779
538538
Allocs: 29
539-
Retain: 61
539+
Retain: 59
540540

541541
Unifications: 622
542542
Conjuncts: 1219

cue/testdata/definitions/033_Issue_#153.txtar

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ Junk: {
6363
-- out/eval/stats --
6464
Leaks: 0
6565
Freed: 15
66-
Reused: 7
67-
Allocs: 8
66+
Reused: 6
67+
Allocs: 9
6868
Retain: 4
6969

7070
Unifications: 11

cue/testdata/definitions/037_closing_with_comprehensions.txtar

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,15 @@ a: _|_ // field "f3" not allowed in closed struct
103103
})
104104
}
105105
-- out/eval/stats --
106-
Leaks: 5
107-
Freed: 23
108-
Reused: 19
109-
Allocs: 9
106+
Leaks: 10
107+
Freed: 18
108+
Reused: 15
109+
Allocs: 13
110110
Retain: 11
111111

112112
Unifications: 28
113113
Conjuncts: 43
114-
Disjuncts: 34
114+
Disjuncts: 29
115115
-- out/eval --
116116
Errors:
117117
#E.f3: field not allowed:

cue/testdata/definitions/files.txtar

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ package foo
2929
-- out/eval/stats --
3030
Leaks: 0
3131
Freed: 25
32-
Reused: 18
33-
Allocs: 7
34-
Retain: 4
32+
Reused: 19
33+
Allocs: 6
34+
Retain: 1
3535

3636
Unifications: 21
3737
Conjuncts: 69
38-
Disjuncts: 29
38+
Disjuncts: 26
3939
-- out/eval --
4040
(#struct){
4141
#theme: (#struct){

cue/testdata/disjunctions/019_ips.txtar

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ MyIP: [10, 10, 10, 10]
5555
])
5656
}
5757
-- out/eval/stats --
58-
Leaks: 2
59-
Freed: 55
60-
Reused: 49
61-
Allocs: 8
58+
Leaks: 3
59+
Freed: 54
60+
Reused: 48
61+
Allocs: 9
6262
Retain: 10
6363

6464
Unifications: 48
6565
Conjuncts: 111
66-
Disjuncts: 65
66+
Disjuncts: 64
6767
-- out/eval --
6868
(struct){
6969
IP: (#list){

cue/testdata/eval/bulk.txtar

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@ patternCycle: t1: p3: {
7070
}
7171

7272
-- out/eval/stats --
73-
Leaks: 2
74-
Freed: 88
75-
Reused: 81
76-
Allocs: 9
77-
Retain: 8
73+
Leaks: 4
74+
Freed: 80
75+
Reused: 73
76+
Allocs: 11
77+
Retain: 12
7878

79-
Unifications: 69
80-
Conjuncts: 135
81-
Disjuncts: 96
79+
Unifications: 63
80+
Conjuncts: 129
81+
Disjuncts: 90
8282
-- out/eval --
8383
Errors:
8484
t1.c.z: field not allowed:
@@ -189,9 +189,12 @@ Result:
189189
// [eval] patternCycle.issue2109.p2.countries: cyclic pattern constraint:
190190
// ./issue2109.cue:15:15
191191
// ./issue2109.cue:17:13
192-
0: (string){ "US" }
193-
1: (string){ "GB" }
194-
2: (string){ "AU" }
192+
0: (_|_){// "US"
193+
}
194+
1: (_|_){// "GB"
195+
}
196+
2: (_|_){// "AU"
197+
}
195198
}
196199
}
197200
p3: (_|_){
@@ -202,9 +205,12 @@ Result:
202205
// [eval] patternCycle.issue2109.p3.countries: cyclic pattern constraint:
203206
// ./issue2109.cue:21:15
204207
// ./issue2109.cue:22:13
205-
0: (string){ "US" }
206-
1: (string){ "GB" }
207-
2: (string){ "AU" }
208+
0: (_|_){// "US"
209+
}
210+
1: (_|_){// "GB"
211+
}
212+
2: (_|_){// "AU"
213+
}
208214
}
209215
}
210216
}

cue/testdata/eval/insertion.txtar

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -96,29 +96,27 @@ embeddedFunctionalExpr: {
9696
#fn
9797
}
9898
-- out/eval/stats --
99-
Leaks: 13
100-
Freed: 55
101-
Reused: 51
99+
Leaks: 12
100+
Freed: 53
101+
Reused: 48
102102
Allocs: 17
103-
Retain: 36
103+
Retain: 23
104104

105-
Unifications: 68
106-
Conjuncts: 225
107-
Disjuncts: 87
105+
Unifications: 65
106+
Conjuncts: 191
107+
Disjuncts: 74
108108
-- out/eval --
109109
(struct){
110110
embeddingDirect: (struct){
111-
t1: (_|_){
112-
// [incomplete] embeddingDirect.t1: cannot add field #a: was already used:
113-
// ./a.cue:5:2
114-
#a: (_){ _ }
111+
t1: (string){
112+
"s"
113+
#a: (string){ string }
115114
}
116115
}
117116
embeddingExpr: (struct){
118-
t1: (_|_){
119-
// [incomplete] embeddingExpr.t1: cannot add field #a: was already used:
120-
// ./a.cue:13:2
121-
#a: (_){ _ }
117+
t1: (string){
118+
"s"
119+
#a: (string){ string }
122120
}
123121
}
124122
unifiedDirect: (struct){
@@ -134,18 +132,17 @@ Disjuncts: 87
134132
}
135133
}
136134
cross: (struct){
137-
t1: (_|_){
138-
// [incomplete] cross.t1: cannot add field a: was already used:
139-
// ./a.cue:52:13
140-
// cross.t1: cannot add field a: was already used:
141-
// ./a.cue:56:3
135+
t1: (struct){
142136
a: (struct){
143137
b: (struct){
144138
v: (int){ 1 }
145139
a: (struct){
146140
w: (int){ 2 }
147141
}
142+
y: (int){ 5 }
148143
}
144+
x: (int){ 2 }
145+
w: (int){ 2 }
149146
}
150147
b: (struct){
151148
a: (struct){
@@ -156,19 +153,25 @@ Disjuncts: 87
156153
w: (int){ 2 }
157154
}
158155
v: (int){ 1 }
156+
y: (int){ 5 }
159157
}
158+
x: (int){ 2 }
159+
y: (int){ 5 }
160160
v: (int){ 1 }
161+
w: (int){ 2 }
161162
}
162163
}
163164
recursive: (struct){
164165
t1: (struct){
165166
e: (struct){
166167
f: (int){ 1 }
168+
g: (int){ 1 }
167169
}
168170
c: (struct){
169171
d: (struct){
170172
e: (struct){
171173
f: (int){ 1 }
174+
g: (int){ 1 }
172175
}
173176
c: (struct){
174177
d: (struct){
@@ -181,21 +184,13 @@ Disjuncts: 87
181184
}
182185
}
183186
}
184-
embeddedFunctionalExpr: (_|_){
185-
// [incomplete] embeddedFunctionalExpr: cannot add field #in: was already used:
186-
// ./issue2169.cue:6:3
187-
// embeddedFunctionalExpr: non-concrete value _ in operand to +:
188-
// ./issue2169.cue:8:3
189-
// ./issue2169.cue:8:4
190-
#fn: (_|_){
191-
// [incomplete] embeddedFunctionalExpr.#fn: cannot add field #in: was already used:
192-
// ./issue2169.cue:6:3
193-
// embeddedFunctionalExpr.#fn: non-concrete value _ in operand to +:
194-
// ./issue2169.cue:8:3
195-
// ./issue2169.cue:8:4
196-
#in: (_){ _ }
187+
embeddedFunctionalExpr: (string){
188+
"str"
189+
#fn: (string){
190+
"str"
191+
#in: (string){ string }
197192
}
198-
#in: (_){ _ }
193+
#in: (string){ string }
199194
}
200195
}
201196
-- out/compile --

cue/testdata/eval/structs.txtar

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import "struct"
33

44
v: {a: struct.MaxFields(2) & {}}.a
55
-- out/eval/stats --
6-
Leaks: 1
7-
Freed: 3
6+
Leaks: 2
7+
Freed: 2
88
Reused: 0
99
Allocs: 4
1010
Retain: 2
1111

1212
Unifications: 4
1313
Conjuncts: 7
14-
Disjuncts: 5
14+
Disjuncts: 4
1515
-- out/eval --
1616
(struct){
1717
v: (struct){

cue/testdata/export/009.txtar

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ f: [1, 2, ...]
4343
}
4444
}
4545
-- out/eval/stats --
46-
Leaks: 2
47-
Freed: 14
46+
Leaks: 3
47+
Freed: 13
4848
Reused: 10
4949
Allocs: 6
5050
Retain: 12
5151

5252
Unifications: 16
5353
Conjuncts: 37
54-
Disjuncts: 26
54+
Disjuncts: 25
5555
-- out/eval --
5656
(struct){
5757
a: (#list){

cue/testdata/export/010.txtar

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ f: [1, 2, ...]
4444
}
4545
}
4646
-- out/eval/stats --
47-
Leaks: 2
48-
Freed: 14
47+
Leaks: 3
48+
Freed: 13
4949
Reused: 10
5050
Allocs: 6
5151
Retain: 12
5252

5353
Unifications: 16
5454
Conjuncts: 37
55-
Disjuncts: 26
55+
Disjuncts: 25
5656
-- out/eval --
5757
(struct){
5858
a: (#list){

0 commit comments

Comments
 (0)