Skip to content

Commit

Permalink
internal/core/adt: split conjunct trees based on prefix
Browse files Browse the repository at this point in the history
Before this change, any conjunct referred to was inserted
at the insertion point in full. Top-level conjuncts have
a tree representing the origin of their definition and
embedding. This caused the closedness rules to be repeated
when they should not, resulting in spurious "field not
allowed" errors.

The new algorithm splits a conjunct into branches with
roots that are shared with the insertion point removed.
This ensures that references that are in scope of a
definition do not get spuriously inserted.

Fixes #3330
Fixes #3331

Signed-off-by: Marcel van Lohuizen <[email protected]>
Change-Id: I7a573f9576d3c46374647045d8ec226a1cd543b3
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1199272
Reviewed-by: Matthew Sackman <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
Reviewed-by: Daniel Martí <[email protected]>
Unity-Result: CUE porcuepine <[email protected]>
  • Loading branch information
mpvl committed Aug 12, 2024
1 parent 53bbdad commit 8e02b92
Show file tree
Hide file tree
Showing 16 changed files with 211 additions and 386 deletions.
4 changes: 2 additions & 2 deletions cue/testdata/benchmarks/inlinedisjunction.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Allocs: 147
Retain: 0

Unifications: 17
Conjuncts: 199
Conjuncts: 198
Disjuncts: 76
-- out/eval --
(struct){
Expand Down Expand Up @@ -60,7 +60,7 @@ diff old new
-Conjuncts: 13409
-Disjuncts: 4674
+Unifications: 17
+Conjuncts: 199
+Conjuncts: 198
+Disjuncts: 76
-- out/eval/stats --
Leaks: 0
Expand Down
4 changes: 2 additions & 2 deletions cue/testdata/benchmarks/issue1684.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Allocs: 2533
Retain: 0

Unifications: 707
Conjuncts: 5878
Conjuncts: 5373
Disjuncts: 1102
-- out/evalalpha --
(struct){
Expand Down Expand Up @@ -159,7 +159,7 @@ diff old new
-Conjuncts: 2480117
-Disjuncts: 1064333
+Unifications: 707
+Conjuncts: 5878
+Conjuncts: 5373
+Disjuncts: 1102
-- diff/-out/evalalpha<==>+out/eval --
diff old new
Expand Down
4 changes: 2 additions & 2 deletions cue/testdata/benchmarks/listdedup.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Allocs: 163
Retain: 0

Unifications: 53
Conjuncts: 431
Conjuncts: 407
Disjuncts: 40
-- out/eval --
(struct){
Expand Down Expand Up @@ -226,7 +226,7 @@ diff old new
-Conjuncts: 100730
-Disjuncts: 24097
+Unifications: 53
+Conjuncts: 431
+Conjuncts: 407
+Disjuncts: 40
-- out/eval/stats --
Leaks: 0
Expand Down
4 changes: 2 additions & 2 deletions cue/testdata/cycle/023_reentrance.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Allocs: 70
Retain: 0

Unifications: 62
Conjuncts: 227
Conjuncts: 225
Disjuncts: 0
-- out/evalalpha --
Errors:
Expand Down Expand Up @@ -133,7 +133,7 @@ diff old new
-Conjuncts: 464
-Disjuncts: 268
+Unifications: 62
+Conjuncts: 227
+Conjuncts: 225
+Disjuncts: 0
-- diff/-out/evalalpha<==>+out/eval --
diff old new
Expand Down
4 changes: 2 additions & 2 deletions cue/testdata/cycle/chain.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ Allocs: 19986
Retain: 0

Unifications: 7496
Conjuncts: 107561
Conjuncts: 107414
Disjuncts: 13651
-- out/evalalpha --
Errors:
Expand Down Expand Up @@ -735,7 +735,7 @@ diff old new
-Conjuncts: 3175
-Disjuncts: 1974
+Unifications: 7496
+Conjuncts: 107561
+Conjuncts: 107414
+Disjuncts: 13651
-- diff/-out/evalalpha<==>+out/eval --
diff old new
Expand Down
4 changes: 2 additions & 2 deletions cue/testdata/cycle/inline_non_recursive.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Allocs: 209
Retain: 0

Unifications: 194
Conjuncts: 1097
Conjuncts: 1034
Disjuncts: 0
-- out/evalalpha --
Errors:
Expand Down Expand Up @@ -203,7 +203,7 @@ diff old new
-Conjuncts: 2709
-Disjuncts: 1414
+Unifications: 194
+Conjuncts: 1097
+Conjuncts: 1034
+Disjuncts: 0
-- diff/-out/evalalpha<==>+out/eval --
diff old new
Expand Down
4 changes: 2 additions & 2 deletions cue/testdata/cycle/issue990.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ Allocs: 2198
Retain: 0

Unifications: 219
Conjuncts: 8714
Conjuncts: 6776
Disjuncts: 462
-- out/evalalpha --
Errors:
Expand Down Expand Up @@ -816,7 +816,7 @@ diff old new
-Conjuncts: 12056
-Disjuncts: 3258
+Unifications: 219
+Conjuncts: 8714
+Conjuncts: 6776
+Disjuncts: 462
-- diff/-out/evalalpha<==>+out/eval --
diff old new
Expand Down
Loading

0 comments on commit 8e02b92

Please sign in to comment.