Skip to content

Commit 46fb300

Browse files
cuematthewmvdan
authored andcommitted
all: remove support for list arithmetic
And adjust or remove tests that use list arithmetic. This has a knock-on effect that in cuego, tags which indicate list length are no longer supported. E.g. `cue:"3*[int|*1]"`. We cannot automatically fix these use cases, but we also don't expect this change to cause breakages as list arithmetic has been undocumented for years and cuego tags tend to be simple expressions. Some of the fixes to tests expose different bugs/limitations in evalv2, though work fine with evalv3, so it's possible evalv2 users will experience more bugs after this change. But these are only in very odd semi-cyclic scenarios. Note that this breaking language change is not based on `language.version` from `cue.mod/module.cue`; the language spec has not mentioned arithmetic on lists for years, and aligning the evaluator with the spec has been planned for some time. Moreover, every CUE configuration should be able to switch to `list.Concat` and `list.Repeat`, for example via `cue fix`. Fixes #2237 Signed-off-by: Matthew Sackman <[email protected]> Change-Id: I39fe190ac2131f60734f91485474e9c94758367f Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1200221 Unity-Result: CUE porcuepine <[email protected]> Reviewed-by: Daniel Martí <[email protected]> TryBot-Result: CUEcueckoo <[email protected]>
1 parent 6f4983e commit 46fb300

File tree

16 files changed

+478
-1352
lines changed

16 files changed

+478
-1352
lines changed

Diff for: cue/testdata/basicrewrite/011_list_arithmetic.txtar

-108
This file was deleted.

Diff for: cue/testdata/comprehensions/issue843.txtar

+17-12
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
-- in.cue --
22
package main
33

4+
import "list"
5+
46
#d1: {
57
as: [...string]
68

79
#c: [
810
#f1 & {
9-
"as": ["go"] + as
11+
"as": list.Concat([["go"], as])
1012
},
1113
]
1214
}
@@ -41,15 +43,15 @@ package main
4143
from: #c1
4244
}
4345
-- out/eval/stats --
44-
Leaks: 9
45-
Freed: 55
46-
Reused: 41
47-
Allocs: 23
48-
Retain: 14
46+
Leaks: 0
47+
Freed: 85
48+
Reused: 70
49+
Allocs: 15
50+
Retain: 7
4951

50-
Unifications: 52
51-
Conjuncts: 120
52-
Disjuncts: 66
52+
Unifications: 65
53+
Conjuncts: 159
54+
Disjuncts: 92
5355
-- out/evalalpha --
5456
(struct){
5557
#d1: (#struct){
@@ -239,9 +241,12 @@ Reordering
239241
]
240242
#c: [
241243
(〈2;#f1〉 & {
242-
as: ([
243-
"go",
244-
] + 〈2;as〉)
244+
as: 〈import;list〉.Concat([
245+
[
246+
"go",
247+
],
248+
〈3;as〉,
249+
])
245250
}),
246251
]
247252
}

Diff for: cue/testdata/cycle/chain.txtar

