Skip to content

Commit 1ac3fe0

Browse files
committed
internal/core/adt: remove closedness for ToDataAll
Data is inherently non-closed. In particular, converting to data removes pattern constraints and required and optional fields, removing its closedness properties. Consider this example: x: matchN(1, [{ a!: _ }]) x: close({ a!: string }) matchN is defined to convert the value it validates to data first. In the process, any pattern constraints and optional and required fields. In this example this means that what is checked is equivalent to close({}). Clearly, if we remove the constraints, we should also remove the "is closed" property, as otherwise it will fail to match the schema of matchN. Fixes #3694 Signed-off-by: Marcel van Lohuizen <[email protected]> Change-Id: I16c814bd19502a8729b2817a295550e6744b15a8 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1207714 TryBot-Result: CUEcueckoo <[email protected]> Unity-Result: CUE porcuepine <[email protected]> Reviewed-by: Roger Peppe <[email protected]>
1 parent f02d1f1 commit 1ac3fe0

File tree

2 files changed

+24
-70
lines changed

2 files changed

+24
-70
lines changed

cue/testdata/builtins/matchn.txtar

Lines changed: 16 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -803,14 +803,6 @@ incomplete.err5.x: invalid value {bar:2} (does not satisfy matchN): 1 matched, e
803803
./incomplete.cue:55:6
804804
./incomplete.cue:55:13
805805
./incomplete.cue:56:6
806-
issue3694.full.#step: invalid value {uses?:string,run?:string} (does not satisfy matchN): 0 matched, expected 1:
807-
./issue3694.cue:2:9
808-
./issue3694.cue:2:16
809-
./issue3694.cue:9:9
810-
issue3694.simple.#step: invalid value {uses?:string} (does not satisfy matchN): 0 matched, expected 1:
811-
./issue3694.cue:19:9
812-
./issue3694.cue:19:16
813-
./issue3694.cue:22:9
814806

