Skip to content

Commit c7a0369

Browse files
committed
internal/core/adt: add indirection in some cases
When a previously registered node is involved in an embedding, we always allocate a new node and add the original node to the set. Not doing so will means that an embedding group will not be marked as excluded. This was worked around with a hack in injectEmbedNode. This has been removed. This fixes exposed some issues in the API that are addressed here as well to prevent breakages. We need to ensure that embeddings do not open across conjuncts passed to Unify. This mechanism makes the TopRef mechanism redundant and this has been removed as part of this change. Fixes #3839 Fixes #3826 Signed-off-by: Marcel van Lohuizen <[email protected]> Change-Id: If2b7ba647e2b7d0e99f906b08a7e76d3d2d7ba43 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1212144 Reviewed-by: Matthew Sackman <[email protected]> TryBot-Result: CUEcueckoo <[email protected]>
1 parent 4810870 commit c7a0369

File tree

8 files changed

+216
-310
lines changed

8 files changed

+216
-310
lines changed

cue/testdata/definitions/fields.txtar

+88-153
Large diffs are not rendered by default.

cue/testdata/definitions/typocheck.txtar

+37-121
Original file line numberDiff line numberDiff line change
@@ -342,12 +342,6 @@ embed.simple.a.err: field not allowed:
342342
./in.cue:4:5
343343
embed.withIndirect.err: field not allowed:
344344
./in.cue:71:8
345-
issue3839.full.out.ingress.bar: field not allowed:
346-
./issue3839.cue:27:4
347-
issue3839.full.out.ingress.foo: field not allowed:
348-
./issue3839.cue:26:4
349-
issue3839.reduced.x.y: field not allowed:
350-
./issue3839.cue:3:5
351345
embed.openValidator.t2.a.b: invalid value 1 (does not satisfy matchN): 0 matched, expected 1:
352346
./validators.cue:21:5
353347
./validators.cue:21:12
@@ -735,24 +729,17 @@ Result:
735729
}
736730
}
737731
}
738-
issue3839: (_|_){
739-
// [eval]
740-
reduced: (_|_){
741-
// [eval]
742-
x: (_|_){
743-
// [eval]
744-
y: (_|_){
745-
// [eval] issue3839.reduced.x.y: field not allowed:
746-
// ./issue3839.cue:3:5
747-
}
732+
issue3839: (struct){
733+
reduced: (struct){
734+
x: (#struct){
735+
y: (int){ 1 }
748736
}
749737
#B: (#struct){
750738
}
751739
A: (#struct){
752740
}
753741
}
754-
full: (_|_){
755-
// [eval]
742+
full: (struct){
756743
_globals: (struct){
757744
glb: (struct){
758745
globalField: (string){ "" }
@@ -765,21 +752,13 @@ Result:
765752
glb: ~(issue3839.full.#GlobalContext)
766753
out: ~(issue3839.full.#GlobalContext)
767754
}
768-
out: (_|_){
769-
// [eval]
770-
ingress: (_|_){
771-
// [eval]
755+
out: (struct){
756+
ingress: (#struct){
772757
#def: (#struct){
773758
globalField: (string){ "" }
774759
}
775-
foo: (_|_){
776-
// [eval] issue3839.full.out.ingress.foo: field not allowed:
777-
// ./issue3839.cue:26:4
778-
}
779-
bar: (_|_){
780-
// [eval] issue3839.full.out.ingress.bar: field not allowed:
781-
// ./issue3839.cue:27:4
782-
}
760+
foo: (int){ 1234 }
761+
bar: (string){ "http" }
783762
}
784763
}
785764
#Embed: (#struct){
@@ -1010,7 +989,7 @@ Result:
1010989
diff old new
1011990
--- old
1012991
+++ new
1013-
@@ -1,81 +1,35 @@
992+
@@ -1,81 +1,29 @@
1014993
Errors:
1015994
and.transitive.out.ok: field not allowed:
1016995
- ./in.cue:34:5
@@ -1089,16 +1068,10 @@ diff old new
10891068
- ./validators.cue:12:6
10901069
- ./validators.cue:17:5
10911070
- ./validators.cue:18:5
1092-
+issue3839.full.out.ingress.bar: field not allowed:
1093-
+ ./issue3839.cue:27:4
1094-
+issue3839.full.out.ingress.foo: field not allowed:
1095-
+ ./issue3839.cue:26:4
1096-
+issue3839.reduced.x.y: field not allowed:
1097-
+ ./issue3839.cue:3:5
10981071
embed.openValidator.t2.a.b: invalid value 1 (does not satisfy matchN): 0 matched, expected 1:
10991072
./validators.cue:21:5
11001073
./validators.cue:21:12
1101-
@@ -94,14 +48,11 @@
1074+
@@ -94,14 +42,11 @@
11021075
}
11031076
a: (_|_){
11041077
// [eval]
@@ -1114,7 +1087,7 @@ diff old new
11141087
}
11151088
}
11161089
andInStruct: (_|_){
1117-
@@ -111,14 +62,11 @@
1090+
@@ -111,14 +56,11 @@
11181091
}
11191092
a: (_|_){
11201093
// [eval]
@@ -1130,7 +1103,7 @@ diff old new
11301103
}
11311104
}
11321105
embedDefWithEmbedding: (_|_){
1133-
@@ -128,15 +76,11 @@
1106+
@@ -128,15 +70,11 @@
11341107
}
11351108
a: (_|_){
11361109
// [eval]
@@ -1147,7 +1120,7 @@ diff old new
11471120
}
11481121
}
11491122
embedComprehension: (_|_){
1150-
@@ -146,16 +90,11 @@
1123+
@@ -146,16 +84,11 @@
11511124
}
11521125
a: (_|_){
11531126
// [eval]
@@ -1165,7 +1138,7 @@ diff old new
11651138
}
11661139
}
11671140
fieldWithAnd: (_|_){
1168-
@@ -166,9 +105,6 @@
1141+
@@ -166,9 +99,6 @@
11691142
// [eval]
11701143
err: (_|_){
11711144
// [eval] embed.fieldWithAnd.a.err: field not allowed:
@@ -1175,7 +1148,7 @@ diff old new
11751148
// ./in.cue:20:13
11761149
}
11771150
}
1178-
@@ -179,20 +115,15 @@
1151+
@@ -179,20 +109,15 @@
11791152
a: (int){ int }
11801153
}
11811154
B: (struct){
@@ -1201,7 +1174,7 @@ diff old new
12011174
}
12021175
}
12031176
andEmbed: (_|_){
1204-
@@ -208,17 +139,11 @@
1177+
@@ -208,17 +133,11 @@
12051178
}
12061179
d: (_|_){
12071180
// [eval]
@@ -1220,7 +1193,7 @@ diff old new
12201193
}
12211194
}
12221195
nonDef: (struct){
1223-
@@ -227,12 +152,12 @@
1196+
@@ -227,12 +146,12 @@
12241197
a: (string){ string }
12251198
}
12261199
#Y: (#struct){
@@ -1237,7 +1210,7 @@ diff old new
12371210
}
12381211
}
12391212
}
1240-
@@ -242,12 +167,12 @@
1213+
@@ -242,12 +161,12 @@
12411214
Name: (string){ string }
12421215
}
12431216
#Step: (#struct){
@@ -1254,7 +1227,7 @@ diff old new
12541227
}
12551228
out: (#struct){
12561229
Name: (string){ "foo" }
1257-
@@ -257,21 +182,15 @@
1230+
@@ -257,21 +176,15 @@
12581231
}
12591232
withIndirect: (_|_){
12601233
// [eval]
@@ -1281,7 +1254,7 @@ diff old new
12811254
}
12821255
normalValidator: (_|_){
12831256
// [eval]
1284-
@@ -281,20 +200,17 @@
1257+
@@ -281,20 +194,17 @@
12851258
}
12861259
x: (_|_){
12871260
// [eval]
@@ -1305,7 +1278,7 @@ diff old new
13051278
#X: (_){
13061279
matchN(0, (#list){
13071280
})
1308-
@@ -301,17 +217,10 @@
1281+
@@ -301,17 +211,10 @@
13091282
a?: (int){ int }
13101283
b?: (int){ int }
13111284
}
@@ -1327,7 +1300,7 @@ diff old new
13271300
}
13281301
}
13291302
t2: (_|_){
1330-
@@ -330,10 +239,7 @@
1303+
@@ -330,10 +233,7 @@
13311304
// [eval]
13321305
b: (_|_){
13331306
// [eval] embed.openValidator.t2.a.b: conflicting values 1 and {b?:Y} (mismatched types int and struct):
@@ -1338,7 +1311,7 @@ diff old new
13381311
// ./validators.cue:24:8
13391312
// embed.openValidator.t2.a.b: invalid value 1 (does not satisfy matchN): 0 matched, expected 1:
13401313
// ./validators.cue:21:5
1341-
@@ -360,16 +266,11 @@
1314+
@@ -360,16 +260,11 @@
13421315
}
13431316
out: (_|_){
13441317
// [eval]
@@ -1356,7 +1329,7 @@ diff old new
13561329
}
13571330
}
13581331
transitiveWithEmbed: (_|_){
1359-
@@ -385,17 +286,11 @@
1332+
@@ -385,17 +280,11 @@
13601333
}
13611334
out: (_|_){
13621335
// [eval]
@@ -1375,7 +1348,7 @@ diff old new
13751348
}
13761349
}
13771350
}
1378-
@@ -414,8 +309,8 @@
1351+
@@ -414,8 +303,8 @@
13791352
// ./issue3832.cue:8:16
13801353
}
13811354
outFirstName: (_|_){
@@ -1386,7 +1359,7 @@ diff old new
13861359
}
13871360
}
13881361
}
1389-
@@ -425,35 +320,27 @@
1362+
@@ -425,35 +314,27 @@
13901363
}, (#struct){
13911364
pass: (#struct){
13921365
let self#1 = (_|_){
@@ -1432,7 +1405,7 @@ diff old new
14321405
pass: (#struct){
14331406
let self#1 = (#struct){
14341407
firstName: (string){ "Sam" }
1435-
@@ -460,18 +347,21 @@
1408+
@@ -460,18 +341,21 @@
14361409
}
14371410
outFirstName: (string){ "Sam" }
14381411
}
@@ -1466,43 +1439,7 @@ diff old new
14661439
}
14671440
issue3833: (struct){
14681441
out: (#struct){
1469-
@@ -527,17 +417,24 @@
1470-
}
1471-
}
1472-
}
1473-
- issue3839: (struct){
1474-
- reduced: (struct){
1475-
- x: (#struct){
1476-
- y: (int){ 1 }
1477-
- }
1478-
- #B: (#struct){
1479-
- }
1480-
- A: (#struct){
1481-
- }
1482-
- }
1483-
- full: (struct){
1484-
+ issue3839: (_|_){
1485-
+ // [eval]
1486-
+ reduced: (_|_){
1487-
+ // [eval]
1488-
+ x: (_|_){
1489-
+ // [eval]
1490-
+ y: (_|_){
1491-
+ // [eval] issue3839.reduced.x.y: field not allowed:
1492-
+ // ./issue3839.cue:3:5
1493-
+ }
1494-
+ }
1495-
+ #B: (#struct){
1496-
+ }
1497-
+ A: (#struct){
1498-
+ }
1499-
+ }
1500-
+ full: (_|_){
1501-
+ // [eval]
1502-
_globals: (struct){
1503-
glb: (struct){
1504-
globalField: (string){ "" }
1505-
@@ -547,20 +444,24 @@
1442+
@@ -547,12 +431,8 @@
15061443
globalField: (string){ string }
15071444
}
15081445
#Context: (#struct){
@@ -1512,33 +1449,12 @@ diff old new
15121449
- out: (#struct){
15131450
- globalField: (string){ string }
15141451
- }
1515-
- }
1516-
- out: (struct){
1517-
- ingress: (#struct){
15181452
+ glb: ~(issue3839.full.#GlobalContext)
15191453
+ out: ~(issue3839.full.#GlobalContext)
1520-
+ }
1521-
+ out: (_|_){
1522-
+ // [eval]
1523-
+ ingress: (_|_){
1524-
+ // [eval]
1525-
#def: (#struct){
1526-
globalField: (string){ "" }
1527-
}
1528-
- foo: (int){ 1234 }
1529-
- bar: (string){ "http" }
1530-
+ foo: (_|_){
1531-
+ // [eval] issue3839.full.out.ingress.foo: field not allowed:
1532-
+ // ./issue3839.cue:26:4
1533-
+ }
1534-
+ bar: (_|_){
1535-
+ // [eval] issue3839.full.out.ingress.bar: field not allowed:
1536-
+ // ./issue3839.cue:27:4
1537-
+ }
1538-
}
15391454
}
1540-
#Embed: (#struct){
1541-
@@ -580,22 +481,22 @@
1455+
out: (struct){
1456+
ingress: (#struct){
1457+
@@ -580,22 +460,22 @@
15421458
#Z: (#struct){
15431459
}
15441460
x: (#struct){
@@ -1577,7 +1493,7 @@ diff old new
15771493
z: (int){ 1 }
15781494
}
15791495
}
1580-
@@ -605,22 +506,22 @@
1496+
@@ -605,22 +485,22 @@
15811497
#Z: (#struct){
15821498
}
15831499
x: (#struct){
@@ -1616,7 +1532,7 @@ diff old new
16161532
z: (int){ 1 }
16171533
}
16181534
}
1619-
@@ -675,38 +576,11 @@
1535+
@@ -675,38 +555,11 @@
16201536
#Main: (#struct){
16211537
namespace: (string){ string }
16221538
output: (_|_){
@@ -1657,7 +1573,7 @@ diff old new
16571573
let base#6 = (#struct){
16581574
someMsg: (string){ string }
16591575
obs: (#struct){ |(*(#struct){
1660-
@@ -749,6 +623,19 @@
1576+
@@ -749,6 +602,19 @@
16611577
}
16621578
}
16631579
}
@@ -1677,7 +1593,7 @@ diff old new
16771593
}
16781594
}
16791595
out: (#struct){
1680-
@@ -768,7 +655,9 @@
1596+
@@ -768,7 +634,9 @@
16811597
}
16821598
out: (#struct){
16831599
b1: (_|_){
@@ -1688,7 +1604,7 @@ diff old new
16881604
// disjunction.withErr.t1.out.b1: conflicting values null and {b2:{b3:params.mayExistLater}} (mismatched types null and struct):
16891605
// ./validators.cue:29:7
16901606
// ./validators.cue:31:17
1691-
@@ -778,17 +667,8 @@
1607+
@@ -778,17 +646,8 @@
16921608
// ./validators.cue:32:17
16931609
// disjunction.withErr.t1.out.b1.b2.b3: undefined field: mayExistLater:
16941610
// ./validators.cue:29:22

0 commit comments

Comments
 (0)