Skip to content

Commit

Permalink
internal/core/adt: fix self reference issue
Browse files Browse the repository at this point in the history
Evaluating comprehension sources was done using
"yield" mode. This caused sets to be evaluated out
of band, causing structs to be closed before fields
can be added.

We now, instead, rely on the recursive call-by-need
behavior in combination with the freezing mechanism.
In the future we plan to move to a scheduler that
relies fully on either call by need or scheduling, but
for now this will have to do.

comprehension.txtar: fixes a P0 bug

freeze.txtar: fixes the target issue.

It would also fix the comprehension.t1.ok tests if
we use "attemptOnly" instead of "finalize". But this
breaks issue 3616. It is either way unclear what the
correct behavior should be and V2 also errors here,
so it is not the worst.

This change would also fix a possible issue with
propagating up an incomplete error. Also here the
behavior is the same as V2, so no problem for now.

adt.txtar: the changes are benign and due to reordering.

Fixes #3178

Signed-off-by: Marcel van Lohuizen <[email protected]>
Change-Id: I94e49767d59a5d0c13f9ebb2ce8882f8c7a68051
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1206318
Reviewed-by: Daniel Martí <[email protected]>
Unity-Result: CUE porcuepine <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
  • Loading branch information
mpvl committed Dec 24, 2024
1 parent 0b6a4e8 commit db3a7c9
Show file tree
Hide file tree
Showing 4 changed files with 286 additions and 158 deletions.
161 changes: 41 additions & 120 deletions cue/testdata/cycle/comprehension.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -310,23 +310,19 @@ issue2367: {
}

-- out/evalalpha/stats --
Leaks: 778
Leaks: 782
Freed: 63
Reused: 63
Allocs: 778
Allocs: 782
Retain: 0

Unifications: 498
Conjuncts: 2977
Unifications: 502
Conjuncts: 3031
Disjuncts: 196
-- out/evalalpha --
Errors:
selfReferential.insertionError.A: adding field foo3 not allowed as field set was already referenced:
./in.cue:117:14
siblingInsertion.t2.p1.deployment: adding field logging not allowed as field set was already referenced:
./in.cue:277:21
siblingInsertion.t2.p2.deployment: adding field logging not allowed as field set was already referenced:
./in.cue:292:21

