Skip to content

Commit 9a44314

Browse files
committed
internal/core/adt: allow sharing of lets
In cuelang.org/cl/1211742 we disabled sharing for non-rooted values. This fixed some bugs related to this. Unfortunately, it also exposed some bugs with let values that otherwise were not exposed with sharing enabled. We partially enable sharing again to allow unblocking some users. This may not be the most ideal implementation, but at least it solves some issues immediately. One result was that the debug printer would print shared let values of "multi-lets". This meant the value did not reflect the let defined at the original position. We now detect this and will print the value verbatim, instead of the reference. The different locations in the error messages for issue 3801 are related to the nodes now being shared. This is not necessarily bad, although perhaps not ideal. This would be a big change to do correctly, though. Fixes #3938 Issue #3801 Signed-off-by: Marcel van Lohuizen <[email protected]> Change-Id: Ie90fe457feb2552d69ad63e8788752bb9b070110 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1215601 Reviewed-by: Daniel Martí <[email protected]> TryBot-Result: CUEcueckoo <[email protected]> Unity-Result: CUE porcuepine <[email protected]>
1 parent 3045a88 commit 9a44314

File tree

9 files changed

+109
-94
lines changed

9 files changed

+109
-94
lines changed

cue/testdata/benchmarks/issue2176.txtar

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ Allocs: 449
6565
Retain: 0
6666

6767
Unifications: 377
68-
Conjuncts: 1527
68+
Conjuncts: 1333
6969
Disjuncts: 8
7070

7171
CloseIDElems: 134
72-
NumCloseIDs: 731
72+
NumCloseIDs: 537
7373
-- diff/-out/evalalpha/stats<==>+out/eval/stats --
7474
diff old new
7575
--- old
@@ -91,11 +91,11 @@ diff old new
9191
+Retain: 0
9292
+
9393
+Unifications: 377
94-
+Conjuncts: 1527
94+
+Conjuncts: 1333
9595
+Disjuncts: 8
9696
+
9797
+CloseIDElems: 134
98-
+NumCloseIDs: 731
98+
+NumCloseIDs: 537
9999
-- out/eval/stats --
100100
Leaks: 90
101101
Freed: 746

