Skip to content

Commit

Permalink
internal/core/adt: add tests for ring-shaped cycles
Browse files Browse the repository at this point in the history
Tests for two chains for fields referring to
each other in a circular fashion.

Note that one of the tests is currently broken,
even though the comments pretend they are not.
The diff/todo section mentions it, thouhg.

This is part of fix needed for
Issue #3476

Signed-off-by: Marcel van Lohuizen <mpvl@gmail.com>
Change-Id: Id24e0ce090faca908663ee598544b697578a8f10
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1202215
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Matthew Sackman <matthew@cue.works>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
  • Loading branch information
mpvl committed Oct 8, 2024
1 parent f8c5520 commit 695d6d3
Showing 1 changed file with 287 additions and 13 deletions.
300 changes: 287 additions & 13 deletions cue/testdata/cycle/constraints.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,36 @@ mutuallyTriggeringCycle: t1: {
x: y
x: c: y
}
-- ring.cue --
brokenRing: t1: {
// NOTE that two permutations here have different results. That is less
// of an issue than it seems, as the structural cycle is hidden behind
// an optional path, which we generally allow.
// TODO: it would be nicer, though, if the representation were consistent.
p1: {
D: a?: T
T: b: D
}
p2: {
T: b: D
D: a?: T
}
}

brokenRing: t2: p1: {
D: [string]: T
T: b: D
}

brokenRing: t2: p2: {
T: b: D
D: [string]: T
}

cyclicRing: t1: {
D: a: T
T: b: D
}

-- out/compile --
--- in.cue
Expand Down Expand Up @@ -433,18 +463,77 @@ mutuallyTriggeringCycle: t1: {
}
}
}
--- ring.cue
{
brokenRing: {
t1: {
p1: {
D: {
a?: 〈1;T〉
}
T: {
b: 〈1;D〉
}
}
p2: {
T: {
b: 〈1;D〉
}
D: {
a?: 〈1;T〉
}
}
}
}
brokenRing: {
t2: {
p1: {
D: {
[string]: 〈1;T〉
}
T: {
b: 〈1;D〉
}
}
}
}
brokenRing: {
t2: {
p2: {
T: {
b: 〈1;D〉
}
D: {
[string]: 〈1;T〉
}
}
}
}
cyclicRing: {
t1: {
D: {
a: 〈1;T〉
}
T: {
b: 〈1;D〉
}
}
}
}
-- out/eval/stats --
Leaks: 0
Freed: 143
Reused: 130
Freed: 173
Reused: 160
Allocs: 13
Retain: 4
Retain: 8

Unifications: 143
Conjuncts: 321
Disjuncts: 147
Unifications: 173
Conjuncts: 360
Disjuncts: 181
-- out/evalalpha --
Errors:
brokenRing.t1.p1.T.b: structural cycle
cyclicRing.t1.T.b: structural cycle
mutuallyTriggeringCycle.t1.x.c.b.b.b.b.b: structural cycle
noCancelSelfInvoke.t1.x.c.b.b: structural cycle
noCancelSelfInvoke.t1.x.c.c: structural cycle
Expand Down Expand Up @@ -778,13 +867,78 @@ Result:
}
}
}
brokenRing: (_|_){
// [structural cycle]
t1: (_|_){
// [structural cycle]
p1: (_|_){
// [structural cycle]
D: (struct){
a?: ~(brokenRing.t1.p1.T)
}
T: (_|_){
// [structural cycle]
b: (_|_){
// [structural cycle] brokenRing.t1.p1.T.b: structural cycle
}
}
}
p2: (struct){
T: (struct){
b: ~(brokenRing.t1.p2.D)
}
D: (struct){
a?: (_|_){
// [structural cycle] brokenRing.t1.p2.D.a: structural cycle
}
}
}
}
t2: (struct){
p1: (struct){
D: (struct){
}
T: (struct){
b: (struct){
}
}
}
p2: (struct){
T: (struct){
b: (struct){
}
}
D: (struct){
}
}
}
}
cyclicRing: (_|_){
// [structural cycle]
t1: (_|_){
// [structural cycle]
D: (_|_){
// [structural cycle]
a: ~(cyclicRing.t1.T)
}
T: (_|_){
// [structural cycle]
b: (_|_){
// [structural cycle] cyclicRing.t1.T.b: structural cycle
}
}
}
}
}
-- diff/-out/evalalpha<==>+out/eval --
diff old new
--- old
+++ new
@@ -1,9 +1,9 @@
@@ -1,12 +1,11 @@
Errors:
brokenRing.t1.p1.T.b: structural cycle
-cyclicRing.t1.D.a.b: structural cycle
cyclicRing.t1.T.b: structural cycle
-mutuallyTriggeringCycle.t1.x.c.b.b.b.b: structural cycle
-noCancelSelfInvoke.t1.x.c.b.b.b: structural cycle
+mutuallyTriggeringCycle.t1.x.c.b.b.b.b.b: structural cycle
Expand All @@ -796,7 +950,7 @@ diff old new
selfTriggerCycle.t1.#T.b.b: structural cycle
selfTriggerCycle.t2.b.c.a: structural cycle

