diff --git a/cue/testdata/basicrewrite/011_list_arithmetic.txtar b/cue/testdata/basicrewrite/011_list_arithmetic.txtar deleted file mode 100644 index 4479f437982..00000000000 --- a/cue/testdata/basicrewrite/011_list_arithmetic.txtar +++ /dev/null @@ -1,108 +0,0 @@ -# DO NOT EDIT; generated by go run testdata/gen.go -# -#name: list arithmetic -#evalPartial --- in.cue -- -list: [1, 2, 3] -mul0: list * 0 -mul1: list * 1 -mul2: 2 * list -list1: [1] -mul1_0: list1 * 0 -mul1_1: 1 * list1 -mul1_2: list1 * 2 -add1_2: list + list1 -e: list * -1 --- out/def -- -list: [1, 2, 3] -mul0: [] -mul1: [1, 2, 3] -mul2: [1, 2, 3, 1, 2, 3] -list1: [1] -mul1_0: [] -mul1_1: [1] -mul1_2: [1, 1] -e: _|_ // negative number -1 multiplies list --- out/legacy-debug -- -<0>{list: [1,2,3], mul0: [], mul1: [1,2,3], mul2: [1,2,3,1,2,3], list1: [1], mul1_0: [], mul1_1: [1], mul1_2: [1,1], e: _|_((<1>.list * -1):negative number -1 multiplies list)} --- out/compile -- ---- in.cue -{ - list: [ - 1, - 2, - 3, - ] - mul0: (〈0;list〉 * 0) - mul1: (〈0;list〉 * 1) - mul2: (2 * 〈0;list〉) - list1: [ - 1, - ] - mul1_0: (〈0;list1〉 * 0) - mul1_1: (1 * 〈0;list1〉) - mul1_2: (〈0;list1〉 * 2) - add1_2: (〈0;list〉 + 〈0;list1〉) - e: (〈0;list〉 * -1) -} --- out/eval/stats -- -Leaks: 7 -Freed: 31 -Reused: 28 -Allocs: 10 -Retain: 7 - -Unifications: 38 -Conjuncts: 77 -Disjuncts: 38 --- out/eval -- -Errors: -e: cannot convert negative number to uint64: - ./in.cue:10:9 - -Result: -(_|_){ - // [eval] - list: (#list){ - 0: (int){ 1 } - 1: (int){ 2 } - 2: (int){ 3 } - } - mul0: (#list){ - } - mul1: (#list){ - 0: (int){ 1 } - 1: (int){ 2 } - 2: (int){ 3 } - } - mul2: (#list){ - 0: (int){ 1 } - 1: (int){ 2 } - 2: (int){ 3 } - 3: (int){ 1 } - 4: (int){ 2 } - 5: (int){ 3 } - } - list1: (#list){ - 0: (int){ 1 } - } - mul1_0: (#list){ - } - mul1_1: (#list){ - 0: (int){ 1 } - } - mul1_2: (#list){ - 0: (int){ 1 } - 1: (int){ 1 } - } - add1_2: (#list){ - 0: (int){ 1 } - 1: (int){ 2 } - 2: (int){ 3 } - 3: (int){ 1 } - } - e: (_|_){ - // [eval] e: cannot convert negative number to uint64: - // ./in.cue:10:9 - } -} diff --git a/cue/testdata/comprehensions/issue843.txtar b/cue/testdata/comprehensions/issue843.txtar index e30823c4bb7..949a0bca685 100644 --- a/cue/testdata/comprehensions/issue843.txtar +++ b/cue/testdata/comprehensions/issue843.txtar @@ -1,12 +1,14 @@ -- in.cue -- package main +import "list" + #d1: { as: [...string] #c: [ #f1 & { - "as": ["go"] + as + "as": list.Concat([["go"], as]) }, ] } @@ -41,15 +43,15 @@ package main from: #c1 } -- out/eval/stats -- -Leaks: 9 -Freed: 55 -Reused: 41 -Allocs: 23 -Retain: 14 +Leaks: 0 +Freed: 85 +Reused: 70 +Allocs: 15 +Retain: 7 -Unifications: 52 -Conjuncts: 120 -Disjuncts: 66 +Unifications: 65 +Conjuncts: 159 +Disjuncts: 92 -- out/evalalpha -- (struct){ #d1: (#struct){ @@ -239,9 +241,12 @@ Reordering ] #c: [ (〈2;#f1〉 & { - as: ([ - "go", - ] + 〈2;as〉) + as: 〈import;list〉.Concat([ + [ + "go", + ], + 〈3;as〉, + ]) }), ] } diff --git a/cue/testdata/cycle/chain.txtar b/cue/testdata/cycle/chain.txtar index abf4e7b1338..ff4db31a5e9 100644 --- a/cue/testdata/cycle/chain.txtar +++ b/cue/testdata/cycle/chain.txtar @@ -30,7 +30,7 @@ chain: t2: p1: { X: 1 // Reference X through x.x0 before X is inserted. - for v in [0, X] + [] { + for v in list.Concat([[0, X], []]) { x: "x\(v)": {} } @@ -41,7 +41,7 @@ chain: t2: p1: { chain: t2: p2: { // Reference X through x.x0 before X is inserted. - for v in [0, X] + [] { + for v in list.Concat([[0, X], []]) { x: "x\(v)": {} } @@ -208,14 +208,14 @@ issue2052: full: { d: #Depth & {#in: tree} } -- out/evalalpha/stats -- -Leaks: 19997 +Leaks: 19999 Freed: 1462 Reused: 1461 -Allocs: 19998 +Allocs: 20000 Retain: 0 -Unifications: 7504 -Conjuncts: 107530 +Unifications: 7506 +Conjuncts: 107540 Disjuncts: 13655 -- out/evalalpha -- Errors: @@ -720,22 +720,22 @@ diff old new --- old +++ new @@ -1,9 +1,9 @@ --Leaks: 70 --Freed: 1815 --Reused: 1801 --Allocs: 84 --Retain: 185 -+Leaks: 19997 +-Leaks: 56 +-Freed: 1830 +-Reused: 1816 +-Allocs: 70 +-Retain: 169 ++Leaks: 19999 +Freed: 1462 +Reused: 1461 -+Allocs: 19998 ++Allocs: 20000 +Retain: 0 --Unifications: 800 --Conjuncts: 3175 --Disjuncts: 1974 -+Unifications: 7504 -+Conjuncts: 107530 +-Unifications: 801 +-Conjuncts: 3177 +-Disjuncts: 1979 ++Unifications: 7506 ++Conjuncts: 107540 +Disjuncts: 13655 -- diff/-out/evalalpha<==>+out/eval -- diff old new @@ -755,7 +755,28 @@ diff old new chain: (struct){ t1: (struct){ #maxiter: (int){ 2 } -@@ -47,148 +55,148 @@ +@@ -27,15 +35,11 @@ + } + } + } +- p2: (_|_){ +- // [incomplete] 1: invalid interpolation: cycle error referencing X: +- // ./in.cue:44:6 +- // ./in.cue:43:28 +- x: (_|_){ +- // [incomplete] 1: invalid interpolation: cycle error referencing X: +- // ./in.cue:44:6 +- // ./in.cue:43:28 +- x0: (struct){ ++ p2: (struct){ ++ x: (struct){ ++ x0: (struct){ ++ } ++ x1: (struct){ + } + } + X: (int){ 1 } +@@ -51,148 +55,148 @@ } } } @@ -1041,7 +1062,7 @@ diff old new #maxiter: (int){ |(*(int){ 4 }, (int){ &(>=0, int) }) } #funcFactory: (#struct){ #next: (_){ _ } -@@ -335,49 +343,7 @@ +@@ -339,49 +343,7 @@ } cow: (string){ "moo" } } @@ -1092,7 +1113,7 @@ diff old new #in: (#struct){ a: (#struct){ foo: (string){ "bar" } -@@ -389,6 +355,142 @@ +@@ -393,6 +355,142 @@ } cow: (string){ "moo" } } @@ -1236,15 +1257,15 @@ diff old new } } -- out/eval/stats -- -Leaks: 70 -Freed: 1815 -Reused: 1801 -Allocs: 84 -Retain: 185 +Leaks: 56 +Freed: 1830 +Reused: 1816 +Allocs: 70 +Retain: 169 -Unifications: 800 -Conjuncts: 3175 -Disjuncts: 1974 +Unifications: 801 +Conjuncts: 3177 +Disjuncts: 1979 -- diff/todo/p1 -- issue2052.*.#Depth: incorrect error message: "adding field #basic not allowed as field set was already referenced" @@ -1280,12 +1301,16 @@ issue2052.full.d: "cannot add field #maxiter: was already used" } } } - p2: (struct){ - x: (struct){ + p2: (_|_){ + // [incomplete] 1: invalid interpolation: cycle error referencing X: + // ./in.cue:44:6 + // ./in.cue:43:28 + x: (_|_){ + // [incomplete] 1: invalid interpolation: cycle error referencing X: + // ./in.cue:44:6 + // ./in.cue:43:28 x0: (struct){ } - x1: (struct){ - } } X: (int){ 1 } } @@ -1676,10 +1701,13 @@ issue2052.full.d: "cannot add field #maxiter: was already used" t2: { p1: { X: 1 - for _, v in ([ - 0, - 〈1;X〉, - ] + []) { + for _, v in 〈import;list〉.Concat([ + [ + 0, + 〈2;X〉, + ], + [], + ]) { x: { "x\(〈2;v〉)": {} } @@ -1692,10 +1720,13 @@ issue2052.full.d: "cannot add field #maxiter: was already used" chain: { t2: { p2: { - for _, v in ([ - 0, - 〈1;X〉, - ] + []) { + for _, v in 〈import;list〉.Concat([ + [ + 0, + 〈2;X〉, + ], + [], + ]) { x: { "x\(〈2;v〉)": {} } diff --git a/cue/testdata/cycle/evaluate.txtar b/cue/testdata/cycle/evaluate.txtar index 470cbc84342..9162f98dda1 100644 --- a/cue/testdata/cycle/evaluate.txtar +++ b/cue/testdata/cycle/evaluate.txtar @@ -7,6 +7,8 @@ // The builtins are typically used to trigger the uncommon path. The choice of // builtin is irrelevant, as long as they don't finalize args before processing. +import "list" + // This is a resolvable reference cycle, were b is equated to c. letCycleOK: t1: { b: c @@ -87,13 +89,13 @@ embedCycle: { listAddCycle: { a: b - b: [c] + [c] + b: list.Concat([[c], [c]]) c: a } listMulCycle: { a: b - b: 3 + [{a: b: c}] + b: list.Repeat([{a: b: c}], 3) c: a } @@ -114,47 +116,45 @@ printCycle: { } } -- out/eval/stats -- -Leaks: 59 -Freed: 92 -Reused: 89 -Allocs: 62 -Retain: 127 +Leaks: 48 +Freed: 127 +Reused: 120 +Allocs: 55 +Retain: 136 -Unifications: 139 -Conjuncts: 274 -Disjuncts: 160 +Unifications: 163 +Conjuncts: 299 +Disjuncts: 192 -- out/evalalpha -- Errors: letCycleOK.t2.a.X: structural cycle: - ./in.cue:22:6 + ./in.cue:24:6 letCycleFail.t1.a.X: structural cycle: - ./in.cue:32:6 + ./in.cue:34:6 listCycleOK.0: structural cycle: - ./in.cue:48:9 + ./in.cue:50:9 disjunctionCycle.b: cannot use 1 (type int) as list in argument 1 to and: - ./in.cue:54:9 + ./in.cue:56:9 forCycle.0.b: structural cycle: - ./in.cue:60:9 + ./in.cue:62:9 letCycleWithAnd.0: structural cycle: - ./in.cue:65:9 + ./in.cue:67:9 closeCycle.d: structural cycle: - ./in.cue:71:11 + ./in.cue:73:11 structCycle.0.d: structural cycle: - ./in.cue:77:9 + ./in.cue:79:9 embedCycle: structural cycle: - ./in.cue:83:11 -listAddCycle.0: structural cycle: - ./in.cue:89:5 -listAddCycle.0: structural cycle: - ./in.cue:89:11 + ./in.cue:85:11 +listAddCycle.0.0: structural cycle: + ./in.cue:91:17 listMulCycle.0.a.b: structural cycle: - ./in.cue:95:9 + ./in.cue:97:17 closeFail.x.b: field not allowed: - ./in.cue:103:6 - ./in.cue:102:6 - ./in.cue:105:5 + ./in.cue:105:6 + ./in.cue:104:6 + ./in.cue:107:5 printCycle.a: cannot use {X:~(printCycle.a)} (type struct) as type bool: - ./in.cue:111:3 + ./in.cue:113:3 Result: (_|_){ @@ -176,7 +176,7 @@ Result: } c: (_|_){ // [structural cycle] letCycleOK.t2.a.X: structural cycle: - // ./in.cue:22:6 + // ./in.cue:24:6 } } } @@ -193,7 +193,7 @@ Result: } c: (_|_){ // [structural cycle] letCycleFail.t1.a.X: structural cycle: - // ./in.cue:32:6 + // ./in.cue:34:6 } } } @@ -202,7 +202,7 @@ Result: let X#4 = (struct){ let X#4 = (_|_){ // [structural cycle] letCycleFail.t2.a.X.X: structural cycle: - // ./in.cue:41:6 + // ./in.cue:43:6 } x: (struct){ y: (string){ "" } @@ -218,30 +218,30 @@ Result: // [structural cycle] a: (_|_){ // [structural cycle] listCycleOK.0: structural cycle: - // ./in.cue:48:9 + // ./in.cue:50:9 } b: (_|_){ // [structural cycle] listCycleOK.0: structural cycle: - // ./in.cue:48:9 + // ./in.cue:50:9 } c: (_|_){ // [structural cycle] listCycleOK.0: structural cycle: - // ./in.cue:48:9 + // ./in.cue:50:9 } } disjunctionCycle: (_|_){ // [eval] a: (_|_){ // [eval] disjunctionCycle.b: cannot use 1 (type int) as list in argument 1 to and: - // ./in.cue:54:9 + // ./in.cue:56:9 } b: (_|_){ // [eval] disjunctionCycle.b: cannot use 1 (type int) as list in argument 1 to and: - // ./in.cue:54:9 + // ./in.cue:56:9 } c: (_|_){ // [eval] disjunctionCycle.b: cannot use 1 (type int) as list in argument 1 to and: - // ./in.cue:54:9 + // ./in.cue:56:9 } } forCycle: (_|_){ @@ -250,12 +250,12 @@ Result: // [structural cycle] a: (_|_){ // [structural cycle] forCycle.0.b: structural cycle: - // ./in.cue:60:9 + // ./in.cue:62:9 } } #B: (_|_){ // [structural cycle] forCycle.0.b: structural cycle: - // ./in.cue:60:9 + // ./in.cue:62:9 } } letCycleWithAnd: (_|_){ @@ -264,18 +264,18 @@ Result: // [structural cycle] d: (_|_){ // [structural cycle] letCycleWithAnd.0: structural cycle: - // ./in.cue:65:9 + // ./in.cue:67:9 } } b: (_|_){ // [structural cycle] letCycleWithAnd.0: structural cycle: - // ./in.cue:65:9 + // ./in.cue:67:9 } c: (_|_){ // [structural cycle] d: (_|_){ // [structural cycle] letCycleWithAnd.0: structural cycle: - // ./in.cue:65:9 + // ./in.cue:67:9 } } } @@ -283,81 +283,75 @@ Result: // [structural cycle] a: (_|_){ // [structural cycle] closeCycle.d: structural cycle: - // ./in.cue:71:11 + // ./in.cue:73:11 } b: (_|_){ // [structural cycle] closeCycle.d: structural cycle: - // ./in.cue:71:11 + // ./in.cue:73:11 } c: (_|_){ // [structural cycle] closeCycle.d: structural cycle: - // ./in.cue:71:11 + // ./in.cue:73:11 } } structCycle: (_|_){ // [structural cycle] a: (_|_){ // [structural cycle] structCycle.0.d: structural cycle: - // ./in.cue:77:9 + // ./in.cue:79:9 } b: (_|_){ // [structural cycle] structCycle.0.d: structural cycle: - // ./in.cue:77:9 + // ./in.cue:79:9 } c: (_|_){ // [structural cycle] structCycle.0.d: structural cycle: - // ./in.cue:77:9 + // ./in.cue:79:9 } } embedCycle: (_|_){ // [structural cycle] a: (_|_){ // [structural cycle] embedCycle: structural cycle: - // ./in.cue:83:11 + // ./in.cue:85:11 } b: (_|_){ // [structural cycle] embedCycle: structural cycle: - // ./in.cue:83:11 + // ./in.cue:85:11 } c: (_|_){ // [structural cycle] embedCycle: structural cycle: - // ./in.cue:83:11 + // ./in.cue:85:11 } } listAddCycle: (_|_){ // [structural cycle] a: (_|_){ - // [structural cycle] listAddCycle.0: structural cycle: - // ./in.cue:89:5 - // listAddCycle.0: structural cycle: - // ./in.cue:89:11 + // [structural cycle] listAddCycle.0.0: structural cycle: + // ./in.cue:91:17 } b: (_|_){ - // [structural cycle] listAddCycle.0: structural cycle: - // ./in.cue:89:5 - // listAddCycle.0: structural cycle: - // ./in.cue:89:11 + // [structural cycle] listAddCycle.0.0: structural cycle: + // ./in.cue:91:17 } c: (_|_){ - // [structural cycle] listAddCycle.0: structural cycle: - // ./in.cue:89:5 - // listAddCycle.0: structural cycle: - // ./in.cue:89:11 + // [structural cycle] listAddCycle.0.0: structural cycle: + // ./in.cue:91:17 } } listMulCycle: (_|_){ // [structural cycle] a: (_|_){ // [structural cycle] listMulCycle.0.a.b: structural cycle: - // ./in.cue:95:9 + // ./in.cue:97:17 } b: (_|_){ // [structural cycle] listMulCycle.0.a.b: structural cycle: - // ./in.cue:95:9 + // ./in.cue:97:17 } c: (_|_){ // [structural cycle] listMulCycle.0.a.b: structural cycle: - // ./in.cue:95:9 + // ./in.cue:97:17 } } closeFail: (_|_){ @@ -369,9 +363,9 @@ Result: // [eval] b: (_|_){ // [eval] closeFail.x.b: field not allowed: - // ./in.cue:103:6 - // ./in.cue:102:6 - // ./in.cue:105:5 + // ./in.cue:105:6 + // ./in.cue:104:6 + // ./in.cue:107:5 } a: (string){ string } } @@ -380,7 +374,7 @@ Result: // [eval] a: (_|_){ // [eval] printCycle.a: cannot use {X:~(printCycle.a)} (type struct) as type bool: - // ./in.cue:111:3 + // ./in.cue:113:3 X: ~(printCycle.a) } } @@ -389,74 +383,58 @@ Result: diff old new --- old +++ new -@@ -1,61 +1,57 @@ +@@ -1,47 +1,55 @@ Errors: -closeCycle.a: structural cycle -closeCycle.b.d: structural cycle -closeFail.x.b: field not allowed: -- ./in.cue:102:6 -- ./in.cue:103:12 - ./in.cue:104:6 -- ./in.cue:105:5 +- ./in.cue:105:12 +- ./in.cue:106:6 +- ./in.cue:107: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: -- ./in.cue:54:9 +- ./in.cue:56:9 +letCycleOK.t2.a.X: structural cycle: -+ ./in.cue:22:6 ++ ./in.cue:24:6 +letCycleFail.t1.a.X: structural cycle: -+ ./in.cue:32:6 ++ ./in.cue:34:6 +listCycleOK.0: structural cycle: -+ ./in.cue:48:9 ++ ./in.cue:50:9 disjunctionCycle.b: cannot use 1 (type int) as list in argument 1 to and: - ./in.cue:54:9 + ./in.cue:56:9 -disjunctionCycle.c: cannot use 1 (type int) as list in argument 1 to and: -- ./in.cue:54:9 +- ./in.cue:56:9 -b: structural cycle: -- ./in.cue:60:6 +- ./in.cue:62:6 -closeCycle.c: structural cycle: -- ./in.cue:71:15 +- ./in.cue:73:15 -structCycle.c: structural cycle: -- ./in.cue:77:14 +- ./in.cue:79:14 +forCycle.0.b: structural cycle: -+ ./in.cue:60:9 ++ ./in.cue:62:9 +letCycleWithAnd.0: structural cycle: -+ ./in.cue:65:9 ++ ./in.cue:67:9 +closeCycle.d: structural cycle: -+ ./in.cue:71:11 ++ ./in.cue:73:11 +structCycle.0.d: structural cycle: -+ ./in.cue:77:9 ++ ./in.cue:79:9 embedCycle: structural cycle: - ./in.cue:83:11 --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 --listMulCycle.b: invalid operands 3 and [{a:{b:c}}] to '+' (type int and list): -- ./in.cue:95:5 -- ./in.cue:95:9 --listMulCycle.c: invalid operands 3 and [{a:{b:c}}] to '+' (type int and list): -- ./in.cue:95:5 -- ./in.cue:95:9 + ./in.cue:85:11 -printCycle.a.X.X: structural cycle: -- ./in.cue:111:6 -+listAddCycle.0: structural cycle: -+ ./in.cue:89:5 -+listAddCycle.0: structural cycle: -+ ./in.cue:89:11 +- ./in.cue:113:6 ++listAddCycle.0.0: structural cycle: ++ ./in.cue:91:17 +listMulCycle.0.a.b: structural cycle: -+ ./in.cue:95:9 ++ ./in.cue:97:17 +closeFail.x.b: field not allowed: -+ ./in.cue:103:6 -+ ./in.cue:102:6 -+ ./in.cue:105:5 ++ ./in.cue:105:6 ++ ./in.cue:104:6 ++ ./in.cue:107:5 +printCycle.a: cannot use {X:~(printCycle.a)} (type struct) as type bool: -+ ./in.cue:111:3 ++ ./in.cue:113:3 Result: (_|_){ @@ -482,22 +460,22 @@ diff old new - c: (int){ 1 } + c: (_|_){ + // [structural cycle] letCycleOK.t2.a.X: structural cycle: -+ // ./in.cue:22:6 ++ // ./in.cue:24:6 + } } } } -@@ -70,7 +66,8 @@ +@@ -56,7 +64,8 @@ // [structural cycle] letCycleFail.t1.a.X: structural cycle } c: (_|_){ - // [structural cycle] letCycleFail.t1.a.c: structural cycle + // [structural cycle] letCycleFail.t1.a.X: structural cycle: -+ // ./in.cue:32:6 ++ // ./in.cue:34:6 } } } -@@ -91,23 +88,33 @@ +@@ -77,23 +86,33 @@ } } } @@ -509,54 +487,54 @@ diff old new + // [structural cycle] + a: (_|_){ + // [structural cycle] listCycleOK.0: structural cycle: -+ // ./in.cue:48:9 ++ // ./in.cue:50:9 + } + b: (_|_){ + // [structural cycle] listCycleOK.0: structural cycle: -+ // ./in.cue:48:9 ++ // ./in.cue:50:9 + } + c: (_|_){ + // [structural cycle] listCycleOK.0: structural cycle: -+ // ./in.cue:48:9 ++ // ./in.cue:50:9 + } } disjunctionCycle: (_|_){ // [eval] a: (_|_){ - // [eval] disjunctionCycle.a: cannot use 1 (type int) as list in argument 1 to and: -- // ./in.cue:54:9 +- // ./in.cue:56:9 - } - b: (_|_){ - // [eval] disjunctionCycle.b: cannot use 1 (type int) as list in argument 1 to and: -- // ./in.cue:54:9 +- // ./in.cue:56:9 - } - c: (_|_){ - // [eval] disjunctionCycle.c: cannot use 1 (type int) as list in argument 1 to and: + // [eval] disjunctionCycle.b: cannot use 1 (type int) as list in argument 1 to and: -+ // ./in.cue:54:9 ++ // ./in.cue:56:9 + } + b: (_|_){ + // [eval] disjunctionCycle.b: cannot use 1 (type int) as list in argument 1 to and: -+ // ./in.cue:54:9 ++ // ./in.cue:56:9 + } + c: (_|_){ + // [eval] disjunctionCycle.b: cannot use 1 (type int) as list in argument 1 to and: - // ./in.cue:54:9 + // ./in.cue:56:9 } } -@@ -116,24 +123,33 @@ +@@ -102,24 +121,33 @@ #A: (_|_){ // [structural cycle] a: (_|_){ - // [structural cycle] b: structural cycle: -- // ./in.cue:60:6 +- // ./in.cue:62:6 + // [structural cycle] forCycle.0.b: structural cycle: -+ // ./in.cue:60:9 ++ // ./in.cue:62:9 } } #B: (_|_){ - // [structural cycle] b: structural cycle: -- // ./in.cue:60:6 +- // ./in.cue:62:6 - } - } - letCycleWithAnd: (struct){ @@ -569,7 +547,7 @@ diff old new - c: (struct){ - d: (struct){ + // [structural cycle] forCycle.0.b: structural cycle: -+ // ./in.cue:60:9 ++ // ./in.cue:62:9 + } + } + letCycleWithAnd: (_|_){ @@ -578,22 +556,22 @@ diff old new + // [structural cycle] + d: (_|_){ + // [structural cycle] letCycleWithAnd.0: structural cycle: -+ // ./in.cue:65:9 ++ // ./in.cue:67:9 + } + } + b: (_|_){ + // [structural cycle] letCycleWithAnd.0: structural cycle: -+ // ./in.cue:65:9 ++ // ./in.cue:67:9 + } + c: (_|_){ + // [structural cycle] + d: (_|_){ + // [structural cycle] letCycleWithAnd.0: structural cycle: -+ // ./in.cue:65:9 ++ // ./in.cue:67:9 } } } -@@ -140,33 +156,31 @@ +@@ -126,33 +154,31 @@ closeCycle: (_|_){ // [structural cycle] a: (_|_){ @@ -607,17 +585,17 @@ diff old new - } - c: (_|_){ - // [structural cycle] closeCycle.c: structural cycle: -- // ./in.cue:71:15 +- // ./in.cue:73:15 + // [structural cycle] closeCycle.d: structural cycle: -+ // ./in.cue:71:11 ++ // ./in.cue:73:11 + } + b: (_|_){ + // [structural cycle] closeCycle.d: structural cycle: -+ // ./in.cue:71:11 ++ // ./in.cue:73:11 + } + c: (_|_){ + // [structural cycle] closeCycle.d: structural cycle: -+ // ./in.cue:71:11 ++ // ./in.cue:73:11 } } structCycle: (_|_){ @@ -633,103 +611,78 @@ diff old new - } - c: (_|_){ - // [structural cycle] structCycle.c: structural cycle: -- // ./in.cue:77:14 +- // ./in.cue:79:14 + // [structural cycle] structCycle.0.d: structural cycle: -+ // ./in.cue:77:9 ++ // ./in.cue:79:9 + } + b: (_|_){ + // [structural cycle] structCycle.0.d: structural cycle: -+ // ./in.cue:77:9 ++ // ./in.cue:79:9 + } + c: (_|_){ + // [structural cycle] structCycle.0.d: structural cycle: -+ // ./in.cue:77:9 ++ // ./in.cue:79:9 } } embedCycle: (_|_){ -@@ -187,43 +201,36 @@ +@@ -173,25 +199,31 @@ listAddCycle: (_|_){ // [structural cycle] a: (_|_){ -- // [structural cycle] listAddCycle.a: structural cycle +- // [structural cycle] - } - b: (_|_){ - // [structural cycle] -- 0: (_|_){ -- // [structural cycle] -- 0: (_|_){ -- // [structural cycle] listAddCycle.b.0.0: structural cycle -- } -- 1: (_|_){ -- // [structural cycle] listAddCycle.b.0.1: structural cycle -- } -- } -- 1: (_|_){ -- // [structural cycle] -- } - } - c: (_|_){ -- // [structural cycle] listAddCycle.c: structural cycle: -- // ./in.cue:89:6 -+ // [structural cycle] listAddCycle.0: structural cycle: -+ // ./in.cue:89:5 -+ // listAddCycle.0: structural cycle: -+ // ./in.cue:89:11 +- // [structural cycle] ++ // [structural cycle] listAddCycle.0.0: structural cycle: ++ // ./in.cue:91:17 + } + b: (_|_){ -+ // [structural cycle] listAddCycle.0: structural cycle: -+ // ./in.cue:89:5 -+ // listAddCycle.0: structural cycle: -+ // ./in.cue:89:11 ++ // [structural cycle] listAddCycle.0.0: structural cycle: ++ // ./in.cue:91:17 + } + c: (_|_){ -+ // [structural cycle] listAddCycle.0: structural cycle: -+ // ./in.cue:89:5 -+ // listAddCycle.0: structural cycle: -+ // ./in.cue:89:11 ++ // [structural cycle] listAddCycle.0.0: structural cycle: ++ // ./in.cue:91:17 } } listMulCycle: (_|_){ -- // [eval] -- a: (_|_){ -- // [eval] listMulCycle.a: invalid operands 3 and [{a:{b:c}}] to '+' (type int and list): -- // ./in.cue:95:5 -- // ./in.cue:95:9 + // [structural cycle] + a: (_|_){ +- // [structural cycle] - } - b: (_|_){ -- // [eval] listMulCycle.b: invalid operands 3 and [{a:{b:c}}] to '+' (type int and list): -- // ./in.cue:95:5 -- // ./in.cue:95:9 +- // [structural cycle] - } - c: (_|_){ -- // [eval] listMulCycle.c: invalid operands 3 and [{a:{b:c}}] to '+' (type int and list): -- // ./in.cue:95:5 -+ // [structural cycle] -+ a: (_|_){ +- // [structural cycle] + // [structural cycle] listMulCycle.0.a.b: structural cycle: -+ // ./in.cue:95:9 ++ // ./in.cue:97:17 + } + b: (_|_){ + // [structural cycle] listMulCycle.0.a.b: structural cycle: -+ // ./in.cue:95:9 ++ // ./in.cue:97:17 + } + c: (_|_){ + // [structural cycle] listMulCycle.0.a.b: structural cycle: - // ./in.cue:95:9 ++ // ./in.cue:97:17 } } -@@ -234,21 +241,21 @@ + closeFail: (_|_){ +@@ -201,21 +233,21 @@ } x: (_|_){ // [eval] - a: (string){ string } b: (_|_){ // [eval] closeFail.x.b: field not allowed: -+ // ./in.cue:103:6 - // ./in.cue:102:6 -- // ./in.cue:103:12 -- // ./in.cue:104:6 - // ./in.cue:105:5 ++ // ./in.cue:105:6 + // ./in.cue:104:6 +- // ./in.cue:105:12 +- // ./in.cue:106:6 + // ./in.cue:107:5 } + a: (string){ string } } @@ -738,11 +691,11 @@ diff old new - // [structural cycle] - a: (_|_){ - // [structural cycle] printCycle.a.X.X: structural cycle: -- // ./in.cue:111:6 +- // ./in.cue:113:6 + // [eval] + a: (_|_){ + // [eval] printCycle.a: cannot use {X:~(printCycle.a)} (type struct) as type bool: -+ // ./in.cue:111:3 ++ // ./in.cue:113:3 + X: ~(printCycle.a) } } @@ -756,43 +709,29 @@ Errors: closeCycle.a: structural cycle closeCycle.b.d: structural cycle closeFail.x.b: field not allowed: - ./in.cue:102:6 - ./in.cue:103:12 ./in.cue:104:6 - ./in.cue:105:5 + ./in.cue:105:12 + ./in.cue:106:6 + ./in.cue:107: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: - ./in.cue:54:9 + ./in.cue:56:9 disjunctionCycle.b: cannot use 1 (type int) as list in argument 1 to and: - ./in.cue:54:9 + ./in.cue:56:9 disjunctionCycle.c: cannot use 1 (type int) as list in argument 1 to and: - ./in.cue:54:9 + ./in.cue:56:9 b: structural cycle: - ./in.cue:60:6 + ./in.cue:62:6 closeCycle.c: structural cycle: - ./in.cue:71:15 + ./in.cue:73:15 structCycle.c: structural cycle: - ./in.cue:77:14 + ./in.cue:79:14 embedCycle: structural cycle: - ./in.cue:83:11 -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 -listMulCycle.b: invalid operands 3 and [{a:{b:c}}] to '+' (type int and list): - ./in.cue:95:5 - ./in.cue:95:9 -listMulCycle.c: invalid operands 3 and [{a:{b:c}}] to '+' (type int and list): - ./in.cue:95:5 - ./in.cue:95:9 + ./in.cue:85:11 printCycle.a.X.X: structural cycle: - ./in.cue:111:6 + ./in.cue:113:6 Result: (_|_){ @@ -833,7 +772,7 @@ Result: let X#4 = (struct){ let X#4 = (_|_){ // [structural cycle] letCycleFail.t2.a.X.X: structural cycle: - // ./in.cue:41:6 + // ./in.cue:43:6 } x: (struct){ y: (string){ "" } @@ -854,15 +793,15 @@ Result: // [eval] a: (_|_){ // [eval] disjunctionCycle.a: cannot use 1 (type int) as list in argument 1 to and: - // ./in.cue:54:9 + // ./in.cue:56:9 } b: (_|_){ // [eval] disjunctionCycle.b: cannot use 1 (type int) as list in argument 1 to and: - // ./in.cue:54:9 + // ./in.cue:56:9 } c: (_|_){ // [eval] disjunctionCycle.c: cannot use 1 (type int) as list in argument 1 to and: - // ./in.cue:54:9 + // ./in.cue:56:9 } } forCycle: (_|_){ @@ -871,12 +810,12 @@ Result: // [structural cycle] a: (_|_){ // [structural cycle] b: structural cycle: - // ./in.cue:60:6 + // ./in.cue:62:6 } } #B: (_|_){ // [structural cycle] b: structural cycle: - // ./in.cue:60:6 + // ./in.cue:62:6 } } letCycleWithAnd: (struct){ @@ -904,7 +843,7 @@ Result: } c: (_|_){ // [structural cycle] closeCycle.c: structural cycle: - // ./in.cue:71:15 + // ./in.cue:73:15 } } structCycle: (_|_){ @@ -920,65 +859,46 @@ Result: } c: (_|_){ // [structural cycle] structCycle.c: structural cycle: - // ./in.cue:77:14 + // ./in.cue:79:14 } } embedCycle: (_|_){ // [structural cycle] a: (_|_){ // [structural cycle] embedCycle: structural cycle: - // ./in.cue:83:11 + // ./in.cue:85:11 } b: (_|_){ // [structural cycle] embedCycle: structural cycle: - // ./in.cue:83:11 + // ./in.cue:85:11 } c: (_|_){ // [structural cycle] embedCycle: structural cycle: - // ./in.cue:83:11 + // ./in.cue:85:11 } } listAddCycle: (_|_){ // [structural cycle] a: (_|_){ - // [structural cycle] listAddCycle.a: structural cycle + // [structural cycle] } b: (_|_){ // [structural cycle] - 0: (_|_){ - // [structural cycle] - 0: (_|_){ - // [structural cycle] listAddCycle.b.0.0: structural cycle - } - 1: (_|_){ - // [structural cycle] listAddCycle.b.0.1: structural cycle - } - } - 1: (_|_){ - // [structural cycle] - } } c: (_|_){ - // [structural cycle] listAddCycle.c: structural cycle: - // ./in.cue:89:6 + // [structural cycle] } } listMulCycle: (_|_){ - // [eval] + // [structural cycle] a: (_|_){ - // [eval] listMulCycle.a: invalid operands 3 and [{a:{b:c}}] to '+' (type int and list): - // ./in.cue:95:5 - // ./in.cue:95:9 + // [structural cycle] } b: (_|_){ - // [eval] listMulCycle.b: invalid operands 3 and [{a:{b:c}}] to '+' (type int and list): - // ./in.cue:95:5 - // ./in.cue:95:9 + // [structural cycle] } c: (_|_){ - // [eval] listMulCycle.c: invalid operands 3 and [{a:{b:c}}] to '+' (type int and list): - // ./in.cue:95:5 - // ./in.cue:95:9 + // [structural cycle] } } closeFail: (_|_){ @@ -991,10 +911,10 @@ Result: a: (string){ string } b: (_|_){ // [eval] closeFail.x.b: field not allowed: - // ./in.cue:102:6 - // ./in.cue:103:12 // ./in.cue:104:6 - // ./in.cue:105:5 + // ./in.cue:105:12 + // ./in.cue:106:6 + // ./in.cue:107:5 } } } @@ -1002,7 +922,7 @@ Result: // [structural cycle] a: (_|_){ // [structural cycle] printCycle.a.X.X: structural cycle: - // ./in.cue:111:6 + // ./in.cue:113:6 } } } @@ -1103,22 +1023,25 @@ Result: } listAddCycle: { a: 〈0;b〉 - b: ([ - 〈1;c〉, - ] + [ - 〈1;c〉, + b: 〈import;list〉.Concat([ + [ + 〈2;c〉, + ], + [ + 〈2;c〉, + ], ]) c: 〈0;a〉 } listMulCycle: { a: 〈0;b〉 - b: (3 + [ + b: 〈import;list〉.Repeat([ { a: { b: 〈3;c〉 } }, - ]) + ], 3) c: 〈0;a〉 } closeFail: { diff --git a/cue/testdata/cycle/self.txtar b/cue/testdata/cycle/self.txtar index 9e7873a8024..4e46625c1c5 100644 --- a/cue/testdata/cycle/self.txtar +++ b/cue/testdata/cycle/self.txtar @@ -1,4 +1,6 @@ -- in.cue -- +import "list" + expr: error1: { a: 3 a: a + 1 @@ -9,11 +11,11 @@ expr: error2: { } list: error1: { a: ["1", "2"] - a: a + ["3"] + a: list.Concat([a, ["3"]]) } list: error2: { - a: ["3"] + a + a: list.Concat([["3"], a]) a: ["1", "2"] } @@ -263,28 +265,27 @@ issue1729: t2: { } -- out/eval/stats -- -Leaks: 14 -Freed: 414 -Reused: 405 -Allocs: 23 -Retain: 27 +Leaks: 0 +Freed: 432 +Reused: 423 +Allocs: 9 +Retain: 15 -Unifications: 236 -Conjuncts: 686 -Disjuncts: 439 +Unifications: 240 +Conjuncts: 663 +Disjuncts: 447 -- out/evalalpha -- Errors: expr.error1.a: conflicting values 4 and 3: - ./in.cue:2:5 - ./in.cue:3:5 + ./in.cue:4:5 + ./in.cue:5:5 expr.error2.a: conflicting values 4 and 3: - ./in.cue:6:5 - ./in.cue:7:5 -list.error1.a: adding field 2 not allowed as field set was already referenced -list.error2.a: adding field 2 not allowed as field set was already referenced -list.error2.a.0: conflicting values "3" and "1": - ./in.cue:15:6 - ./in.cue:16:6 + ./in.cue:8:5 + ./in.cue:9:5 +list.error1.0: structural cycle: + ./in.cue:13:17 +list.error2.1: structural cycle: + ./in.cue:17:17 Result: (_|_){ @@ -295,49 +296,33 @@ Result: // [eval] a: (_|_){ // [eval] expr.error1.a: conflicting values 4 and 3: - // ./in.cue:2:5 - // ./in.cue:3:5 + // ./in.cue:4:5 + // ./in.cue:5:5 } } error2: (_|_){ // [eval] a: (_|_){ // [eval] expr.error2.a: conflicting values 4 and 3: - // ./in.cue:6:5 - // ./in.cue:7:5 + // ./in.cue:8:5 + // ./in.cue:9:5 } } } list: (_|_){ - // [eval] + // [structural cycle] error1: (_|_){ - // [eval] + // [structural cycle] a: (_|_){ - // [eval] list.error1.a: adding field 2 not allowed as field set was already referenced - 0: (string){ "1" } - 1: (string){ "2" } + // [structural cycle] list.error1.0: structural cycle: + // ./in.cue:13:17 } } error2: (_|_){ - // [eval] + // [structural cycle] a: (_|_){ - // [eval] list.error2.a: adding field 2 not allowed as field set was already referenced - // list.error2.a.0: conflicting values "3" and "1": - // ./in.cue:15:6 - // ./in.cue:16:6 - 0: (_|_){ - // [eval] list.error2.a.0: conflicting values "3" and "1": - // ./in.cue:15:6 - // ./in.cue:16:6 - } - 1: (_|_){ - // [eval] list.error2.a.1: conflicting values "1" and "2": - // ./in.cue:16:6 - // ./in.cue:16:11 - // list.error2.a.1: conflicting values "3" and "2": - // ./in.cue:15:6 - // ./in.cue:16:11 - } + // [structural cycle] list.error2.1: structural cycle: + // ./in.cue:17:17 } } } @@ -649,71 +634,41 @@ Result: diff old new --- old +++ new -@@ -5,23 +5,11 @@ +@@ -5,6 +5,10 @@ expr.error2.a: conflicting values 4 and 3: - ./in.cue:6:5 - ./in.cue:7:5 --list.error1.a: element at index 2 not allowed by earlier comprehension or reference cycle --list.error2.a: element at index 2 not allowed by earlier comprehension or reference cycle -+list.error1.a: adding field 2 not allowed as field set was already referenced -+list.error2.a: adding field 2 not allowed as field set was already referenced - list.error2.a.0: conflicting values "3" and "1": - ./in.cue:15:6 - ./in.cue:16:6 --list.error2.a.1: conflicting values "1" and "2": -- ./in.cue:16:6 -- ./in.cue:16:11 --list.error2.a.1: conflicting values "3" and "2": -- ./in.cue:15:6 -- ./in.cue:16:11 --list.error2.a.2: conflicting values "1" and "2": -- ./in.cue:16:6 -- ./in.cue:16:11 --list.error2.a.2: conflicting values "3" and "2": -- ./in.cue:15:6 -- ./in.cue:16:11 + ./in.cue:8:5 + ./in.cue:9:5 ++list.error1.0: structural cycle: ++ ./in.cue:13:17 ++list.error2.1: structural cycle: ++ ./in.cue:17:17 Result: (_|_){ -@@ -50,16 +38,18 @@ +@@ -33,17 +37,15 @@ error1: (_|_){ - // [eval] + // [structural cycle] a: (_|_){ -- // [eval] list.error1.a: element at index 2 not allowed by earlier comprehension or reference cycle -+ // [eval] list.error1.a: adding field 2 not allowed as field set was already referenced - 0: (string){ "1" } - 1: (string){ "2" } -- 2: (string){ "3" } +- // [structural cycle] +- 0: (string){ "1" } +- 1: (string){ "2" } - } - } - error2: (_|_){ -- // [eval] +- // [structural cycle] - a: (_|_){ -- // [eval] list.error2.a: element at index 2 not allowed by earlier comprehension or reference cycle +- // [structural cycle] +- 0: (string){ "1" } +- 1: (string){ "2" } ++ // [structural cycle] list.error1.0: structural cycle: ++ // ./in.cue:13:17 + } + } + error2: (_|_){ -+ // [eval] ++ // [structural cycle] + a: (_|_){ -+ // [eval] list.error2.a: adding field 2 not allowed as field set was already referenced -+ // list.error2.a.0: conflicting values "3" and "1": -+ // ./in.cue:15:6 -+ // ./in.cue:16:6 - 0: (_|_){ - // [eval] list.error2.a.0: conflicting values "3" and "1": - // ./in.cue:15:6 -@@ -73,14 +63,6 @@ - // ./in.cue:15:6 - // ./in.cue:16:11 - } -- 2: (_|_){ -- // [eval] list.error2.a.2: conflicting values "1" and "2": -- // ./in.cue:16:6 -- // ./in.cue:16:11 -- // list.error2.a.2: conflicting values "3" and "2": -- // ./in.cue:15:6 -- // ./in.cue:16:11 -- } ++ // [structural cycle] list.error2.1: structural cycle: ++ // ./in.cue:17:17 } } } @@ -722,28 +677,11 @@ list.error*: different error messages. -- out/eval -- Errors: expr.error1.a: conflicting values 4 and 3: - ./in.cue:2:5 - ./in.cue:3:5 + ./in.cue:4:5 + ./in.cue:5:5 expr.error2.a: conflicting values 4 and 3: - ./in.cue:6:5 - ./in.cue:7:5 -list.error1.a: element at index 2 not allowed by earlier comprehension or reference cycle -list.error2.a: element at index 2 not allowed by earlier comprehension or reference cycle -list.error2.a.0: conflicting values "3" and "1": - ./in.cue:15:6 - ./in.cue:16:6 -list.error2.a.1: conflicting values "1" and "2": - ./in.cue:16:6 - ./in.cue:16:11 -list.error2.a.1: conflicting values "3" and "2": - ./in.cue:15:6 - ./in.cue:16:11 -list.error2.a.2: conflicting values "1" and "2": - ./in.cue:16:6 - ./in.cue:16:11 -list.error2.a.2: conflicting values "3" and "2": - ./in.cue:15:6 - ./in.cue:16:11 + ./in.cue:8:5 + ./in.cue:9:5 Result: (_|_){ @@ -754,55 +692,35 @@ Result: // [eval] a: (_|_){ // [eval] expr.error1.a: conflicting values 4 and 3: - // ./in.cue:2:5 - // ./in.cue:3:5 + // ./in.cue:4:5 + // ./in.cue:5:5 } } error2: (_|_){ // [eval] a: (_|_){ // [eval] expr.error2.a: conflicting values 4 and 3: - // ./in.cue:6:5 - // ./in.cue:7:5 + // ./in.cue:8:5 + // ./in.cue:9:5 } } } list: (_|_){ - // [eval] + // [structural cycle] error1: (_|_){ - // [eval] + // [structural cycle] a: (_|_){ - // [eval] list.error1.a: element at index 2 not allowed by earlier comprehension or reference cycle + // [structural cycle] 0: (string){ "1" } 1: (string){ "2" } - 2: (string){ "3" } } } error2: (_|_){ - // [eval] + // [structural cycle] a: (_|_){ - // [eval] list.error2.a: element at index 2 not allowed by earlier comprehension or reference cycle - 0: (_|_){ - // [eval] list.error2.a.0: conflicting values "3" and "1": - // ./in.cue:15:6 - // ./in.cue:16:6 - } - 1: (_|_){ - // [eval] list.error2.a.1: conflicting values "1" and "2": - // ./in.cue:16:6 - // ./in.cue:16:11 - // list.error2.a.1: conflicting values "3" and "2": - // ./in.cue:15:6 - // ./in.cue:16:11 - } - 2: (_|_){ - // [eval] list.error2.a.2: conflicting values "1" and "2": - // ./in.cue:16:6 - // ./in.cue:16:11 - // list.error2.a.2: conflicting values "3" and "2": - // ./in.cue:15:6 - // ./in.cue:16:11 - } + // [structural cycle] + 0: (string){ "1" } + 1: (string){ "2" } } } } @@ -1131,16 +1049,22 @@ Result: "1", "2", ] - a: (〈0;a〉 + [ - "3", + a: 〈import;list〉.Concat([ + 〈1;a〉, + [ + "3", + ], ]) } } list: { error2: { - a: ([ - "3", - ] + 〈0;a〉) + a: 〈import;list〉.Concat([ + [ + "3", + ], + 〈1;a〉, + ]) a: [ "1", "2", diff --git a/cue/testdata/disjunctions/019_ips.txtar b/cue/testdata/disjunctions/019_ips.txtar index 5655756464c..569c8330570 100644 --- a/cue/testdata/disjunctions/019_ips.txtar +++ b/cue/testdata/disjunctions/019_ips.txtar @@ -3,7 +3,9 @@ #name: ips #evalFull -- in.cue -- -IP: 4 * [ uint8] +import "list" + +IP: list.Repeat([uint8], 4) Private: *[ 192, 168, uint8, uint8] | @@ -23,9 +25,9 @@ MyIP: [10, 10, 10, 10] -- out/compile -- --- in.cue { - IP: (4 * [ + IP: 〈import;list〉.Repeat([ &(int, >=0, <=255), - ]) + ], 4) Private: (*[ 192, 168, @@ -55,15 +57,15 @@ MyIP: [10, 10, 10, 10] ]) } -- out/eval/stats -- -Leaks: 3 -Freed: 54 -Reused: 48 -Allocs: 9 -Retain: 6 +Leaks: 0 +Freed: 61 +Reused: 55 +Allocs: 6 +Retain: 1 -Unifications: 48 -Conjuncts: 111 -Disjuncts: 60 +Unifications: 52 +Conjuncts: 115 +Disjuncts: 62 -- out/eval -- (struct){ IP: (#list){ diff --git a/cue/testdata/eval/issue500.txtar b/cue/testdata/eval/issue500.txtar index 31f9279da72..120273c22c6 100644 --- a/cue/testdata/eval/issue500.txtar +++ b/cue/testdata/eval/issue500.txtar @@ -2,6 +2,7 @@ package x import "strings" +import "list" a: strings.Join(strings.Split("test", "")[1:], "") @@ -10,25 +11,25 @@ b: strings.Join(["t", "e", "s", "t"][1:], "") c: ["t", "e", "s", "t"][1:] d: strings.Join(c, "") -e: strings.Join(["a"]+["b"], "") +e: strings.Join(list.Concat([["a"], ["b"]]), "") -f: ["a"] + ["b"] +f: list.Concat([["a"], ["b"]]) g: strings.Join(f, "") -h: strings.Join(3*["a"], "") +h: strings.Join(list.Repeat(["a"], 3), "") -i: 3 * ["b"] +i: list.Repeat(["b"], 3) j: strings.Join(i, "") -- out/eval/stats -- -Leaks: 16 -Freed: 34 -Reused: 31 -Allocs: 19 -Retain: 22 +Leaks: 2 +Freed: 55 +Reused: 50 +Allocs: 7 +Retain: 6 -Unifications: 50 -Conjuncts: 66 -Disjuncts: 46 +Unifications: 57 +Conjuncts: 74 +Disjuncts: 61 -- out/eval -- (struct){ a: (string){ "est" } @@ -70,22 +71,28 @@ Disjuncts: 46 "t", ][1:] d: 〈import;strings〉.Join(〈0;c〉, "") - e: 〈import;strings〉.Join(([ - "a", - ] + [ - "b", + e: 〈import;strings〉.Join(〈import;list〉.Concat([ + [ + "a", + ], + [ + "b", + ], ]), "") - f: ([ - "a", - ] + [ - "b", + f: 〈import;list〉.Concat([ + [ + "a", + ], + [ + "b", + ], ]) g: 〈import;strings〉.Join(〈0;f〉, "") - h: 〈import;strings〉.Join((3 * [ + h: 〈import;strings〉.Join(〈import;list〉.Repeat([ "a", - ]), "") - i: (3 * [ + ], 3), "") + i: 〈import;list〉.Repeat([ "b", - ]) + ], 3) j: 〈import;strings〉.Join(〈0;i〉, "") } diff --git a/cue/testdata/export/009.txtar b/cue/testdata/export/009.txtar index e809044b31c..8d8493cbcef 100644 --- a/cue/testdata/export/009.txtar +++ b/cue/testdata/export/009.txtar @@ -1,8 +1,10 @@ # DO NOT EDIT; generated by go run testdata/gen.go # -- in.cue -- +import "list" + { - a: 5 * [int] + a: list.Repeat([int], 5) a: [1, 2, ...] e: [...int] e: [1, 2, ...] @@ -19,9 +21,9 @@ f: [1, 2, ...] --- in.cue { { - a: (5 * [ + a: 〈import;list〉.Repeat([ int, - ]) + ], 5) a: [ 1, 2, @@ -43,15 +45,15 @@ f: [1, 2, ...] } } -- out/eval/stats -- -Leaks: 3 -Freed: 13 -Reused: 10 -Allocs: 6 -Retain: 7 +Leaks: 0 +Freed: 21 +Reused: 17 +Allocs: 4 +Retain: 1 -Unifications: 16 -Conjuncts: 37 -Disjuncts: 20 +Unifications: 21 +Conjuncts: 42 +Disjuncts: 22 -- out/eval -- (struct){ a: (#list){ diff --git a/cue/testdata/export/010.txtar b/cue/testdata/export/010.txtar index a604c42e2ba..91138ab5fa2 100644 --- a/cue/testdata/export/010.txtar +++ b/cue/testdata/export/010.txtar @@ -2,8 +2,10 @@ # raw: true -- in.cue -- +import "list" + { - a: 5 * [int] + a: list.Repeat([int], 5) a: [1, 2, ...] e: [...int] e: [1, 2, ...] @@ -20,9 +22,9 @@ f: [1, 2, ...] --- in.cue { { - a: (5 * [ + a: 〈import;list〉.Repeat([ int, - ]) + ], 5) a: [ 1, 2, @@ -44,15 +46,15 @@ f: [1, 2, ...] } } -- out/eval/stats -- -Leaks: 3 -Freed: 13 -Reused: 10 -Allocs: 6 -Retain: 7 +Leaks: 0 +Freed: 21 +Reused: 17 +Allocs: 4 +Retain: 1 -Unifications: 16 -Conjuncts: 37 -Disjuncts: 20 +Unifications: 21 +Conjuncts: 42 +Disjuncts: 22 -- out/eval -- (struct){ a: (#list){ diff --git a/cue/testdata/lists/019_list_types.txtar b/cue/testdata/lists/019_list_types.txtar index d19e07235ce..91dd2b13924 100644 --- a/cue/testdata/lists/019_list_types.txtar +++ b/cue/testdata/lists/019_list_types.txtar @@ -3,7 +3,9 @@ #name: list types #evalPartial -- in.cue -- -l0: 3 * [int] +import "list" + +l0: list.Repeat([int], 3) l0: [1, 2, 3] l2: [...{a: int}] l2: [{a: 1}, {a: 2, b: 3}] @@ -12,10 +14,10 @@ l2: [{a: 1}, {a: 2, b: 3}] // l3: <=10*[int] // l3: [1, 2, 3, ...] -s1: (6 * [int])[2:3] +s1: (list.Repeat([int], 6))[2:3] s2: [0, 2, 3][1:2] -i1: (6 * [int])[2] +i1: (list.Repeat([int], 6))[2] i2: [0, 2, 3][2] t0: [...{a: 8}] @@ -23,7 +25,7 @@ t0: [{}] t1: [...] t1: [...int] -e0: 2 * [{}] +e0: list.Repeat([{}], 2) e0: [{}] e1: [...int] e1: [...float] @@ -51,9 +53,9 @@ e1: [..._|_ // conflicting values int and float (mismatched types int and float) -- out/compile -- --- in.cue { - l0: (3 * [ + l0: 〈import;list〉.Repeat([ int, - ]) + ], 3) l0: [ 1, 2, @@ -73,17 +75,17 @@ e1: [..._|_ // conflicting values int and float (mismatched types int and float) b: 3 }, ] - s1: (6 * [ + s1: 〈import;list〉.Repeat([ int, - ])[2:3] + ], 6)[2:3] s2: [ 0, 2, 3, ][1:2] - i1: (6 * [ + i1: 〈import;list〉.Repeat([ int, - ])[2] + ], 6)[2] i2: [ 0, 2, @@ -103,9 +105,9 @@ e1: [..._|_ // conflicting values int and float (mismatched types int and float) t1: [ ...int, ] - e0: (2 * [ + e0: 〈import;list〉.Repeat([ {}, - ]) + ], 2) e0: [ {}, ] @@ -117,15 +119,15 @@ e1: [..._|_ // conflicting values int and float (mismatched types int and float) ] } -- out/eval/stats -- -Leaks: 15 -Freed: 26 -Reused: 23 -Allocs: 18 -Retain: 20 +Leaks: 3 +Freed: 54 +Reused: 50 +Allocs: 7 +Retain: 7 -Unifications: 41 -Conjuncts: 75 -Disjuncts: 45 +Unifications: 57 +Conjuncts: 99 +Disjuncts: 60 -- out/eval -- Errors: e0: incompatible list lengths (1 and 2) diff --git a/cue/testdata/lists/020_list_arithmetic.txtar b/cue/testdata/lists/020_list_arithmetic.txtar deleted file mode 100644 index fb3626e9359..00000000000 --- a/cue/testdata/lists/020_list_arithmetic.txtar +++ /dev/null @@ -1,513 +0,0 @@ -#name: list arithmetic -#evalPartial --- in.cue -- -l0: 3 * [1, 2, 3] -l1: 0 * [1, 2, 3] -l2: 10 * [] -l6: 3 * [...int] -l7: 3 * [1, ...int] -l8: 3 * [1, 2, ...int] - -s0: [] + [] -s1: [1] + [] -s2: [] + [2] -s3: [1] + [2] -s4: [1, 2] + [] -s5: [] + [1, 2] -s6: [1] + [1, 2] -s7: [1, 2] + [1] -s8: [1, 2] + [1, 2] -s9: [] + [...] -s10: [1] + [...] -s11: [] + [2, ...] -s12: [1] + [2, ...] -s13: [1, 2] + [...] -s14: [] + [1, 2, ...] -s15: [1] + [1, 2, ...] -s16: [1, 2] + [1, ...] -s17: [1, 2] + [1, 2, ...] - -s18: [...] + [] -s19: [1, ...] + [] -s20: [...] + [2] -s21: [1, ...] + [2] -s22: [1, 2, ...] + [] -s23: [...] + [1, 2] -s24: [1, ...] + [1, 2] -s25: [1, 2, ...] + [1] -s26: [1, 2, ...] + [1, 2] -s27: [...] + [...] -s28: [1, ...] + [...] -s29: [...] + [2, ...] -s30: [1, ...] + [2, ...] -s31: [1, 2, ...] + [...] -s32: [...] + [1, 2, ...] -s33: [1, ...] + [1, 2, ...] -s34: [1, 2, ...] + [1, ...] -s35: [1, 2, ...] + [1, 2, ...] --- out/def -- -l0: [1, 2, 3, 1, 2, 3, 1, 2, 3] -l1: [] -l2: [] -l3: <=2 * [] -l4: <=2 * [int] -l5: <=2 * (int * [int]) -l6: [] -l7: [1, 1, 1] -l8: [1, 2, 1, 2, 1, 2] -s0: [] -s1: [1] -s2: [2] -s3: [1, 2] -s4: [1, 2] -s5: [1, 2] -s6: [1, 1, 2] -s7: [1, 2, 1] -s8: [1, 2, 1, 2] -s9: [] -s10: [1] -s11: [2] -s12: [1, 2] -s13: [1, 2] -s14: [1, 2] -s15: [1, 1, 2] -s16: [1, 2, 1] -s17: [1, 2, 1, 2] -s18: [] -s19: [1] -s20: [2] -s21: [1, 2] -s22: [1, 2] -s23: [1, 2] -s24: [1, 1, 2] -s25: [1, 2, 1] -s26: [1, 2, 1, 2] -s27: [] -s28: [1] -s29: [2] -s30: [1, 2] -s31: [1, 2] -s32: [1, 2] -s33: [1, 1, 2] -s34: [1, 2, 1] -s35: [1, 2, 1, 2] --- out/legacy-debug -- -<0>{l0: [1,2,3,1,2,3,1,2,3], l1: [], l2: [], l3: (<=2 * []), l4: (<=2 * [int]), l5: (<=2 * (int * [int])), l6: [], l7: [1,1,1], l8: [1,2,1,2,1,2], s0: [], s1: [1], s2: [2], s3: [1,2], s4: [1,2], s5: [1,2], s6: [1,1,2], s7: [1,2,1], s8: [1,2,1,2], s9: [], s10: [1], s11: [2], s12: [1,2], s13: [1,2], s14: [1,2], s15: [1,1,2], s16: [1,2,1], s17: [1,2,1,2], s18: [], s19: [1], s20: [2], s21: [1,2], s22: [1,2], s23: [1,2], s24: [1,1,2], s25: [1,2,1], s26: [1,2,1,2], s27: [], s28: [1], s29: [2], s30: [1,2], s31: [1,2], s32: [1,2], s33: [1,1,2], s34: [1,2,1], s35: [1,2,1,2]} --- out/compile -- ---- in.cue -{ - l0: (3 * [ - 1, - 2, - 3, - ]) - l1: (0 * [ - 1, - 2, - 3, - ]) - l2: (10 * []) - l6: (3 * [ - ...int, - ]) - l7: (3 * [ - 1, - ...int, - ]) - l8: (3 * [ - 1, - 2, - ...int, - ]) - s0: ([] + []) - s1: ([ - 1, - ] + []) - s2: ([] + [ - 2, - ]) - s3: ([ - 1, - ] + [ - 2, - ]) - s4: ([ - 1, - 2, - ] + []) - s5: ([] + [ - 1, - 2, - ]) - s6: ([ - 1, - ] + [ - 1, - 2, - ]) - s7: ([ - 1, - 2, - ] + [ - 1, - ]) - s8: ([ - 1, - 2, - ] + [ - 1, - 2, - ]) - s9: ([] + [ - ..., - ]) - s10: ([ - 1, - ] + [ - ..., - ]) - s11: ([] + [ - 2, - ..., - ]) - s12: ([ - 1, - ] + [ - 2, - ..., - ]) - s13: ([ - 1, - 2, - ] + [ - ..., - ]) - s14: ([] + [ - 1, - 2, - ..., - ]) - s15: ([ - 1, - ] + [ - 1, - 2, - ..., - ]) - s16: ([ - 1, - 2, - ] + [ - 1, - ..., - ]) - s17: ([ - 1, - 2, - ] + [ - 1, - 2, - ..., - ]) - s18: ([ - ..., - ] + []) - s19: ([ - 1, - ..., - ] + []) - s20: ([ - ..., - ] + [ - 2, - ]) - s21: ([ - 1, - ..., - ] + [ - 2, - ]) - s22: ([ - 1, - 2, - ..., - ] + []) - s23: ([ - ..., - ] + [ - 1, - 2, - ]) - s24: ([ - 1, - ..., - ] + [ - 1, - 2, - ]) - s25: ([ - 1, - 2, - ..., - ] + [ - 1, - ]) - s26: ([ - 1, - 2, - ..., - ] + [ - 1, - 2, - ]) - s27: ([ - ..., - ] + [ - ..., - ]) - s28: ([ - 1, - ..., - ] + [ - ..., - ]) - s29: ([ - ..., - ] + [ - 2, - ..., - ]) - s30: ([ - 1, - ..., - ] + [ - 2, - ..., - ]) - s31: ([ - 1, - 2, - ..., - ] + [ - ..., - ]) - s32: ([ - ..., - ] + [ - 1, - 2, - ..., - ]) - s33: ([ - 1, - ..., - ] + [ - 1, - 2, - ..., - ]) - s34: ([ - 1, - 2, - ..., - ] + [ - 1, - ..., - ]) - s35: ([ - 1, - 2, - ..., - ] + [ - 1, - 2, - ..., - ]) -} --- out/eval/stats -- -Leaks: 198 -Freed: 133 -Reused: 130 -Allocs: 201 -Retain: 210 - -Unifications: 331 -Conjuncts: 475 -Disjuncts: 253 --- out/eval -- -(struct){ - l0: (#list){ - 0: (int){ 1 } - 1: (int){ 2 } - 2: (int){ 3 } - 3: (int){ 1 } - 4: (int){ 2 } - 5: (int){ 3 } - 6: (int){ 1 } - 7: (int){ 2 } - 8: (int){ 3 } - } - l1: (#list){ - } - l2: (#list){ - } - l6: (#list){ - } - l7: (#list){ - 0: (int){ 1 } - 1: (int){ 1 } - 2: (int){ 1 } - } - l8: (#list){ - 0: (int){ 1 } - 1: (int){ 2 } - 2: (int){ 1 } - 3: (int){ 2 } - 4: (int){ 1 } - 5: (int){ 2 } - } - s0: (#list){ - } - s1: (#list){ - 0: (int){ 1 } - } - s2: (#list){ - 0: (int){ 2 } - } - s3: (#list){ - 0: (int){ 1 } - 1: (int){ 2 } - } - s4: (#list){ - 0: (int){ 1 } - 1: (int){ 2 } - } - s5: (#list){ - 0: (int){ 1 } - 1: (int){ 2 } - } - s6: (#list){ - 0: (int){ 1 } - 1: (int){ 1 } - 2: (int){ 2 } - } - s7: (#list){ - 0: (int){ 1 } - 1: (int){ 2 } - 2: (int){ 1 } - } - s8: (#list){ - 0: (int){ 1 } - 1: (int){ 2 } - 2: (int){ 1 } - 3: (int){ 2 } - } - s9: (#list){ - } - s10: (#list){ - 0: (int){ 1 } - } - s11: (#list){ - 0: (int){ 2 } - } - s12: (#list){ - 0: (int){ 1 } - 1: (int){ 2 } - } - s13: (#list){ - 0: (int){ 1 } - 1: (int){ 2 } - } - s14: (#list){ - 0: (int){ 1 } - 1: (int){ 2 } - } - s15: (#list){ - 0: (int){ 1 } - 1: (int){ 1 } - 2: (int){ 2 } - } - s16: (#list){ - 0: (int){ 1 } - 1: (int){ 2 } - 2: (int){ 1 } - } - s17: (#list){ - 0: (int){ 1 } - 1: (int){ 2 } - 2: (int){ 1 } - 3: (int){ 2 } - } - s18: (#list){ - } - s19: (#list){ - 0: (int){ 1 } - } - s20: (#list){ - 0: (int){ 2 } - } - s21: (#list){ - 0: (int){ 1 } - 1: (int){ 2 } - } - s22: (#list){ - 0: (int){ 1 } - 1: (int){ 2 } - } - s23: (#list){ - 0: (int){ 1 } - 1: (int){ 2 } - } - s24: (#list){ - 0: (int){ 1 } - 1: (int){ 1 } - 2: (int){ 2 } - } - s25: (#list){ - 0: (int){ 1 } - 1: (int){ 2 } - 2: (int){ 1 } - } - s26: (#list){ - 0: (int){ 1 } - 1: (int){ 2 } - 2: (int){ 1 } - 3: (int){ 2 } - } - s27: (#list){ - } - s28: (#list){ - 0: (int){ 1 } - } - s29: (#list){ - 0: (int){ 2 } - } - s30: (#list){ - 0: (int){ 1 } - 1: (int){ 2 } - } - s31: (#list){ - 0: (int){ 1 } - 1: (int){ 2 } - } - s32: (#list){ - 0: (int){ 1 } - 1: (int){ 2 } - } - s33: (#list){ - 0: (int){ 1 } - 1: (int){ 1 } - 2: (int){ 2 } - } - s34: (#list){ - 0: (int){ 1 } - 1: (int){ 2 } - 2: (int){ 1 } - } - s35: (#list){ - 0: (int){ 1 } - 1: (int){ 2 } - 2: (int){ 1 } - 3: (int){ 2 } - } -} diff --git a/cue/testdata/scalars/embed.txtar b/cue/testdata/scalars/embed.txtar index 54b75de6d12..7bc3edcf074 100644 --- a/cue/testdata/scalars/embed.txtar +++ b/cue/testdata/scalars/embed.txtar @@ -2,6 +2,7 @@ -- in.cue -- import "strings" +import "list" intEmbed: { a1: { @@ -26,7 +27,7 @@ listEmbed: { [1, 2] #foo: 1 } - b4: b3 + b3 + b4: list.Concat([b3, b3]) b5: b3[1] b6: b3[5] b7: b4[a1] // 1 @@ -151,19 +152,19 @@ selfRefInEmbed: t1: { } -- out/eval/stats -- -Leaks: 11 -Freed: 121 -Reused: 114 -Allocs: 18 +Leaks: 10 +Freed: 135 +Reused: 128 +Allocs: 17 Retain: 57 -Unifications: 128 -Conjuncts: 297 -Disjuncts: 164 +Unifications: 141 +Conjuncts: 313 +Disjuncts: 178 -- out/evalalpha -- Errors: listEmbed.b6: index out of range [5] with length 2: - ./in.cue:28:9 + ./in.cue:29:9 Result: (_|_){ @@ -197,7 +198,7 @@ Result: b5: (int){ 2 } b6: (_|_){ // [eval] listEmbed.b6: index out of range [5] with length 2: - // ./in.cue:28:9 + // ./in.cue:29:9 } b7: (int){ 1 } } @@ -222,8 +223,8 @@ Result: sum: (struct){ out: (_|_){ // [incomplete] outPattern.sum.out: non-concrete value int in operand to +: - // ./in.cue:43:8 // ./in.cue:44:8 + // ./in.cue:45:8 } #a: (int){ int } #b: (int){ int } @@ -237,8 +238,8 @@ Result: arithmetic: (struct){ sum: (_|_){ // [incomplete] arithmetic.sum: non-concrete value int in operand to +: - // ./in.cue:52:3 - // ./in.cue:53:7 + // ./in.cue:53:3 + // ./in.cue:54:7 #a: (int){ int } #b: (int){ int } } @@ -378,7 +379,7 @@ diff old new Errors: -listEmbed.b6: invalid list index 5 (out of bounds): +listEmbed.b6: index out of range [5] with length 2: - ./in.cue:28:9 + ./in.cue:29:9 Result: @@ -12,10 +12,7 @@ @@ -399,7 +400,7 @@ diff old new b6: (_|_){ - // [eval] listEmbed.b6: invalid list index 5 (out of bounds): + // [eval] listEmbed.b6: index out of range [5] with length 2: - // ./in.cue:28:9 + // ./in.cue:29:9 } b7: (int){ 1 } @@ -69,9 +66,9 @@ @@ -420,7 +421,7 @@ Improved error message. -- out/eval -- Errors: listEmbed.b6: invalid list index 5 (out of bounds): - ./in.cue:28:9 + ./in.cue:29:9 Result: (_|_){ @@ -457,7 +458,7 @@ Result: b5: (int){ 2 } b6: (_|_){ // [eval] listEmbed.b6: invalid list index 5 (out of bounds): - // ./in.cue:28:9 + // ./in.cue:29:9 } b7: (int){ 1 } } @@ -482,8 +483,8 @@ Result: sum: (struct){ out: (_|_){ // [incomplete] outPattern.sum.out: non-concrete value int in operand to +: - // ./in.cue:43:8 // ./in.cue:44:8 + // ./in.cue:45:8 } #a: (int){ int } #b: (int){ int } @@ -497,8 +498,8 @@ Result: arithmetic: (struct){ sum: (_|_){ // [incomplete] arithmetic.sum: non-concrete value int in operand to +: - // ./in.cue:52:3 - // ./in.cue:53:7 + // ./in.cue:53:3 + // ./in.cue:54:7 #a: (int){ int } #b: (int){ int } } @@ -658,7 +659,10 @@ Result: ] #foo: 1 } - b4: (〈0;b3〉 + 〈0;b3〉) + b4: 〈import;list〉.Concat([ + 〈1;b3〉, + 〈1;b3〉, + ]) b5: 〈0;b3〉[1] b6: 〈0;b3〉[5] b7: 〈0;b4〉[〈0;a1〉] diff --git a/cue/types_test.go b/cue/types_test.go index 5676d02d377..ec641b56c8f 100644 --- a/cue/types_test.go +++ b/cue/types_test.go @@ -3027,7 +3027,10 @@ func TestWalk(t *testing.T) { out: `[int]`, }, { value: `3 * [1, 2]`, - out: `[1,2,1,2,1,2]`, + out: `_|_(Multiplication of lists is superseded by list.Repeat; see https://cuelang.org/e/v0.11-list-arithmetic)`, + }, { + value: `[7, 8] + [1, 2]`, + out: `_|_(Addition of lists is superseded by list.Concat; see https://cuelang.org/e/v0.11-list-arithmetic)`, }, { value: `{}`, out: `{}`, diff --git a/cuego/cuego_test.go b/cuego/cuego_test.go index 7094e9e3619..1efed9bac2e 100644 --- a/cuego/cuego_test.go +++ b/cuego/cuego_test.go @@ -67,12 +67,6 @@ func TestValidate(t *testing.T) { name: "string list", value: []string{"a", "b", "c"}, constraints: `[_, "b", ...]`, - }, { - // Not a typical constraint, but it is possible. - name: "string list incompatible lengths", - value: []string{"a", "b", "c"}, - constraints: `4*[string]`, - err: fail, }} for _, tc := range testCases { @@ -91,13 +85,6 @@ func TestValidate(t *testing.T) { } func TestUpdate(t *testing.T) { - type updated struct { - A []*int `cue:"[...int|*1]"` // arbitrary length slice with values 1 - B []int `cue:"3*[int|*1]"` // slice of length 3, defaults to [1,1,1] - - // TODO: better errors if the user forgets to quote. - M map[string]int `cue:",opt"` - } type sump struct { A *int `cue:"C-B"` B *int `cue:"C-A"` @@ -155,36 +142,6 @@ func TestUpdate(t *testing.T) { value: []string{"a", "b", "c"}, result: []string{"a", "b", "c"}, err: fail, - }, { - name: "composite values update", - // allocate a slice with uninitialized values and let Update fill - // out default values. - value: &updated{A: make([]*int, 3)}, - result: &updated{ - A: []*int{&one, &one, &one}, - B: []int{1, 1, 1}, - M: map[string]int(nil), - }, - }, { - name: "composite values update with unsatisfied map constraints", - value: &updated{}, - result: &updated{}, - - constraints: ` { M: {foo: bar, bar: foo} } `, - err: fail, // incomplete values - }, { - name: "composite values update with map constraints", - value: &updated{M: map[string]int{"foo": 1}}, - constraints: ` { M: {foo: bar, bar: foo} } `, - result: &updated{ - // TODO: would be better if this is nil, but will not matter for - // JSON output: if omitempty is false, an empty list will be - // printed regardless, and if it is true, it will be omitted - // regardless. - A: []*int{}, - B: []int{1, 1, 1}, - M: map[string]int{"bar": 1, "foo": 1}, - }, }} for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { diff --git a/encoding/gocode/gocodec/codec_test.go b/encoding/gocode/gocodec/codec_test.go index cacdd8d3156..bc4ab3aa091 100644 --- a/encoding/gocode/gocodec/codec_test.go +++ b/encoding/gocode/gocodec/codec_test.go @@ -71,12 +71,6 @@ func TestValidate(t *testing.T) { name: "string list", value: []string{"a", "b", "c"}, constraints: `[_, "b", ...]`, - }, { - // Not a typical constraint, but it is possible. - name: "string list incompatible lengths", - value: []string{"a", "b", "c"}, - constraints: `4*[string]`, - err: fail, }} for _, tc := range testCases { @@ -111,13 +105,6 @@ func TestValidate(t *testing.T) { } func TestComplete(t *testing.T) { - type updated struct { - A []*int `cue:"[...int|*1]"` // arbitrary length slice with values 1 - B []int `cue:"3*[int|*1]"` // slice of length 3, defaults to [1,1,1] - - // TODO: better errors if the user forgets to quote. - M map[string]int `cue:",opt"` - } type sump struct { A *int `cue:"C-B"` B *int `cue:"C-A"` @@ -175,36 +162,6 @@ func TestComplete(t *testing.T) { value: []string{"a", "b", "c"}, result: []string{"a", "b", "c"}, err: fail, - }, { - name: "composite values update", - // allocate a slice with uninitialized values and let Update fill - // out default values. - value: &updated{A: make([]*int, 3)}, - result: &updated{ - A: []*int{&one, &one, &one}, - B: []int{1, 1, 1}, - M: map[string]int(nil), - }, - }, { - name: "composite values update with unsatisfied map constraints", - value: &updated{}, - result: &updated{}, - - constraints: ` { M: {foo: bar, bar: foo} } `, - err: fail, // incomplete values - }, { - name: "composite values update with map constraints", - value: &updated{M: map[string]int{"foo": 1}}, - constraints: ` { M: {foo: bar, bar: foo} } `, - result: &updated{ - // TODO: would be better if this is nil, but will not matter for - // JSON output: if omitempty is false, an empty list will be - // printed regardless, and if it is true, it will be omitted - // regardless. - A: []*int{}, - B: []int{1, 1, 1}, - M: map[string]int{"bar": 1, "foo": 1}, - }, }} for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { diff --git a/internal/core/adt/binop.go b/internal/core/adt/binop.go index 254412e3255..52f45b4c6fe 100644 --- a/internal/core/adt/binop.go +++ b/internal/core/adt/binop.go @@ -173,49 +173,7 @@ func BinOp(c *OpContext, op Op, left, right Value) Value { return c.newBytes(b) case leftKind == ListKind && rightKind == ListKind: - // TODO: get rid of list addition. Semantically it is somewhat - // unclear and, as it turns out, it is also hard to get right. - // Simulate addition with comprehensions now. - if err := c.Err(); err != nil { - return err - } - - x := MakeIdentLabel(c, "x", "") - - // for x in expr { x } - forClause := func(src Expr) *Comprehension { - s := &StructLit{Decls: []Decl{ - &FieldReference{UpCount: 1, Label: x}, - }} - return &Comprehension{ - Clauses: []Yielder{ - &ForClause{ - Value: x, - Src: src, - }, - }, - Value: s, - } - } - - list := &ListLit{ - Elems: []Elem{ - forClause(left), - forClause(right), - }, - } - - n := c.newInlineVertex(nil, nil, MakeConjunct(c.Env(0), list, c.ci)) - n.CompleteArcs(c) - - // NOTE: if we set isData to true, whoever processes the result will - // avoid having to process the expressions again. This improves - // performance. It also change the a potential cycle error message - // to a more concrete messages as if this result was unified as is. - // TODO: uncomment this and see if we like the result. - // n.isData = true - - return n + return c.NewErrf("Addition of lists is superseded by list.Concat; see https://cuelang.org/e/v0.11-list-arithmetic") } case SubtractOp: @@ -243,40 +201,10 @@ func BinOp(c *OpContext, op Op, left, right Value) Value { const as = "bytes multiplication" return c.newBytes(bytes.Repeat(c.bytesValue(right, as), int(c.uint64(left, as)))) - case leftKind == ListKind && rightKind == IntKind: - left, right = right, left - fallthrough - case leftKind == IntKind && rightKind == ListKind: - // TODO: get rid of list multiplication. - - list := &ListLit{} - x := MakeIdentLabel(c, "x", "") - - for i := c.uint64(left, "list multiplier"); i > 0; i-- { - st := &StructLit{Decls: []Decl{ - &FieldReference{UpCount: 1, Label: x}, - }} - list.Elems = append(list.Elems, - &Comprehension{ - Clauses: []Yielder{ - &ForClause{ - Value: x, - Src: right, - }, - }, - Value: st, - }, - ) - } - if err := c.Err(); err != nil { - return err - } - - n := c.newInlineVertex(nil, nil, MakeConjunct(c.Env(0), list, c.ci)) - n.CompleteArcs(c) - - return n + fallthrough + case leftKind == ListKind && rightKind == IntKind: + return c.NewErrf("Multiplication of lists is superseded by list.Repeat; see https://cuelang.org/e/v0.11-list-arithmetic") } case FloatQuotientOp: