Skip to content

Commit

Permalink
internal/core/adt: pre-evaluate pattern constraints
Browse files Browse the repository at this point in the history
The new evaluator allows disambiguating partially
evaluated values more accurately than the old evaluator
by treating pattern constraints as actual values.
For this to work, however, we need to evaluate these
values as if they were fields, and not just retain the
conjuncts.

Issue #2884

Signed-off-by: Marcel van Lohuizen <[email protected]>
Change-Id: I24cbcba66f95282f56f44eb3cacfd8633d2afc0f
  • Loading branch information
mpvl committed Apr 17, 2024
1 parent 306f356 commit 76beb07
Show file tree
Hide file tree
Showing 12 changed files with 2,476 additions and 1,531 deletions.
31 changes: 31 additions & 0 deletions cue/testdata/benchmarks/disjunction.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,37 @@ x: a0: {}
a0: {}
}
}
-- out/evalalpha/stats --
Leaks: 160
Freed: 2
Reused: 2
Allocs: 160
Retain: 0

Unifications: 44
Conjuncts: 249
Disjuncts: 118
-- diff/-out/evalalpha/stats<==>+out/eval/stats --
diff old new
--- old
+++ new
@@ -1,9 +1,9 @@
-Leaks: 0
-Freed: 82
-Reused: 74
-Allocs: 8
+Leaks: 160
+Freed: 2
+Reused: 2
+Allocs: 160
Retain: 0

-Unifications: 4
-Conjuncts: 143
-Disjuncts: 82
+Unifications: 44
+Conjuncts: 249
+Disjuncts: 118
-- out/eval/stats --
Leaks: 0
Freed: 82
Expand Down
167 changes: 23 additions & 144 deletions cue/testdata/benchmarks/issue1684.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,17 @@ out: #secrets & {
ONE: TWO: THREE: $secret: _id: "123"
}
-- out/evalalpha/stats --
Leaks: 11862
Freed: 2500
Reused: 2497
Allocs: 11865
Leaks: 80025
Freed: 18309
Reused: 18309
Allocs: 80025
Retain: 0

Unifications: 449
Conjuncts: 22643
Disjuncts: 4560
-- out/evalalpha --
Errors:
out.FOO: field not allowed:
./in.cue:14:11
./in.cue:4:22
./in.cue:7:2
./in.cue:17:2
out.ONE: field not allowed:
./in.cue:14:11
./in.cue:4:22
./in.cue:8:2
./in.cue:18:2

