Skip to content

Commit

Permalink
all: remove support for list arithmetic
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
cuematthew authored and mvdan committed Sep 3, 2024
1 parent 6f4983e commit 46fb300
Show file tree
Hide file tree
Showing 16 changed files with 478 additions and 1,352 deletions.
108 changes: 0 additions & 108 deletions cue/testdata/basicrewrite/011_list_arithmetic.txtar

This file was deleted.

29 changes: 17 additions & 12 deletions cue/testdata/comprehensions/issue843.txtar
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
-- in.cue --
package main

import "list"

#d1: {
as: [...string]

#c: [
#f1 & {
"as": ["go"] + as
"as": list.Concat([["go"], as])
},
]
}
Expand Down Expand Up @@ -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){
Expand Down Expand Up @@ -239,9 +241,12 @@ Reordering
]
#c: [
(〈2;#f1〉 & {
as: ([
"go",
] + 〈2;as〉)
as: 〈import;list〉.Concat([
[
"go",
],
〈3;as〉,
])
}),
]
}
Expand Down
113 changes: 72 additions & 41 deletions cue/testdata/cycle/chain.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -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)": {}
}

Expand All @@ -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)": {}
}

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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 @@
}
}
}
Expand Down Expand Up @@ -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" }
}
Expand Down Expand Up @@ -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" }
}
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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 }
}
Expand Down Expand Up @@ -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〉)": {}
}
Expand All @@ -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〉)": {}
}
Expand Down
Loading

0 comments on commit 46fb300

Please sign in to comment.