Skip to content

Commit 92330b4

Browse files
committed
internal/core/adt: new cycle algorithm
V3 only partially implemented the V2 cycle algorithm. Rather than implementing the rest, we came up with a new algorithm that fits better with the depth-first nature of V3. It is overall considerably simpler than the V2 algorithm. This CL reflects a "mostly done" state. There are still improvements to be made (e.g. inline and let fields), but it is already in better shape that V3 was before. Further fixes will be done in subsequent CLs. Note that this algorith is much simpler. It no longer needs: - track individual reference points (although it still does so for debugging purposes, but it does not use it to influence outcome) - track nodeContext.cyclicReferences - have a special mechanism to detect and disable mutual references - track depth of optional markers - track depth of references - additional finding of evidence of non-cyclic nodes in some cases CHANGES IN TESTS benchmarks/issue1684: more efficient at trimming disjunctions comprehensions/errors: more efficient at trimming disjunctions cycle/comprehenion: changes are strict improvements, even though they do not fix the underlying bugs cycle/constraints: - both shorter and deeper cutoffs cycle/evaluate: - reordering, mostly cycle/inline_non_recursive: - FIXES cycle/inline: - Minor improvements - Does not yet fix underlying bug cycle/structural: - Some processing is now deeper - Some less deep - Some P0-level bugs now FIXED that were somehow not listed in diff/todo/*. eval/v0.7: - NEW BUG: notification mechanism bypassed, it seems. export/030: - performance improvements Issue #2850 Signed-off-by: Marcel van Lohuizen <[email protected]> Change-Id: I280fcf9cb333735fcc1774f980bf34e7ed72c9a9 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1201897 Reviewed-by: Matthew Sackman <[email protected]> TryBot-Result: CUEcueckoo <[email protected]> Unity-Result: CUE porcuepine <[email protected]>
1 parent a0138fb commit 92330b4

19 files changed

+1124
-800
lines changed

cue/testdata/benchmarks/issue1684.txtar

+25-33
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,15 @@ nestedClosed: passing: {
6262
D: {id: {}} | {[string]: D}
6363
}
6464
-- out/evalalpha/stats --
65-
Leaks: 2533
66-
Freed: 612
67-
Reused: 612
68-
Allocs: 2533
65+
Leaks: 2135
66+
Freed: 658
67+
Reused: 658
68+
Allocs: 2135
6969
Retain: 0
7070

71-
Unifications: 707
72-
Conjuncts: 5373
73-
Disjuncts: 1102
71+
Unifications: 475
72+
Conjuncts: 4781
73+
Disjuncts: 918
7474
-- out/evalalpha --
7575
(struct){
7676
#Secret: (#struct){
@@ -127,12 +127,6 @@ Disjuncts: 1102
127127
id: (struct){ |((struct){
128128
id: (struct){
129129
}
130-
}, (struct){
131-
id: (struct){ |((struct){
132-
id: (struct){
133-
}
134-
}, (struct){
135-
}) }
136130
}, (struct){
137131
}) }
138132
}, (struct){
@@ -149,28 +143,26 @@ diff old new
149143
-Freed: 1064333
150144
-Reused: 1064282
151145
-Allocs: 51
152-
+Leaks: 2533
153-
+Freed: 612
154-
+Reused: 612
155-
+Allocs: 2533
146+
+Leaks: 2135
147+
+Freed: 658
148+
+Reused: 658
149+
+Allocs: 2135
156150
Retain: 0
157151

158152
-Unifications: 792123
159153
-Conjuncts: 2480117
160154
-Disjuncts: 1064333
161-
+Unifications: 707
162-
+Conjuncts: 5373
163-
+Disjuncts: 1102
155+
+Unifications: 475
156+
+Conjuncts: 4781
157+
+Disjuncts: 918
164158
-- diff/-out/evalalpha<==>+out/eval --
165159
diff old new
166160
--- old
167161
+++ new
168-
@@ -54,35 +54,11 @@
169-
id: (struct){
170-
}
162+
@@ -56,36 +56,6 @@
171163
}, (struct){
172-
- }) }
173-
- }, (struct){
164+
}) }
165+
}, (struct){
174166
- id: (struct){ |((struct){
175167
- id: (struct){
176168
- }
@@ -198,14 +190,14 @@ diff old new
198190
- id: (struct){ |((struct){
199191
- id: (struct){
200192
- }
201-
+ id: (struct){ |((struct){
202-
+ id: (struct){
203-
+ }
204-
+ }, (struct){
205-
+ }) }
206-
}, (struct){
207-
}) }
208-
}, (struct){
193+
- }, (struct){
194+
- }) }
195+
- }, (struct){
196+
}) }
197+
}
198+
}
199+
-- diff/explanation --
200+
New algorithm is better at trimming recursive disjunctions.
209201
-- out/eval/stats --
210202
Leaks: 0
211203
Freed: 1064333

cue/testdata/benchmarks/listdisj.txtar

+11-11
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,6 @@ Retain: 0
6464
Unifications: 15
6565
Conjuncts: 43
6666
Disjuncts: 4
67-
-- out/evalalpha --
68-
(struct){
69-
#T: (list){
70-
0: (string){ "d" }
71-
}
72-
x: ~(#T)
73-
y: ~(#T)
74-
z: ~(#T)
75-
v: ~(#T)
76-
#X: ~(#T)
77-
}
7867
-- diff/-out/evalalpha/stats<==>+out/eval/stats --
7968
diff old new
8069
--- old
@@ -96,6 +85,17 @@ diff old new
9685
+Unifications: 15
9786
+Conjuncts: 43
9887
+Disjuncts: 4
88+
-- out/evalalpha --
89+
(struct){
90+
#T: (list){
91+
0: (string){ "d" }
92+
}
93+
x: ~(#T)
94+
y: ~(#T)
95+
z: ~(#T)
96+
v: ~(#T)
97+
#X: ~(#T)
98+
}
9999
-- diff/-out/evalalpha<==>+out/eval --
100100
diff old new
101101
--- old

cue/testdata/comprehensions/errors.txtar

+14-5
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,7 @@ Result:
6868
// [eval]
6969
circularIf: (struct){
7070
#list: (#struct){
71-
tail: ((null|struct)){ |(*(null){ null }, (#struct){
72-
tail: (null){ null }
73-
}) }
71+
tail: (null){ null }
7472
}
7573
}
7674
circularFor: (_|_){
@@ -116,7 +114,18 @@ diff old new
116114
circularFor.#list: cannot range over tail != null (found bool, want list or struct):
117115
./in.cue:12:12
118116
intField: integer fields not supported:
119-
@@ -35,10 +34,6 @@
117+
@@ -13,9 +12,7 @@
118+
// [eval]
119+
circularIf: (struct){
120+
#list: (#struct){
121+
- tail: ((null|struct)){ |(*(null){ null }, (#struct){
122+
- tail: (null){ null }
123+
- }) }
124+
+ tail: (null){ null }
125+
}
126+
}
127+
circularFor: (_|_){
128+
@@ -35,10 +32,6 @@
120129
intField: (_|_){
121130
// [eval] intField: integer fields not supported:
122131
// ./in.cue:27:4
@@ -127,7 +136,7 @@ diff old new
127136
}
128137
conflictRangingOverSelf: (_|_){
129138
// [eval]
130-
@@ -49,7 +44,6 @@
139+
@@ -49,7 +42,6 @@
131140
// [eval] conflictRangingOverSelf.x.age: conflicting values int and "age" (mismatched types int and string):
132141
// ./in.cue:36:9
133142
// ./in.cue:40:3

0 commit comments

Comments
 (0)