Skip to content

Commit

Permalink
internal/core/adt: hacky alternative for cyclicReferences
Browse files Browse the repository at this point in the history
We did not yet implement cyclicReferences for the new
evaluator. This mechanism is an important aspect for performance.
It is hard to implement for the new evaluator, at least for now,
as we want to retain the flexibility of not having to evaluate
a referenced node first. Maybe later that is okay.
We implement an approximate alternative. This may give some
spurious structural cycles.

The idea is also that once we have structure sharing implemented,
we could probably implement a neater alternative to using
cyclicReferences.

Also, this change is blocking the implementation of structure
sharing. Altogether we think it is a good tradeoff to introduce
the new errors in favor of fixing the others.

Issue #2854
Issue #2884

Signed-off-by: Marcel van Lohuizen <[email protected]>
Change-Id: If5f9b0d570cd8d122bd535e1fbc9b3ceafa848ba
  • Loading branch information
mpvl committed Apr 17, 2024
1 parent 76beb07 commit 78589af
Show file tree
Hide file tree
Showing 13 changed files with 960 additions and 842 deletions.
28 changes: 14 additions & 14 deletions cue/testdata/benchmarks/issue1684.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ out: #secrets & {
ONE: TWO: THREE: $secret: _id: "123"
}
-- out/evalalpha/stats --
Leaks: 80025
Freed: 18309
Reused: 18309
Allocs: 80025
Leaks: 2115
Freed: 539
Reused: 539
Allocs: 2115
Retain: 0

Unifications: 19610
Conjuncts: 161517
Disjuncts: 32694
Unifications: 614
Conjuncts: 5842
Disjuncts: 846
-- out/eval --
(struct){
#Secret: (#struct){
Expand Down Expand Up @@ -85,18 +85,18 @@ diff old new
-Freed: 1064043
-Reused: 1063992
-Allocs: 51
+Leaks: 80025
+Freed: 18309
+Reused: 18309
+Allocs: 80025
+Leaks: 2115
+Freed: 539
+Reused: 539
+Allocs: 2115
Retain: 0

-Unifications: 791999
-Conjuncts: 2479541
-Disjuncts: 1064043
+Unifications: 19610
+Conjuncts: 161517
+Disjuncts: 32694
+Unifications: 614
+Conjuncts: 5842
+Disjuncts: 846
-- out/eval/stats --
Leaks: 0
Freed: 1064043
Expand Down
28 changes: 14 additions & 14 deletions cue/testdata/benchmarks/listdedup.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ C: #steps: #Script & {mount: [B]}

#ref: {a: 1} | {b: 2}
-- out/evalalpha/stats --
Leaks: 261590
Freed: 35214
Reused: 35213
Allocs: 261591
Leaks: 12448
Freed: 1388
Reused: 1387
Allocs: 12449
Retain: 0

Unifications: 23412
Conjuncts: 326798
Disjuncts: 87912
Unifications: 2716
Conjuncts: 48270
Disjuncts: 3272
-- out/eval --
(struct){
A: (#struct){ |((#struct){
Expand Down Expand Up @@ -216,18 +216,18 @@ diff old new
-Reused: 24051
-Allocs: 45
-Retain: 1
+Leaks: 261590
+Freed: 35214
+Reused: 35213
+Allocs: 261591
+Leaks: 12448
+Freed: 1388
+Reused: 1387
+Allocs: 12449
+Retain: 0

-Unifications: 18724
-Conjuncts: 100730
-Disjuncts: 24097
+Unifications: 23412
+Conjuncts: 326798
+Disjuncts: 87912
+Unifications: 2716
+Conjuncts: 48270
+Disjuncts: 3272
-- out/eval/stats --
Leaks: 0
Freed: 24096
Expand Down
68 changes: 48 additions & 20 deletions cue/testdata/cycle/023_reentrance.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@ Disjuncts: 0
Errors:
structural cycle:
./in.cue:3:25
structural cycle:
./in.cue:8:9
structural cycle:
./in.cue:8:38

Result:
(_|_){
Expand All @@ -100,28 +96,21 @@ Result:
n: (int){ int }
}
fib1: (int){ 1 }
fib2: (int){ 1 }
fib2: (_|_){
// [structural cycle] structural cycle:
// ./in.cue:3:25
}
fib3: (_|_){
// [structural cycle] structural cycle:
// ./in.cue:3:25
// structural cycle:
// ./in.cue:8:38
}
fib7: (_|_){
// [structural cycle] structural cycle:
// ./in.cue:3:25
// structural cycle:
// ./in.cue:8:9
// structural cycle:
// ./in.cue:8:38
}
fib12: (_|_){
// [structural cycle] structural cycle:
// ./in.cue:3:25
// structural cycle:
// ./in.cue:8:9
// structural cycle:
// ./in.cue:8:38
}
}
-- diff/-out/evalalpha/stats<==>+out/eval/stats --
Expand All @@ -139,7 +128,7 @@ diff old new
+Reused: 0
+Allocs: 70
+Retain: 0

-Unifications: 196
-Conjuncts: 464
-Disjuncts: 268
Expand All @@ -150,7 +139,18 @@ diff old new
diff old new
--- old
+++ new
@@ -16,10 +16,6 @@
@@ -1,10 +1,6 @@
Errors:
structural cycle:
./in.cue:3:25
-structural cycle:
- ./in.cue:8:9
-structural cycle:
- ./in.cue:8:38

Result:
(_|_){
@@ -16,10 +12,6 @@
// ./in.cue:7:5
// ./in.cue:3:35
// ./in.cue:5:5
Expand All @@ -161,7 +161,7 @@ diff old new
}
}
fib: (_|_){
@@ -26,9 +22,6 @@
@@ -26,33 +18,23 @@
// [incomplete] fib: non-concrete value int in operand to >=:
// ./in.cue:7:5
// ./in.cue:5:5
Expand All @@ -171,6 +171,36 @@ diff old new
n: (int){ int }
}
fib1: (int){ 1 }
- fib2: (int){ 1 }
+ fib2: (_|_){
+ // [structural cycle] structural cycle:
+ // ./in.cue:3:25
+ }
fib3: (_|_){
// [structural cycle] structural cycle:
// ./in.cue:3:25
- // structural cycle:
- // ./in.cue:8:38
}
fib7: (_|_){
// [structural cycle] structural cycle:
// ./in.cue:3:25
- // structural cycle:
- // ./in.cue:8:9
- // structural cycle:
- // ./in.cue:8:38
}
fib12: (_|_){
// [structural cycle] structural cycle:
// ./in.cue:3:25
- // structural cycle:
- // ./in.cue:8:9
- // structural cycle:
- // ./in.cue:8:38
}
}
-- diff/todo/p3 --
Note that it is okay for fib2 to fail.
-- out/eval/stats --
Leaks: 16
Freed: 180
Expand All @@ -181,8 +211,6 @@ Retain: 148
Unifications: 196
Conjuncts: 464
Disjuncts: 268
-- diff/todo/p3 --
Note that it is okay for fib2 to fail.
-- out/eval --
Errors:
structural cycle:
Expand Down
Loading

0 comments on commit 78589af

Please sign in to comment.