+72-41
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ chain: t2: p1: {
3030
X: 1
3131

3232
// Reference X through x.x0 before X is inserted.
33-
for v in [0, X] + [] {
33+
for v in list.Concat([[0, X], []]) {
3434
x: "x\(v)": {}
3535
}
3636

@@ -41,7 +41,7 @@ chain: t2: p1: {
4141

4242
chain: t2: p2: {
4343
// Reference X through x.x0 before X is inserted.
44-
for v in [0, X] + [] {
44+
for v in list.Concat([[0, X], []]) {
4545
x: "x\(v)": {}
4646
}
4747

@@ -208,14 +208,14 @@ issue2052: full: {
208208
d: #Depth & {#in: tree}
209209
}
210210
-- out/evalalpha/stats --
211-
Leaks: 19997
211+
Leaks: 19999
212212
Freed: 1462
213213
Reused: 1461
214-
Allocs: 19998
214+
Allocs: 20000
215215
Retain: 0
216216

217-
Unifications: 7504
218-
Conjuncts: 107530
217+
Unifications: 7506
218+
Conjuncts: 107540
219219
Disjuncts: 13655
220220
-- out/evalalpha --
221221
Errors:
@@ -720,22 +720,22 @@ diff old new
720720
--- old
721721
+++ new
722722
@@ -1,9 +1,9 @@
723-
-Leaks: 70
724-
-Freed: 1815
725-
-Reused: 1801
726-
-Allocs: 84
727-
-Retain: 185
728-
+Leaks: 19997
723+
-Leaks: 56
724+
-Freed: 1830
725+
-Reused: 1816
726+
-Allocs: 70
727+
-Retain: 169
728+
+Leaks: 19999
729729
+Freed: 1462
730730
+Reused: 1461
731-
+Allocs: 19998
731+
+Allocs: 20000
732732
+Retain: 0
733733

734-
-Unifications: 800
735-
-Conjuncts: 3175
736-
-Disjuncts: 1974
737-
+Unifications: 7504
738-
+Conjuncts: 107530
734+
-Unifications: 801
735+
-Conjuncts: 3177
736+
-Disjuncts: 1979
737+
+Unifications: 7506
738+
+Conjuncts: 107540
739739
+Disjuncts: 13655
740740
-- diff/-out/evalalpha<==>+out/eval --
741741
diff old new
@@ -755,7 +755,28 @@ diff old new
755755
chain: (struct){
756756
t1: (struct){
757757
#maxiter: (int){ 2 }
758-
@@ -47,148 +55,148 @@
758+
@@ -27,15 +35,11 @@
759+
}
760+
}
761+
}
762+
- p2: (_|_){
763+
- // [incomplete] 1: invalid interpolation: cycle error referencing X:
764+
- // ./in.cue:44:6
765+
- // ./in.cue:43:28
766+
- x: (_|_){
767+
- // [incomplete] 1: invalid interpolation: cycle error referencing X:
768+
- // ./in.cue:44:6
769+
- // ./in.cue:43:28
770+
- x0: (struct){
771+
+ p2: (struct){
772+
+ x: (struct){
773+
+ x0: (struct){
774+
+ }
775+
+ x1: (struct){
776+
}
777+
}
778+
X: (int){ 1 }
779+
@@ -51,148 +55,148 @@
759780
}
760781
}
761782
}
@@ -1041,7 +1062,7 @@ diff old new
10411062
#maxiter: (int){ |(*(int){ 4 }, (int){ &(>=0, int) }) }
10421063
#funcFactory: (#struct){
10431064
#next: (_){ _ }
1044-
@@ -335,49 +343,7 @@
1065+
@@ -339,49 +343,7 @@
10451066
}
10461067
cow: (string){ "moo" }
10471068
}
@@ -1092,7 +1113,7 @@ diff old new
10921113
#in: (#struct){
10931114
a: (#struct){
10941115
foo: (string){ "bar" }
1095-
@@ -389,6 +355,142 @@
1116+
@@ -393,6 +355,142 @@
10961117
}
10971118
cow: (string){ "moo" }
10981119
}
@@ -1236,15 +1257,15 @@ diff old new
12361257
}
12371258
}
12381259
-- out/eval/stats --
1239-
Leaks: 70
1240-
Freed: 1815
1241-
Reused: 1801
1242-
Allocs: 84
1243-
Retain: 185
1260+
Leaks: 56
1261+
Freed: 1830
1262+
Reused: 1816
1263+
Allocs: 70
1264+
Retain: 169
12441265

1245-
Unifications: 800
1246-
Conjuncts: 3175
1247-
Disjuncts: 1974
1266+
Unifications: 801
1267+
Conjuncts: 3177
1268+
Disjuncts: 1979
12481269
-- diff/todo/p1 --
12491270
issue2052.*.#Depth: incorrect error message:
12501271
"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"
12801301
}
12811302
}
12821303
}
1283-
p2: (struct){
1284-
x: (struct){
1304+
p2: (_|_){
1305+
// [incomplete] 1: invalid interpolation: cycle error referencing X:
1306+
// ./in.cue:44:6
1307+
// ./in.cue:43:28
1308+
x: (_|_){
1309+
// [incomplete] 1: invalid interpolation: cycle error referencing X:
1310+
// ./in.cue:44:6
1311+
// ./in.cue:43:28
12851312
x0: (struct){
12861313
}
1287-
x1: (struct){
1288-
}
12891314
}
12901315
X: (int){ 1 }
12911316
}
@@ -1676,10 +1701,13 @@ issue2052.full.d: "cannot add field #maxiter: was already used"
16761701
t2: {
16771702
p1: {
16781703
X: 1
1679-
for _, v in ([
1680-
0,
1681-
〈1;X〉,
1682-
] + []) {
1704+
for _, v in 〈import;list〉.Concat([
1705+
[
1706+
0,
1707+
〈2;X〉,
1708+
],
1709+
[],
1710+
]) {
16831711
x: {
16841712
"x\(〈2;v〉)": {}
16851713
}
@@ -1692,10 +1720,13 @@ issue2052.full.d: "cannot add field #maxiter: was already used"
16921720
chain: {
16931721
t2: {
16941722
p2: {
1695-
for _, v in ([
1696-
0,
1697-
〈1;X〉,
1698-
] + []) {
1723+
for _, v in 〈import;list〉.Concat([
1724+
[
1725+
0,
1726+
〈2;X〉,
1727+
],
1728+
[],
1729+
]) {
16991730
x: {
17001731
"x\(〈2;v〉)": {}
17011732
}

0 commit comments

Comments
 (0)