Result:
(_|_){
// [eval]
Unifications: 19610
Conjuncts: 161517
Disjuncts: 32694
-- out/eval --
(struct){
#Secret: (#struct){
$secret: (#struct){
id: (string){ string }
Expand All @@ -71,27 +57,17 @@ Result:
}
}, (#struct){
}) }
out: (_|_){
// [eval] out.FOO: field not allowed:
// ./in.cue:14:11
// ./in.cue:4:22
// ./in.cue:7:2
// ./in.cue:17:2
// out.ONE: field not allowed:
// ./in.cue:14:11
// ./in.cue:4:22
// ./in.cue:8:2
// ./in.cue:18:2
FOO: (struct){
$secret: (struct){
out: (#struct){
FOO: (#struct){
$secret: (#struct){
id: (string){ "100" }
_id: (string){ "100" }
}
}
ONE: (struct){
TWO: (struct){
THREE: (struct){
$secret: (struct){
ONE: (#struct){
TWO: (#struct){
THREE: (#struct){
$secret: (#struct){
id: (string){ "123" }
_id: (string){ "123" }
}
Expand All @@ -109,77 +85,18 @@ diff old new
-Freed: 1064043
-Reused: 1063992
-Allocs: 51
+Leaks: 11862
+Freed: 2500
+Reused: 2497
+Allocs: 11865
+Leaks: 80025
+Freed: 18309
+Reused: 18309
+Allocs: 80025
Retain: 0

-Unifications: 791999
-Conjuncts: 2479541
-Disjuncts: 1064043
+Unifications: 449
+Conjuncts: 22643
+Disjuncts: 4560
-- diff/-out/evalalpha<==>+out/eval --
diff old new
--- old
+++ new
@@ -1,4 +1,18 @@
-(struct){
+Errors:
+out.FOO: field not allowed:
+ ./in.cue:14:11
+ ./in.cue:4:22
+ ./in.cue:7:2
+ ./in.cue:17:2
+out.ONE: field not allowed:
+ ./in.cue:14:11
+ ./in.cue:4:22
+ ./in.cue:8:2
+ ./in.cue:18:2
+
+Result:
+(_|_){
+ // [eval]
#Secret: (#struct){
$secret: (#struct){
id: (string){ string }
@@ -12,17 +26,27 @@
}
}, (#struct){
}) }
- out: (#struct){
- FOO: (#struct){
- $secret: (#struct){
+ out: (_|_){
+ // [eval] out.FOO: field not allowed:
+ // ./in.cue:14:11
+ // ./in.cue:4:22
+ // ./in.cue:7:2
+ // ./in.cue:17:2
+ // out.ONE: field not allowed:
+ // ./in.cue:14:11
+ // ./in.cue:4:22
+ // ./in.cue:8:2
+ // ./in.cue:18:2
+ FOO: (struct){
+ $secret: (struct){
id: (string){ "100" }
_id: (string){ "100" }
}
}
- ONE: (#struct){
- TWO: (#struct){
- THREE: (#struct){
- $secret: (#struct){
+ ONE: (struct){
+ TWO: (struct){
+ THREE: (struct){
+ $secret: (struct){
id: (string){ "123" }
_id: (string){ "123" }
}
+Unifications: 19610
+Conjuncts: 161517
+Disjuncts: 32694
-- out/eval/stats --
Leaks: 0
Freed: 1064043
Expand All @@ -190,44 +107,6 @@ Retain: 0
Unifications: 791999
Conjuncts: 2479541
Disjuncts: 1064043
-- diff/todo/p0 --
out.FOO: incorrectly not allowed. This is a result of the overlay evaluating
non-overlay Vertices during the evaluation of disjunctions. This should be fixed
in a separate CL.
-- out/eval --
(struct){
#Secret: (#struct){
$secret: (#struct){
id: (string){ string }
_id: (string){ string }
}
}
#secrets: (#struct){ |((#struct){
$secret: (#struct){
id: (string){ string }
_id: (string){ string }
}
}, (#struct){
}) }
out: (#struct){
FOO: (#struct){
$secret: (#struct){
id: (string){ "100" }
_id: (string){ "100" }
}
}
ONE: (#struct){
TWO: (#struct){
THREE: (#struct){
$secret: (#struct){
id: (string){ "123" }
_id: (string){ "123" }
}
}
}
}
}
}
-- out/compile --
--- in.cue
{
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: 8924
Freed: 1044
Reused: 1042
Allocs: 8926
Leaks: 261590
Freed: 35214
Reused: 35213
Allocs: 261591
Retain: 0

Unifications: 1360
Conjuncts: 41949
Disjuncts: 2412
Unifications: 23412
Conjuncts: 326798
Disjuncts: 87912
-- out/eval --
(struct){
A: (#struct){ |((#struct){
Expand Down Expand Up @@ -216,18 +216,18 @@ diff old new
-Reused: 24051
-Allocs: 45
-Retain: 1
+Leaks: 8924
+Freed: 1044
+Reused: 1042
+Allocs: 8926
+Leaks: 261590
+Freed: 35214
+Reused: 35213
+Allocs: 261591
+Retain: 0

-Unifications: 18724
-Conjuncts: 100730
-Disjuncts: 24097
+Unifications: 1360
+Conjuncts: 41949
+Disjuncts: 2412
+Unifications: 23412
+Conjuncts: 326798
+Disjuncts: 87912
-- out/eval/stats --
Leaks: 0
Freed: 24096
Expand Down
47 changes: 39 additions & 8 deletions cue/testdata/benchmarks/listdisj.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,16 @@ v: #T
#X: 〈0;v〉
#X: 〈0;#T〉
}
-- out/eval/stats --
Leaks: 0
Freed: 447
Reused: 439
Allocs: 8
-- out/evalalpha/stats --
Leaks: 3340
Freed: 771
Reused: 771
Allocs: 3340
Retain: 0

Unifications: 287
Conjuncts: 894
Disjuncts: 447
Unifications: 2743
Conjuncts: 16921
Disjuncts: 1368
-- out/evalalpha --
(struct){
#T: (list){
Expand Down Expand Up @@ -460,6 +460,27 @@ Disjuncts: 447
0: (string){ "d" }
}) }
}
-- diff/-out/evalalpha/stats<==>+out/eval/stats --
diff old new
--- old
+++ new
@@ -1,9 +1,9 @@
-Leaks: 0
-Freed: 447
-Reused: 439
-Allocs: 8
+Leaks: 3340
+Freed: 771
+Reused: 771
+Allocs: 3340
Retain: 0

-Unifications: 287
-Conjuncts: 894
-Disjuncts: 447
+Unifications: 2743
+Conjuncts: 16921
+Disjuncts: 1368
-- diff/-out/evalalpha<==>+out/eval --
diff old new
--- old
Expand Down Expand Up @@ -874,6 +895,16 @@ diff old new
+ 0: (string){ "d" }
+ }) }
}
-- out/eval/stats --
Leaks: 0
Freed: 447
Reused: 439
Allocs: 8
Retain: 0

Unifications: 287
Conjuncts: 894
Disjuncts: 447
-- diff/todo/p0 --
Structural cycles detected too late.
-- diff/todo/p3 --
Expand Down
Loading

0 comments on commit 76beb07

Please sign in to comment.