Skip to content

Commit

Permalink
internal/core/eval: handle structural cycles
Browse files Browse the repository at this point in the history
Issue #29
Issue #42

Change-Id: I86191d7bf4fdcf8705d740171aedd81e04819dd5
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/6522
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
  • Loading branch information
mpvl committed Jul 22, 2020
1 parent 50dac24 commit 711bbb1
Show file tree
Hide file tree
Showing 17 changed files with 1,765 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ b:
}
b: (struct){
e: (int){ 3 }
f: (_){ _ }
f: (int){ 3 }
}
}
11 changes: 8 additions & 3 deletions cue/testdata/cycle/023_reentrance.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ fib12: 144
}).out
}
-- out/eval --
(struct){
(_|_){
// [structural cycle]
fibRec: (struct){
nn: (int){ int }
out: (_|_){
Expand All @@ -93,6 +94,10 @@ fib12: 144
n: (int){ int }
}
fib2: (int){ 1 }
fib7: (int){ 13 }
fib12: (int){ 144 }
fib7: (_|_){
// [structural cycle]
}
fib12: (_|_){
// [structural cycle]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,26 @@ c2: (*{
-- out/eval --
(struct){
a1: (_|_){
// [incomplete]
// [incomplete] incomplete cause disjunction
}
a2: (_|_){
// [incomplete]
// [incomplete] incomplete cause disjunction
}
a3: (int){ 1 }
b1: (_|_){
// [incomplete] ambiguous disjunction
}
b2: (_|_){
// [incomplete] ambiguous disjunction
}
c1: (_|_){
// [incomplete] ambiguous disjunction
}
c2: (_|_){
// [incomplete] ambiguous disjunction
}
b1: (int){ |((int){ 0 }, (int){ 1 }) }
b2: (int){ |((int){ 1 }, (int){ 0 }) }
c1: (struct){ |((struct){
a: (int){ 1 }
b: (int){ 2 }
}, (struct){
b: (int){ 1 }
a: (int){ 2 }
}) }
c2: (struct){ |((struct){
a: (int){ 2 }
b: (int){ 1 }
}, (struct){
b: (int){ 2 }
a: (int){ 1 }
}) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,14 @@ Result:
xa2: (int){ 8 }
xa3: (int){ 6 }
xa4: (int){ 10 }
xb1: (int){ 8 }
xb2: (int){ 8 }
xb3: (int){ 6 }
xb4: (int){ 10 }
xb1: (int){ |((int){ 8 }, (int){ 9 }) }
xb2: (_|_){
// [incomplete]
}
xb3: (int){ |((int){ 6 }, (int){ 9 }) }
xb4: (_|_){
// [cycle] cycle error
}
xc1: (int){ |((int){ 8 }, (int){ 9 }) }
xc2: (int){ 8 }
xc3: (int){ 6 }
Expand Down Expand Up @@ -202,10 +206,14 @@ Result:
// [eval] incompatible values 7 and 6:
// ./in.cue:44:6
}
xf1: (int){ 8 }
xf2: (int){ 8 }
xf3: (int){ 6 }
xf4: (int){ 10 }
xf1: (int){ |((int){ 8 }, (int){ 9 }) }
xf2: (_|_){
// [incomplete]
}
xf3: (int){ |((int){ 6 }, (int){ 9 }) }
xf4: (_|_){
// [cycle] cycle error
}
z1: (int){ |((int){ 11 }, (int){ 13 }) }
z2: (int){ 10 }
z3: (int){ 8 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,14 @@ Result:
xa2: (int){ 8 }
xa3: (int){ 6 }
xa4: (int){ 10 }
xb1: (int){ 8 }
xb2: (int){ 8 }
xb1: (int){ |(*(int){ 8 }, (int){ 9 }) }
xb2: (_|_){
// [incomplete]
}
xb3: (int){ 6 }
xb4: (int){ 10 }
xb4: (_|_){
// [cycle] cycle error
}
xc1: (int){ |(*(int){ 8 }, (int){ 9 }) }
xc2: (int){ 8 }
xc3: (int){ 6 }
Expand Down
150 changes: 150 additions & 0 deletions cue/testdata/cycle/disjunction.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
-- in.cue --

// cycle is a structural cycle
cycle: a: cycle

// reference to outside structural cycle
r1a: cycle | int
r1b: int | cycle

r2a: cycle | 1
r2b: 1 | cycle

r3a: cycle | null
r3b: null | cycle

r4a: cycle | {}
r4b: {} | cycle

r5a: cycle | []
r5b: [] | cycle

// reference to ancestor node
s1a: x: s1a | int
s1b: x: int | s1b

s2a: x: s2a | 1
s2b: x: 1 | s2b

s3a: x: s3a | null
s3b: x: null | s3b

s4a: x: s4a | {}
s4b: x: {} | s4b

s5a: x: s5a | []
s5b: x: [] | s5b



-- out/eval --
Errors:
structural cycle

Result:
(_|_){
// [structural cycle]
cycle: (_|_){
// [structural cycle]
a: (_|_){
// [structural cycle] structural cycle
a: (_|_){// 〈1;cycle〉
}
}
}
r1a: (int){ int }
r1b: (int){ int }
r2a: (int){ 1 }
r2b: (int){ 1 }
r3a: (null){ null }
r3b: (null){ null }
r4a: (struct){
}
r4b: (struct){
}
r5a: (#list){
}
r5b: (#list){
}
s1a: (struct){
x: (int){ int }
}
s1b: (struct){
x: (int){ int }
}
s2a: (struct){
x: (int){ 1 }
}
s2b: (struct){
x: (int){ 1 }
}
s3a: (struct){
x: (null){ null }
}
s3b: (struct){
x: (null){ null }
}
s4a: (struct){
x: (struct){
}
}
s4b: (struct){
x: (struct){
}
}
s5a: (struct){
x: (#list){
}
}
s5b: (struct){
x: (#list){
}
}
}
-- out/compile --
--- in.cue
{
cycle: {
a: 〈1;cycle〉
}
r1a: (〈0;cycle〉|int)
r1b: (int|〈0;cycle〉)
r2a: (〈0;cycle〉|1)
r2b: (1|〈0;cycle〉)
r3a: (〈0;cycle〉|null)
r3b: (null|〈0;cycle〉)
r4a: (〈0;cycle〉|{})
r4b: ({}|〈0;cycle〉)
r5a: (〈0;cycle〉|[])
r5b: ([]|〈0;cycle〉)
s1a: {
x: (〈1;s1a〉|int)
}
s1b: {
x: (int|〈1;s1b〉)
}
s2a: {
x: (〈1;s2a〉|1)
}
s2b: {
x: (1|〈1;s2b〉)
}
s3a: {
x: (〈1;s3a〉|null)
}
s3b: {
x: (null|〈1;s3b〉)
}
s4a: {
x: (〈1;s4a〉|{})
}
s4b: {
x: ({}|〈1;s4b〉)
}
s5a: {
x: (〈1;s5a〉|[])
}
s5b: {
x: ([]|〈1;s5b〉)
}
}

0 comments on commit 711bbb1

Please sign in to comment.