815807
Result:
816808
(_|_){
@@ -1175,12 +1167,10 @@ Result:
11751167
}
11761168
}
11771169
}
1178-
issue3694: (_|_){
1179-
// [eval]
1180-
full: (_|_){
1181-
// [eval]
1170+
issue3694: (struct){
1171+
full: (struct){
11821172
#step: (_|_){
1183-
// [eval] issue3694.full.#step: invalid value {uses?:string,run?:string} (does not satisfy matchN): 0 matched, expected 1:
1173+
// [incomplete] issue3694.full.#step: invalid value {uses?:string,run?:string} (does not satisfy matchN): 0 matched, expected 1:
11841174
// ./issue3694.cue:2:9
11851175
// ./issue3694.cue:2:16
11861176
// ./issue3694.cue:9:9
@@ -1192,10 +1182,9 @@ Result:
11921182
uses?: (string){ string }
11931183
}
11941184
}
1195-
simple: (_|_){
1196-
// [eval]
1185+
simple: (struct){
11971186
#step: (_|_){
1198-
// [eval] issue3694.simple.#step: invalid value {uses?:string} (does not satisfy matchN): 0 matched, expected 1:
1187+
// [incomplete] issue3694.simple.#step: invalid value {uses?:string} (does not satisfy matchN): 0 matched, expected 1:
11991188
// ./issue3694.cue:19:9
12001189
// ./issue3694.cue:19:16
12011190
// ./issue3694.cue:22:9
@@ -1220,22 +1209,7 @@ diff old new
12201209
incomplete.err1.x: invalid value {bar:2} (does not satisfy matchN): 0 matched, expected 1:
12211210
./incomplete.cue:34:6
12221211
./incomplete.cue:34:13
1223-
@@ -72,6 +67,14 @@
1224-
./incomplete.cue:55:6
1225-
./incomplete.cue:55:13
1226-
./incomplete.cue:56:6
1227-
+issue3694.full.#step: invalid value {uses?:string,run?:string} (does not satisfy matchN): 0 matched, expected 1:
1228-
+ ./issue3694.cue:2:9
1229-
+ ./issue3694.cue:2:16
1230-
+ ./issue3694.cue:9:9
1231-
+issue3694.simple.#step: invalid value {uses?:string} (does not satisfy matchN): 0 matched, expected 1:
1232-
+ ./issue3694.cue:19:9
1233-
+ ./issue3694.cue:19:16
1234-
+ ./issue3694.cue:22:9
1235-
1236-
Result:
1237-
(_|_){
1238-
@@ -111,7 +114,7 @@
1212+
@@ -111,7 +106,7 @@
12391213
0: (int){ 2 }
12401214
}), int) }) }
12411215
pickTopOK2: (int){ &(matchN(1, (#list){
@@ -1244,7 +1218,7 @@ diff old new
12441218
}
12451219
}), int) }
12461220
pickTopErr: (int){ &(matchN(1, (#list){
1247-
@@ -244,21 +247,21 @@
1221+
@@ -244,21 +239,21 @@
12481222
embed: (struct){
12491223
t1: (struct){
12501224
a: (_){ matchN(1, (#list){
@@ -1281,7 +1255,7 @@ diff old new
12811255
}
12821256
}) }
12831257
}
1284-
@@ -266,21 +269,21 @@
1258+
@@ -266,21 +261,21 @@
12851259
direct: (struct){
12861260
t1: (struct){
12871261
a: (_){ matchN(1, (#list){
@@ -1318,7 +1292,7 @@ diff old new
13181292
}
13191293
}) }
13201294
}
1321-
@@ -294,9 +297,9 @@
1295+
@@ -294,9 +289,9 @@
13221296
}
13231297
ok2: (struct){
13241298
x: (_){ matchN(0, (#list){
@@ -1331,7 +1305,7 @@ diff old new
13311305
}
13321306
}) }
13331307
}
1334-
@@ -306,23 +309,16 @@
1308+
@@ -306,23 +301,16 @@
13351309
}
13361310
}
13371311
}
@@ -1364,7 +1338,7 @@ diff old new
13641338
a: (int){ 1 }
13651339
}
13661340
}
1367-
@@ -329,10 +325,10 @@
1341+
@@ -329,10 +317,10 @@
13681342
}
13691343
test2: (struct){
13701344
#x: (_){ matchN(1, (#list){
@@ -1379,7 +1353,7 @@ diff old new
13791353
a: (int){ 1 }
13801354
}
13811355
}
1382-
@@ -350,9 +346,9 @@
1356+
@@ -350,9 +338,9 @@
13831357
}
13841358
incomplete2: (struct){
13851359
x: (_){ matchN(1, (#list){
@@ -1392,44 +1366,16 @@ diff old new
13921366
}
13931367
}) }
13941368
}
1395-
@@ -443,10 +439,12 @@
1396-
}
1397-
}
1398-
}
1399-
- issue3694: (struct){
1400-
- full: (struct){
1401-
- #step: (_|_){
1402-
- // [incomplete] issue3694.full.#step: invalid value {uses?:string,run?:string} (does not satisfy matchN): 0 matched, expected 1:
1403-
+ issue3694: (_|_){
1404-
+ // [eval]
1405-
+ full: (_|_){
1406-
+ // [eval]
1407-
+ #step: (_|_){
1408-
+ // [eval] issue3694.full.#step: invalid value {uses?:string,run?:string} (does not satisfy matchN): 0 matched, expected 1:
1409-
// ./issue3694.cue:2:9
1410-
// ./issue3694.cue:2:16
1411-
// ./issue3694.cue:9:9
1412-
@@ -454,13 +452,14 @@
1369+
@@ -454,8 +442,8 @@
14131370
run?: (string){ string }
14141371
}
14151372
s: (#struct){
14161373
- uses?: (string){ string }
14171374
run: (string){ "echo hello world" }
1418-
- }
1419-
- }
1420-
- simple: (struct){
1421-
- #step: (_|_){
1422-
- // [incomplete] issue3694.simple.#step: invalid value {uses?:string} (does not satisfy matchN): 0 matched, expected 1:
14231375
+ uses?: (string){ string }
1424-
+ }
1425-
+ }
1426-
+ simple: (_|_){
1427-
+ // [eval]
1428-
+ #step: (_|_){
1429-
+ // [eval] issue3694.simple.#step: invalid value {uses?:string} (does not satisfy matchN): 0 matched, expected 1:
1430-
// ./issue3694.cue:19:9
1431-
// ./issue3694.cue:19:16
1432-
// ./issue3694.cue:22:9
1376+
}
1377+
}
1378+
simple: (struct){
14331379
-- diff/explanation --
14341380
The old evaluator does not correctly handle ToDataAll if a node is
14351381
mid-evaluation. The new evaluator does.

internal/core/adt/composite.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,14 @@ func (v *Vertex) ToDataAll(ctx *OpContext) *Vertex {
812812
w.Arcs = arcs
813813
w.isData = true
814814
w.Conjuncts = slices.Clone(v.Conjuncts)
815+
816+
// Converting to dat drops constraints and non-regular fields. This means
817+
// that the domain on which they are defined is reduced, which will change
818+
// closedness properties. We therefore remove closedness. Note that data,
819+
// in general and JSON specifically, is not closed.
820+
w.ClosedRecursive = false
821+
w.ClosedNonRecursive = false
822+
815823
// TODO(perf): this is not strictly necessary for evaluation, but it can
816824
// hurt performance greatly. Drawback is that it may disable ordering.
817825
for _, s := range w.Structs {

0 commit comments

Comments
 (0)