Skip to content

Commit

Permalink
internal/core/adt: fix stack overflow with comprehensions
Browse files Browse the repository at this point in the history
The issue was that evaluating an arc in the source of a
comprehension resulted in infinite recursion. The call
to unify that is removed can be removed, as it is already
called in the block above when it is necessary.

This is not a full fix, but is something that will be easier
to fix in the new evaluator.

Fixes #2367

Signed-off-by: Marcel van Lohuizen <[email protected]>
Change-Id: Ibcab74235097180094284f249750c3c0ec5d2845
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/557011
TryBot-Result: CUEcueckoo <[email protected]>
Reviewed-by: Daniel Martí <[email protected]>
Unity-Result: CUE porcuepine <[email protected]>
  • Loading branch information
mpvl authored and mvdan committed Jul 28, 2023
1 parent 538eb9c commit 33071c0
Show file tree
Hide file tree
Showing 43 changed files with 171 additions and 171 deletions.
16 changes: 8 additions & 8 deletions cue/testdata/benchmarks/issue2176.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ output: {
"2": (datastream & {marker: length: 14}).marker.position
}
-- out/eval/stats --
Leaks: 214
Freed: 5799
Reused: 5795
Allocs: 218
Retain: 1911
Leaks: 90
Freed: 4079
Reused: 4074
Allocs: 95
Retain: 1359