cue/testdata/definitions/typocheck.txtar

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -448,18 +448,18 @@ full: {
448448
out: (#Main & {namespace: "ns1"}).output
449449
}
450450
-- out/evalalpha/stats --
451-
Leaks: 739
451+
Leaks: 738
452452
Freed: 0
453453
Reused: 0
454-
Allocs: 739
454+
Allocs: 738
455455
Retain: 0
456456

457-
Unifications: 611
458-
Conjuncts: 1199
457+
Unifications: 615
458+
Conjuncts: 1193
459459
Disjuncts: 45
460460

461-
CloseIDElems: 1839
462-
NumCloseIDs: 395
461+
CloseIDElems: 1859
462+
NumCloseIDs: 386
463463
-- diff/-out/evalalpha/stats<==>+out/eval/stats --
464464
diff old new
465465
--- old
@@ -474,18 +474,18 @@ diff old new
474474
-Unifications: 918
475475
-Conjuncts: 1892
476476
-Disjuncts: 1189
477-
+Leaks: 739
477+
+Leaks: 738
478478
+Freed: 0
479479
+Reused: 0
480-
+Allocs: 739
480+
+Allocs: 738
481481
+Retain: 0
482482
+
483-
+Unifications: 611
484-
+Conjuncts: 1199
483+
+Unifications: 615
484+
+Conjuncts: 1193
485485
+Disjuncts: 45
486486
+
487-
+CloseIDElems: 1839
488-
+NumCloseIDs: 395
487+
+CloseIDElems: 1859
488+
+NumCloseIDs: 386
489489
-- out/eval/stats --
490490
Leaks: 115
491491
Freed: 879
@@ -1351,7 +1351,7 @@ Result:
13511351
op: (string){ "add" }
13521352
path: (string){ "/metadata" }
13531353
value: (_|_){
1354-
// [incomplete] full.#Resource.patches.0.value: invalid interpolation: non-concrete value string (type string):
1354+
// [incomplete] full.#Resource.pickMsg.msg: invalid interpolation: non-concrete value string (type string):
13551355
// ./large.cue:7:25
13561356
// ./large.cue:3:12
13571357
}
@@ -1380,7 +1380,7 @@ Result:
13801380
#Main: (#struct){
13811381
namespace: (string){ string }
13821382
output: (_|_){
1383-
// [incomplete] full.#Main.output: key value of dynamic field must be concrete, found string:
1383+
// [incomplete] full.#Main.jsonPatch.output: key value of dynamic field must be concrete, found string:
13841384
// ./large.cue:21:24
13851385
// ./large.cue:19:15
13861386
}
@@ -1403,7 +1403,7 @@ Result:
14031403
op: (string){ "add" }
14041404
path: (string){ "/metadata" }
14051405
value: (_|_){
1406-
// [incomplete] full.#Main.jsonPatch.base.patches.0.value: invalid interpolation: non-concrete value string (type string):
1406+
// [incomplete] full.#Main.jsonPatch.base.pickMsg.msg: invalid interpolation: non-concrete value string (type string):
14071407
// ./large.cue:7:25
14081408
// ./large.cue:3:12
14091409
}
@@ -2159,12 +2159,21 @@ diff old new
21592159
}
21602160
#Foo: (#struct){
21612161
foo?: ((null|struct)){ |(*(#struct){
2162+
@@ -983,7 +852,7 @@
2163+
op: (string){ "add" }
2164+
path: (string){ "/metadata" }
2165+
value: (_|_){
2166+
- // [incomplete] full.#Resource.patches.0.value: invalid interpolation: non-concrete value string (type string):
2167+
+ // [incomplete] full.#Resource.pickMsg.msg: invalid interpolation: non-concrete value string (type string):
2168+
// ./large.cue:7:25
2169+
// ./large.cue:3:12
2170+
}
21622171
@@ -1012,38 +881,11 @@
21632172
#Main: (#struct){
21642173
namespace: (string){ string }
21652174
output: (_|_){
21662175
- // [incomplete] full.#Main.output: invalid non-ground value string (must be concrete string):
2167-
+ // [incomplete] full.#Main.output: key value of dynamic field must be concrete, found string:
2176+
+ // [incomplete] full.#Main.jsonPatch.output: key value of dynamic field must be concrete, found string:
21682177
+ // ./large.cue:21:24
21692178
// ./large.cue:19:15
21702179
- // ./large.cue:41:15
@@ -2200,6 +2209,15 @@ diff old new
22002209
let base#6 = (#struct){
22012210
someMsg: (string){ string }
22022211
obs: (#struct){ |(*(#struct){
2212+
@@ -1062,7 +904,7 @@
2213+
op: (string){ "add" }
2214+
path: (string){ "/metadata" }
2215+
value: (_|_){
2216+
- // [incomplete] full.#Main.jsonPatch.base.patches.0.value: invalid interpolation: non-concrete value string (type string):
2217+
+ // [incomplete] full.#Main.jsonPatch.base.pickMsg.msg: invalid interpolation: non-concrete value string (type string):
2218+
// ./large.cue:7:25
2219+
// ./large.cue:3:12
2220+
}
22032221
@@ -1086,6 +928,19 @@
22042222
}
22052223
}

cue/testdata/eval/bulk.txtar

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -140,18 +140,18 @@ issue3638: compare: {
140140
#x: { a: int } | *{ b: 2 }
141141
}
142142
-- out/evalalpha/stats --
143-
Leaks: 332
143+
Leaks: 302
144144
Freed: 0
145145
Reused: 0
146-
Allocs: 332
146+
Allocs: 302
147147
Retain: 0
148148

149-
Unifications: 248
150-
Conjuncts: 487
151-
Disjuncts: 63
149+
Unifications: 229
150+
Conjuncts: 453
151+
Disjuncts: 53
152152

153-
CloseIDElems: 1023
154-
NumCloseIDs: 130
153+
CloseIDElems: 121
154+
NumCloseIDs: 125
155155
-- diff/-out/evalalpha/stats<==>+out/eval/stats --
156156
diff old new
157157
--- old
@@ -166,18 +166,18 @@ diff old new
166166
-Unifications: 214
167167
-Conjuncts: 639
168168
-Disjuncts: 297
169-
+Leaks: 332
169+
+Leaks: 302
170170
+Freed: 0
171171
+Reused: 0
172-
+Allocs: 332
172+
+Allocs: 302
173173
+Retain: 0
174174
+
175-
+Unifications: 248
176-
+Conjuncts: 487
177-
+Disjuncts: 63
175+
+Unifications: 229
176+
+Conjuncts: 453
177+
+Disjuncts: 53
178178
+
179-
+CloseIDElems: 1023
180-
+NumCloseIDs: 130
179+
+CloseIDElems: 121
180+
+NumCloseIDs: 125
181181
-- out/eval/stats --
182182
Leaks: 4
183183
Freed: 269

cue/testdata/eval/issue3801.txtar

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,18 @@ issue3801: nonRooted: full: {
9797
}
9898
}
9999
-- out/evalalpha/stats --
100-
Leaks: 269
100+
Leaks: 266
101101
Freed: 0
102102
Reused: 0
103-
Allocs: 269
103+
Allocs: 266
104104
Retain: 0
105105

106-
Unifications: 178
107-
Conjuncts: 355
106+
Unifications: 181
107+
Conjuncts: 346
108108
Disjuncts: 16
109109

110-
CloseIDElems: 130
111-
NumCloseIDs: 94
110+
CloseIDElems: 151
111+
NumCloseIDs: 83
112112
-- diff/-out/evalalpha/stats<==>+out/eval/stats --
113113
diff old new
114114
--- old
@@ -123,18 +123,18 @@ diff old new
123123
-Unifications: 599
124124
-Conjuncts: 1319
125125
-Disjuncts: 762
126-
+Leaks: 269
126+
+Leaks: 266
127127
+Freed: 0
128128
+Reused: 0
129-
+Allocs: 269
129+
+Allocs: 266
130130
+Retain: 0
131131
+
132-
+Unifications: 178
133-
+Conjuncts: 355
132+
+Unifications: 181
133+
+Conjuncts: 346
134134
+Disjuncts: 16
135135
+
136-
+CloseIDElems: 130
137-
+NumCloseIDs: 94
136+
+CloseIDElems: 151
137+
+NumCloseIDs: 83
138138
-- out/eval/stats --
139139
Leaks: 237
140140
Freed: 408
@@ -191,7 +191,7 @@ Disjuncts: 762
191191
op: (string){ "add" }
192192
path: (string){ "/metadata" }
193193
value: (_|_){
194-
// [incomplete] issue3801.let.full.#Resource.patches.0.value: invalid interpolation: non-concrete value string (type string):
194+
// [incomplete] issue3801.let.full.#Resource.pickMsg.msg: invalid interpolation: non-concrete value string (type string):
195195
// ./nested.cue:29:25
196196
// ./nested.cue:25:12
197197
}
@@ -220,7 +220,7 @@ Disjuncts: 762
220220
#Main: (#struct){
221221
namespace: (string){ string }
222222
output: (_|_){
223-
// [incomplete] issue3801.let.full.#Main.output: key value of dynamic field must be concrete, found string:
223+
// [incomplete] issue3801.let.full.#Main.jsonPatch.output: key value of dynamic field must be concrete, found string:
224224
// ./nested.cue:43:24
225225
// ./nested.cue:41:15
226226
}
@@ -243,7 +243,7 @@ Disjuncts: 762
243243
op: (string){ "add" }
244244
path: (string){ "/metadata" }
245245
value: (_|_){
246-
// [incomplete] issue3801.let.full.#Main.jsonPatch.base.patches.0.value: invalid interpolation: non-concrete value string (type string):
246+
// [incomplete] issue3801.let.full.#Main.jsonPatch.base.pickMsg.msg: invalid interpolation: non-concrete value string (type string):
247247
// ./nested.cue:29:25
248248
// ./nested.cue:25:12
249249
}
@@ -355,12 +355,21 @@ Disjuncts: 762
355355
diff old new
356356
--- old
357357
+++ new
358+
@@ -43,7 +43,7 @@
359+
op: (string){ "add" }
360+
path: (string){ "/metadata" }
361+
value: (_|_){
362+
- // [incomplete] issue3801.let.full.#Resource.patches.0.value: invalid interpolation: non-concrete value string (type string):
363+
+ // [incomplete] issue3801.let.full.#Resource.pickMsg.msg: invalid interpolation: non-concrete value string (type string):
364+
// ./nested.cue:29:25
365+
// ./nested.cue:25:12
366+
}
358367
@@ -72,38 +72,11 @@
359368
#Main: (#struct){
360369
namespace: (string){ string }
361370
output: (_|_){
362371
- // [incomplete] issue3801.let.full.#Main.output: invalid non-ground value string (must be concrete string):
363-
+ // [incomplete] issue3801.let.full.#Main.output: key value of dynamic field must be concrete, found string:
372+
+ // [incomplete] issue3801.let.full.#Main.jsonPatch.output: key value of dynamic field must be concrete, found string:
364373
+ // ./nested.cue:43:24
365374
// ./nested.cue:41:15
366375
- // ./nested.cue:63:15
@@ -396,6 +405,15 @@ diff old new
396405
let base#8 = (#struct){
397406
someMsg: (string){ string }
398407
obs: (#struct){ |(*(#struct){
408+
@@ -122,7 +95,7 @@
409+
op: (string){ "add" }
410+
path: (string){ "/metadata" }
411+
value: (_|_){
412+
- // [incomplete] issue3801.let.full.#Main.jsonPatch.base.patches.0.value: invalid interpolation: non-concrete value string (type string):
413+
+ // [incomplete] issue3801.let.full.#Main.jsonPatch.base.pickMsg.msg: invalid interpolation: non-concrete value string (type string):
414+
// ./nested.cue:29:25
415+
// ./nested.cue:25:12
416+
}
399417
@@ -146,6 +119,19 @@
400418
}
401419
}

cue/testdata/eval/letjoin.txtar

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,12 @@ Reused: 0
138138
Allocs: 212
139139
Retain: 0
140140

141-
Unifications: 138
142-
Conjuncts: 359
141+
Unifications: 139
142+
Conjuncts: 353
143143
Disjuncts: 36
144144

145145
CloseIDElems: 14
146-
NumCloseIDs: 93
146+
NumCloseIDs: 86
147147
-- diff/-out/evalalpha/stats<==>+out/eval/stats --
148148
diff old new
149149
--- old
@@ -164,12 +164,12 @@ diff old new
164164
+Allocs: 212
165165
+Retain: 0
166166
+
167-
+Unifications: 138
168-
+Conjuncts: 359
167+
+Unifications: 139
168+
+Conjuncts: 353
169169
+Disjuncts: 36
170170
+
171171
+CloseIDElems: 14
172-
+NumCloseIDs: 93
172+
+NumCloseIDs: 86
173173
-- out/eval/stats --
174174
Leaks: 28
175175
Freed: 215

0 commit comments

Comments
 (0)