Result:
(_|_){
Expand Down Expand Up @@ -651,8 +647,7 @@ Result:
}
}
}
siblingInsertion: (_|_){
// [eval]
siblingInsertion: (struct){
t1: (struct){
p1: (struct){
D: (struct){
Expand Down Expand Up @@ -685,28 +680,35 @@ Result:
}
}
}
t2: (_|_){
// [eval]
p1: (_|_){
// [eval] siblingInsertion.t2.p1.deployment: adding field logging not allowed as field set was already referenced:
// ./in.cue:277:21
t2: (struct){
p1: (struct){
D: (struct){
logging: (_){ _ }
}
deployment: (_|_){
// [eval] siblingInsertion.t2.p1.deployment: adding field logging not allowed as field set was already referenced:
// ./in.cue:277:21
deployment: (struct){
logging: (struct){
env2: (struct){
ENV: (string){ "True" }
}
env: (struct){
ENV: (string){ "True" }
}
}
}
}
p2: (_|_){
// [eval] siblingInsertion.t2.p2.deployment: adding field logging not allowed as field set was already referenced:
// ./in.cue:292:21
p2: (struct){
D: (struct){
logging: (_){ _ }
}
deployment: (_|_){
// [eval] siblingInsertion.t2.p2.deployment: adding field logging not allowed as field set was already referenced:
// ./in.cue:292:21
deployment: (struct){
logging: (struct){
env2: (struct){
ENV: (string){ "True" }
}
env: (struct){
ENV: (string){ "True" }
}
}
}
}
}
Expand All @@ -719,19 +721,15 @@ Result:
diff old new
--- old
+++ new
@@ -1,5 +1,10 @@
@@ -1,5 +1,6 @@
Errors:
-selfReferential.insertionError.A: field foo3 not allowed by earlier comprehension or reference cycle
+selfReferential.insertionError.A: adding field foo3 not allowed as field set was already referenced:
+ ./in.cue:117:14
+siblingInsertion.t2.p1.deployment: adding field logging not allowed as field set was already referenced:
+ ./in.cue:277:21
+siblingInsertion.t2.p2.deployment: adding field logging not allowed as field set was already referenced:
+ ./in.cue:292:21

Result:
(_|_){
@@ -19,7 +24,9 @@
@@ -19,7 +20,9 @@
B: (struct){
a: (struct){
parent: (string){ "" }
Expand All @@ -742,7 +740,7 @@ diff old new
}
}
}
@@ -52,17 +59,12 @@
@@ -52,17 +55,12 @@
}
}
_e: (#struct){
Expand All @@ -766,7 +764,7 @@ diff old new
}
}
e: (#struct){
@@ -76,12 +78,7 @@
@@ -76,12 +74,7 @@
}
f2: (#struct){
a: (#struct){
Expand All @@ -780,7 +778,7 @@ diff old new
}
}
}
@@ -127,9 +124,9 @@
@@ -127,9 +120,9 @@
insertionError: (_|_){
// [eval]
A: (_|_){
Expand All @@ -792,7 +790,7 @@ diff old new
}
}
acrossOr: (struct){
@@ -254,27 +251,31 @@
@@ -254,27 +247,31 @@
issue1881: (struct){
p1: (struct){
o: (#struct){
Expand Down Expand Up @@ -845,7 +843,7 @@ diff old new
}) }
}
p2: (struct){
@@ -290,7 +291,7 @@
@@ -290,7 +287,7 @@
}
}
o: (#struct){
Expand All @@ -854,90 +852,15 @@ diff old new
output: (#struct){
reject: (string){ "ok" }
}
@@ -320,15 +321,16 @@
@@ -320,7 +317,7 @@
resource: (string){ string }
}) }
o: (#struct){
- retry: (#struct){
- output: (#struct){
- reject: (string){ "ok" }
- }
- }
- }
- }
- }
- siblingInsertion: (struct){
+ retry: (struct){
+ output: (#struct){
+ reject: (string){ "ok" }
+ }
+ }
+ }
+ }
+ }
+ siblingInsertion: (_|_){
+ // [eval]
t1: (struct){
p1: (struct){
D: (struct){
@@ -361,35 +363,28 @@
}
}
}
- t2: (struct){
- p1: (struct){
- D: (struct){
- logging: (_){ _ }
- }
- deployment: (struct){
- logging: (struct){
- env2: (struct){
- ENV: (string){ "True" }
- }
- env: (struct){
- ENV: (string){ "True" }
- }
- }
- }
- }
- p2: (struct){
- D: (struct){
- logging: (_){ _ }
- }
- deployment: (struct){
- logging: (struct){
- env2: (struct){
- ENV: (string){ "True" }
- }
- env: (struct){
- ENV: (string){ "True" }
- }
- }
+ t2: (_|_){
+ // [eval]
+ p1: (_|_){
+ // [eval] siblingInsertion.t2.p1.deployment: adding field logging not allowed as field set was already referenced:
+ // ./in.cue:277:21
+ D: (struct){
+ logging: (_){ _ }
+ }
+ deployment: (_|_){
+ // [eval] siblingInsertion.t2.p1.deployment: adding field logging not allowed as field set was already referenced:
+ // ./in.cue:277:21
+ }
+ }
+ p2: (_|_){
+ // [eval] siblingInsertion.t2.p2.deployment: adding field logging not allowed as field set was already referenced:
+ // ./in.cue:292:21
+ D: (struct){
+ logging: (_){ _ }
+ }
+ deployment: (_|_){
+ // [eval] siblingInsertion.t2.p2.deployment: adding field logging not allowed as field set was already referenced:
+ // ./in.cue:292:21
}
}
}
output: (#struct){
reject: (string){ "ok" }
}
-- diff/-out/evalalpha/stats<==>+out/eval/stats --
diff old new
--- old
Expand All @@ -948,17 +871,17 @@ diff old new
-Reused: 1260
-Allocs: 60
-Retain: 145
+Leaks: 778
+Leaks: 782
+Freed: 63
+Reused: 63
+Allocs: 778
+Allocs: 782
+Retain: 0

-Unifications: 832
-Conjuncts: 2525
-Disjuncts: 1404
+Unifications: 498
+Conjuncts: 2977
+Unifications: 502
+Conjuncts: 3031
+Disjuncts: 196
-- out/eval/stats --
Leaks: 50
Expand All @@ -972,8 +895,6 @@ Conjuncts: 2525
Disjuncts: 1404
-- diff/explanation --
B.a.children: now correctly marked as incomplete
-- diff/todo/p0 --
siblingInsertion.t2: errors
-- diff/todo/p2 --
issue1881.#AllOutputs.retry: additional entry.
Might be error in practice and okay.
Expand Down
44 changes: 8 additions & 36 deletions cue/testdata/cycle/freeze.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,6 @@ comprehension.t3.err.a: adding field xq not allowed as field set was already ref
./comprehension.cue:82:13
comprehension.moreSpecific.err.a.x: adding field z not allowed as field set was already referenced:
./comprehension.cue:114:9
issue3178.output: adding field Value not allowed as field set was already referenced:
./issue3178.cue:9:23

Result:
(_|_){
Expand Down Expand Up @@ -295,23 +293,20 @@ Result:
}
}
}
issue3178: (_|_){
// [eval] issue3178.output: adding field Value not allowed as field set was already referenced:
// ./issue3178.cue:9:23
issue3178: (struct){
input: (#list){
0: (string){ "Value" }
}
output: (_|_){
// [eval] issue3178.output: adding field Value not allowed as field set was already referenced:
// ./issue3178.cue:9:23
output: (struct){
Value: (bool){ true }
}
}
}
-- diff/-out/evalalpha<==>+out/eval --
diff old new
--- old
+++ new
@@ -1,11 +1,12 @@
@@ -1,11 +1,10 @@
Errors:
-comprehension.moreSpecific.err.a: field z not allowed by earlier comprehension or reference cycle
-comprehension.t1.ok.p0.x: field z not allowed by earlier comprehension or reference cycle
Expand All @@ -326,12 +321,10 @@ diff old new
+ ./comprehension.cue:82:13
+comprehension.moreSpecific.err.a.x: adding field z not allowed as field set was already referenced:
+ ./comprehension.cue:114:9
+issue3178.output: adding field Value not allowed as field set was already referenced:
+ ./issue3178.cue:9:23

Result:
(_|_){
@@ -12,73 +13,65 @@
@@ -12,73 +11,65 @@
// [eval]
comprehension: (_|_){
// [eval]
Expand Down Expand Up @@ -455,7 +448,7 @@ diff old new
}
}
}
@@ -89,9 +82,9 @@
@@ -89,9 +80,9 @@
err: (_|_){
// [eval]
a: (_|_){
Expand All @@ -468,7 +461,7 @@ diff old new
}
}
}
@@ -99,16 +92,14 @@
@@ -99,16 +90,14 @@
// [eval]
err: (_|_){
// [eval]
Expand All @@ -491,7 +484,7 @@ diff old new
}
}
}
@@ -132,10 +123,10 @@
@@ -132,10 +121,10 @@
err: (_|_){
// [eval]
a: (_|_){
Expand All @@ -504,27 +497,6 @@ diff old new
}
}
}
@@ -151,12 +142,15 @@
}
}
}
- issue3178: (struct){
+ issue3178: (_|_){
+ // [eval] issue3178.output: adding field Value not allowed as field set was already referenced:
+ // ./issue3178.cue:9:23
input: (#list){
0: (string){ "Value" }
}
- output: (struct){
- Value: (bool){ true }
+ output: (_|_){
+ // [eval] issue3178.output: adding field Value not allowed as field set was already referenced:
+ // ./issue3178.cue:9:23
}
}
}
-- diff/todo/p3 --
Error path location could improve.
-- diff/explanation --
v0.7 fixes bugs in v0.6:
- t1 should be incomplete error, as it is fixable.
Expand Down
Loading

0 comments on commit db3a7c9

Please sign in to comment.