@@ -149,18 +149,10 @@
@@ -152,18 +151,10 @@
#D: (#struct){
}
#E: (#struct){
Expand All @@ -819,7 +973,7 @@ diff old new
}
#S: (#struct){
y: (#struct){
@@ -198,18 +190,15 @@
@@ -201,18 +192,15 @@
// [structural cycle]
c: (_|_){
// [structural cycle]
Expand All @@ -844,7 +998,7 @@ diff old new
}
}
}
@@ -218,12 +207,7 @@
@@ -221,12 +209,7 @@
// [structural cycle]
t1: (_|_){
// [structural cycle]
Expand All @@ -858,7 +1012,7 @@ diff old new
#T: (_|_){
// [structural cycle]
b: (_|_){
@@ -263,13 +247,7 @@
@@ -266,13 +249,7 @@
c: (_|_){
// [structural cycle]
b: (_|_){
Expand All @@ -873,7 +1027,7 @@ diff old new
}
}
}
@@ -284,20 +262,29 @@
@@ -287,20 +264,29 @@
// [structural cycle]
a: (_|_){
// [structural cycle]
Expand Down Expand Up @@ -913,7 +1067,7 @@ diff old new
}
}
}
@@ -333,7 +320,10 @@
@@ -336,7 +322,10 @@
b: (_|_){
// [structural cycle]
b: (_|_){
Expand All @@ -925,11 +1079,55 @@ diff old new
}
}
}
@@ -352,12 +341,7 @@
p1: (_|_){
// [structural cycle]
D: (struct){
- a?: (_|_){
- // [structural cycle]
- b: (_|_){
- // [structural cycle] brokenRing.t1.p1.D.a.b: structural cycle
- }
- }
+ a?: ~(brokenRing.t1.p1.T)
}
T: (_|_){
// [structural cycle]
@@ -368,11 +352,7 @@
}
p2: (struct){
T: (struct){
- b: (struct){
- a?: (_|_){
- // [structural cycle] brokenRing.t1.p2.T.b.a: structural cycle
- }
- }
+ b: ~(brokenRing.t1.p2.D)
}
D: (struct){
a?: (_|_){
@@ -406,12 +386,7 @@
// [structural cycle]
D: (_|_){
// [structural cycle]
- a: (_|_){
- // [structural cycle]
- b: (_|_){
- // [structural cycle] cyclicRing.t1.D.a.b: structural cycle
- }
- }
+ a: ~(cyclicRing.t1.T)
}
T: (_|_){
// [structural cycle]
-- diff/todo/p2 --
issue1503: cycle detected too late (but not super late)
selfTriggerCycle.t1.a.b.b: cycle detected slightly too late
-- out/eval --
Errors:
brokenRing.t1.p1.T.b: structural cycle
cyclicRing.t1.D.a.b: structural cycle
cyclicRing.t1.T.b: structural cycle
mutuallyTriggeringCycle.t1.x.c.b.b.b.b: structural cycle
noCancelSelfInvoke.t1.x.c.b.b.b: structural cycle
noCancelSelfInvoke.t1.x.c.c: structural cycle
Expand Down Expand Up @@ -1273,4 +1471,80 @@ Result:
}
}
}
brokenRing: (_|_){
// [structural cycle]
t1: (_|_){
// [structural cycle]
p1: (_|_){
// [structural cycle]
D: (struct){
a?: (_|_){
// [structural cycle]
b: (_|_){
// [structural cycle] brokenRing.t1.p1.D.a.b: structural cycle
}
}
}
T: (_|_){
// [structural cycle]
b: (_|_){
// [structural cycle] brokenRing.t1.p1.T.b: structural cycle
}
}
}
p2: (struct){
T: (struct){
b: (struct){
a?: (_|_){
// [structural cycle] brokenRing.t1.p2.T.b.a: structural cycle
}
}
}
D: (struct){
a?: (_|_){
// [structural cycle] brokenRing.t1.p2.D.a: structural cycle
}
}
}
}
t2: (struct){
p1: (struct){
D: (struct){
}
T: (struct){
b: (struct){
}
}
}
p2: (struct){
T: (struct){
b: (struct){
}
}
D: (struct){
}
}
}
}
cyclicRing: (_|_){
// [structural cycle]
t1: (_|_){
// [structural cycle]
D: (_|_){
// [structural cycle]
a: (_|_){
// [structural cycle]
b: (_|_){
// [structural cycle] cyclicRing.t1.D.a.b: structural cycle
}
}
}
T: (_|_){
// [structural cycle]
b: (_|_){
// [structural cycle] cyclicRing.t1.T.b: structural cycle
}
}
}
}
}

0 comments on commit 695d6d3

Please sign in to comment.