Unifications: 6005
Conjuncts: 14507
Disjuncts: 6864
Unifications: 4161
Conjuncts: 9489
Disjuncts: 4804
-- out/eval --
(struct){
#Datastream: (#struct){
Expand Down
8 changes: 4 additions & 4 deletions cue/testdata/comprehensions/015_list_comprehension.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ d:
-- out/eval/stats --
Leaks: 0
Freed: 19
Reused: 11
Allocs: 8
Retain: 14
Reused: 12
Allocs: 7
Retain: 10

Unifications: 19
Conjuncts: 35
Conjuncts: 36
Disjuncts: 23
-- out/eval --
(struct){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ Leaks: 3
Freed: 7
Reused: 2
Allocs: 8
Retain: 8
Retain: 7

Unifications: 8
Conjuncts: 11
Disjuncts: 13
Disjuncts: 12
-- out/eval --
(struct){
x: (struct){
Expand Down
2 changes: 1 addition & 1 deletion cue/testdata/comprehensions/closed.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Leaks: 2
Freed: 70
Reused: 64
Allocs: 8
Retain: 4
Retain: 3

Unifications: 58
Conjuncts: 103
Expand Down
18 changes: 9 additions & 9 deletions cue/testdata/comprehensions/errors.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,18 @@ conflictRangingOverSelf: {
}
}
-- out/eval/stats --
Leaks: 4
Freed: 27
Reused: 23
Allocs: 8
Retain: 6
Leaks: 1
Freed: 28
Reused: 22
Allocs: 7
Retain: 1

Unifications: 21
Unifications: 19
Conjuncts: 40
Disjuncts: 30
Disjuncts: 29
-- out/eval --
Errors:
conflictRangingOverSelf.x: conflicting values int and "age" (mismatched types int and string):
conflictRangingOverSelf.x.age: conflicting values int and "age" (mismatched types int and string):
./in.cue:36:9
./in.cue:40:3
./in.cue:41:9
Expand Down Expand Up @@ -102,7 +102,7 @@ Result:
// [eval]
name: (string){ "name" }
age: (_|_){
// [eval] conflictRangingOverSelf.x: conflicting values int and "age" (mismatched types int and string):
// [eval] conflictRangingOverSelf.x.age: conflicting values int and "age" (mismatched types int and string):
// ./in.cue:36:9
// ./in.cue:40:3
// ./in.cue:41:9
Expand Down
4 changes: 2 additions & 2 deletions cue/testdata/comprehensions/fields.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ Leaks: 1
Freed: 32
Reused: 26
Allocs: 7
Retain: 2
Retain: 1

Unifications: 33
Conjuncts: 40
Conjuncts: 41
Disjuncts: 33
-- out/eval --
(struct){
Expand Down
8 changes: 4 additions & 4 deletions cue/testdata/comprehensions/for.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ comprehensionBinds: {
b: {for _, _ in [1] {a: _}}
}
-- out/eval/stats --
Leaks: 4
Leaks: 2
Freed: 16
Reused: 12
Allocs: 8
Retain: 11
Allocs: 6
Retain: 7

Unifications: 20
Unifications: 18
Conjuncts: 18
Disjuncts: 21
-- out/eval --
Expand Down
4 changes: 2 additions & 2 deletions cue/testdata/comprehensions/iferror.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@ Leaks: 0
Freed: 43
Reused: 35
Allocs: 8
Retain: 18
Retain: 14

Unifications: 33
Conjuncts: 65
Conjuncts: 66
Disjuncts: 57
-- out/eval --
Errors:
Expand Down
10 changes: 5 additions & 5 deletions cue/testdata/comprehensions/issue1732.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ foo: {
}
}
-- out/eval/stats --
Leaks: 4
Leaks: 3
Freed: 118
Reused: 103
Allocs: 19
Retain: 14
Allocs: 18
Retain: 10

Unifications: 112
Unifications: 111
Conjuncts: 249
Disjuncts: 128
Disjuncts: 126
-- out/eval --
(struct){
networkingv1: (struct){
Expand Down
4 changes: 2 additions & 2 deletions cue/testdata/comprehensions/issue2171.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ Leaks: 0
Freed: 3
Reused: 0
Allocs: 3
Retain: 2
Retain: 0

Unifications: 3
Conjuncts: 5
Disjuncts: 5
Disjuncts: 3
-- out/eval --
(struct){
do: (struct){
Expand Down
2 changes: 1 addition & 1 deletion cue/testdata/comprehensions/issue843.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Leaks: 9
Freed: 55
Reused: 41
Allocs: 23
Retain: 20
Retain: 14

Unifications: 52
Conjuncts: 120
Expand Down
4 changes: 2 additions & 2 deletions cue/testdata/comprehensions/nested.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ Leaks: 0
Freed: 45
Reused: 26
Allocs: 19
Retain: 36
Retain: 33

Unifications: 35
Conjuncts: 95
Disjuncts: 78
Disjuncts: 75
-- out/eval --
(struct){
service: (struct){
Expand Down
6 changes: 3 additions & 3 deletions cue/testdata/comprehensions/pushdown.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -746,11 +746,11 @@ Leaks: 14
Freed: 394
Reused: 387
Allocs: 21
Retain: 120
Retain: 107

Unifications: 394
Conjuncts: 637
Disjuncts: 476
Conjuncts: 638
Disjuncts: 471
-- out/eval --
Errors:
embed.fail1.p: field not allowed:
Expand Down
10 changes: 5 additions & 5 deletions cue/testdata/cycle/chain.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,14 @@ issue2052: full: {
d: #Depth & {#in: tree}
}
-- out/eval/stats --
Leaks: 72
Leaks: 70
Freed: 1815
Reused: 1801
Allocs: 86
Retain: 195
Allocs: 84
Retain: 185

Unifications: 802
Conjuncts: 3177
Unifications: 800
Conjuncts: 3175
Disjuncts: 1974
-- out/eval --
(struct){
Expand Down
31 changes: 24 additions & 7 deletions cue/testdata/cycle/comprehension.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -303,16 +303,22 @@ selfReferential: fail: {
}
}

// avoid infinite recursion
issue2367: {
a: _
for x in [a] {a: x}
}

-- out/eval/stats --
Leaks: 48
Freed: 1268
Reused: 1256
Leaks: 50
Freed: 1270
Reused: 1260
Allocs: 60
Retain: 189
Retain: 145

Unifications: 828
Conjuncts: 2512
Disjuncts: 1437
Unifications: 832
Conjuncts: 2525
Disjuncts: 1404
-- out/eval --
Errors:
selfReferential.insertionError.A: field foo3 not allowed by earlier comprehension or reference cycle
Expand Down Expand Up @@ -710,6 +716,9 @@ Result:
}
}
}
issue2367: (struct){
a: (_){ _ }
}
}
-- out/compile --
--- in.cue
Expand Down Expand Up @@ -1194,4 +1203,12 @@ Result:
if 〈0;b〉 {}
}
}
issue2367: {
a: _
for _, x in [
〈1;a〉,
] {
a: 〈1;x〉
}
}
}
56 changes: 20 additions & 36 deletions cue/testdata/cycle/evaluate.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,15 @@ closeFail: {
}

-- out/eval/stats --
Leaks: 66
Freed: 95
Reused: 91
Allocs: 70
Retain: 136
Leaks: 57
Freed: 90
Reused: 86
Allocs: 61
Retain: 126

Unifications: 149
Conjuncts: 289
Disjuncts: 171
Unifications: 135
Conjuncts: 269
Disjuncts: 156
-- out/eval --
Errors:
closeCycle.a: structural cycle
Expand All @@ -126,6 +126,9 @@ closeFail.x.b: field not allowed:
./in.cue:104:6
./in.cue:105:5
letCycleFail.t1.a.c: structural cycle
listAddCycle.a: structural cycle
listAddCycle.b.0.0: structural cycle
listAddCycle.b.0.1: structural cycle
structCycle.a: structural cycle
structCycle.b.d: structural cycle
disjunctionCycle.a: cannot use 1 (type int) as list in argument 1 to and:
Expand All @@ -142,10 +145,8 @@ structCycle.c: structural cycle:
./in.cue:77:14
embedCycle: structural cycle:
./in.cue:83:11
listAddCycle.c.0.0: structural cycle:
./in.cue:89:5
listAddCycle.c.0.1: structural cycle:
./in.cue:89:5
listAddCycle.c: structural cycle:
./in.cue:89:6
listMulCycle.a: invalid operands 3 and [{a:{b:c}}] to '+' (type int and list):
./in.cue:95:5
./in.cue:95:9
Expand Down Expand Up @@ -303,44 +304,27 @@ Result:
listAddCycle: (_|_){
// [structural cycle]
a: (_|_){
// [structural cycle]
0: (_|_){
// [structural cycle] listAddCycle.c.0.0: structural cycle:
// ./in.cue:89:5
}
1: (_|_){
// [structural cycle] listAddCycle.c.0.0: structural cycle:
// ./in.cue:89:5
}
// [structural cycle] listAddCycle.a: structural cycle
}
b: (_|_){
// [structural cycle]
0: (_|_){
// [structural cycle] listAddCycle.c.0.0: structural cycle:
// ./in.cue:89:5
}
1: (_|_){
// [structural cycle] listAddCycle.c.0.0: structural cycle:
// ./in.cue:89:5
}
}
c: (_|_){
// [structural cycle]
0: (_|_){
// [structural cycle]
0: (_|_){
// [structural cycle] listAddCycle.c.0.0: structural cycle:
// ./in.cue:89:5
// [structural cycle] listAddCycle.b.0.0: structural cycle
}
1: (_|_){
// [structural cycle] listAddCycle.c.0.1: structural cycle:
// ./in.cue:89:5
// [structural cycle] listAddCycle.b.0.1: structural cycle
}
}
1: (_|_){
// [structural cycle]
}
}
c: (_|_){
// [structural cycle] listAddCycle.c: structural cycle:
// ./in.cue:89:6
}
}
listMulCycle: (_|_){
// [eval]
Expand Down
Loading

0 comments on commit 33071c0

Please sign in to comment.