Skip to content

Commit 2702426

Browse files
committedDec 23, 2024·
internal/core/adt: fix let issue for eval v2
This only fixes the issue for V2: for v3 this causes too many issues and another solution has to be found. Note that of the tests only letjoin.txtar has material changes. The changes in let.txtar reflect the behavior in V2 from before the regression. All other test changes are counter changes. See the original regression: https://cuelang.org/cl/1199752 Issue #3590 Issue #3591 Signed-off-by: Marcel van Lohuizen <[email protected]> Change-Id: I9ff6496c37dbf21ca58861ee2906d82beaa82e62 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1206279 TryBot-Result: CUEcueckoo <[email protected]> Unity-Result: CUE porcuepine <[email protected]> Reviewed-by: Daniel Martí <[email protected]>
1 parent 06f41bc commit 2702426

File tree

15 files changed

+159
-170
lines changed

15 files changed

+159
-170
lines changed
 

‎cue/testdata/benchmarks/cycleshare.txtar

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ diff old new
4444
-Freed: 965
4545
-Reused: 951
4646
-Allocs: 22
47-
-Retain: 15
47+
-Retain: 17
4848
+Leaks: 64
4949
+Freed: 0
5050
+Reused: 0
@@ -62,7 +62,7 @@ Leaks: 8
6262
Freed: 965
6363
Reused: 951
6464
Allocs: 22
65-
Retain: 15
65+
Retain: 17
6666

6767
Unifications: 559
6868
Conjuncts: 1046

‎cue/testdata/benchmarks/issue2176.txtar

+4-4
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ output: {
6161
-- out/eval/stats --
6262
Leaks: 90
6363
Freed: 4079
64-
Reused: 4072
65-
Allocs: 97
66-
Retain: 1364
64+
Reused: 4074
65+
Allocs: 95
66+
Retain: 1359
6767

6868
Unifications: 4161
6969
Conjuncts: 9489
70-
Disjuncts: 4809
70+
Disjuncts: 4804
7171
-- out/evalalpha --
7272
(struct){
7373
#Datastream: (#struct){

‎cue/testdata/compile/scope.txtar

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ Leaks: 2
8282
Freed: 48
8383
Reused: 45
8484
Allocs: 5
85-
Retain: 7
85+
Retain: 8
8686

8787
Unifications: 50
8888
Conjuncts: 102

‎cue/testdata/comprehensions/checkdefined.txtar

+6-6
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,14 @@ structs: {
8282

8383
-- out/eval/stats --
8484
Leaks: 11
85-
Freed: 87
86-
Reused: 83
85+
Freed: 89
86+
Reused: 85
8787
Allocs: 15
88-
Retain: 20
88+
Retain: 26
8989

90-
Unifications: 98
91-
Conjuncts: 131
92-
Disjuncts: 102
90+
Unifications: 100
91+
Conjuncts: 134
92+
Disjuncts: 105
9393
-- out/eval --
9494
(struct){
9595
xc: (#struct){

‎cue/testdata/comprehensions/issue2481.txtar

+4-4
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ full: {
7373
-- out/eval/stats --
7474
Leaks: 3
7575
Freed: 23
76-
Reused: 16
77-
Allocs: 10
78-
Retain: 61
76+
Reused: 17
77+
Allocs: 9
78+
Retain: 58
7979

8080
Unifications: 26
8181
Conjuncts: 50
82-
Disjuncts: 59
82+
Disjuncts: 56
8383
-- out/eval --
8484
Errors:
8585
out: cannot combine regular field "val" with "b":

‎cue/testdata/comprehensions/pushdown.txtar

+1-1
Original file line numberDiff line numberDiff line change
@@ -1894,7 +1894,7 @@ Leaks: 17
18941894
Freed: 443
18951895
Reused: 437
18961896
Allocs: 23
1897-
Retain: 104
1897+
Retain: 103
18981898

18991899
Unifications: 444
19001900
Conjuncts: 721

‎cue/testdata/cycle/evaluate.txtar

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ Leaks: 48
120120
Freed: 127
121121
Reused: 120
122122
Allocs: 55
123-
Retain: 136
123+
Retain: 138
124124

125125
Unifications: 163
126126
Conjuncts: 299

‎cue/testdata/cycle/issue990.txtar

+12-12
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,9 @@ diff old new
253253
--- old
254254
+++ new
255255
@@ -1,9 +1,9 @@
256-
-Leaks: 7
257-
-Freed: 3218
258-
-Reused: 3200
256+
-Leaks: 6
257+
-Freed: 3232
258+
-Reused: 3213
259259
-Allocs: 25
260260
-Retain: 26
261261
+Leaks: 605
@@ -264,9 +264,9 @@ diff old new
264264
+Allocs: 605
265265
+Retain: 0
266266

267-
-Unifications: 2577
268-
-Conjuncts: 12017
269-
-Disjuncts: 3244
267+
-Unifications: 2588
268+
-Conjuncts: 12056
269+
-Disjuncts: 3258
270270
+Unifications: 175
271271
+Conjuncts: 2668
272272
+Disjuncts: 92
@@ -617,15 +617,15 @@ diff old new
617617
}
618618
}
619619
-- out/eval/stats --
620-
Leaks: 7
621-
Freed: 3218
622-
Reused: 3200
620+
Leaks: 6
621+
Freed: 3232
622+
Reused: 3213
623623
Allocs: 25
624624
Retain: 26
625625

626-
Unifications: 2577
627-
Conjuncts: 12017
628-
Disjuncts: 3244
626+
Unifications: 2588
627+
Conjuncts: 12056
628+
Disjuncts: 3258
629629
-- out/eval --
630630
(struct){
631631
#AC: (#struct){

‎cue/testdata/cycle/structural.txtar

+1-1
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ Leaks: 15
602602
Freed: 835
603603
Reused: 823
604604
Allocs: 27
605-
Retain: 65
605+
Retain: 66
606606

607607
Unifications: 664
608608
Conjuncts: 1289

‎cue/testdata/eval/issue2235.txtar

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,11 @@ Leaks: 3
104104
Freed: 101
105105
Reused: 84
106106
Allocs: 20
107-
Retain: 69
107+
Retain: 72
108108

109109
Unifications: 104
110110
Conjuncts: 271
111-
Disjuncts: 160
111+
Disjuncts: 161
112112
-- out/evalalpha --
113113
(struct){
114114
shorewallParams: (#struct){

‎cue/testdata/eval/let.txtar

+2-2
Original file line numberDiff line numberDiff line change
@@ -556,11 +556,11 @@ Leaks: 52
556556
Freed: 158
557557
Reused: 149
558558
Allocs: 61
559-
Retain: 151
559+
Retain: 184
560560

561561
Unifications: 196
562562
Conjuncts: 365
563-
Disjuncts: 242
563+
Disjuncts: 241
564564
-- out/eval --
565565
Errors:
566566
indirectReference.y: conflicting values 2 and 1:

‎cue/testdata/eval/letjoin.txtar

+102-116
Original file line numberDiff line numberDiff line change
@@ -146,33 +146,33 @@ diff old new
146146
--- old
147147
+++ new
148148
@@ -1,9 +1,9 @@
149-
-Leaks: 19
150-
-Freed: 202
151-
-Reused: 187
152-
-Allocs: 34
153-
-Retain: 141
149+
-Leaks: 24
150+
-Freed: 219
151+
-Reused: 207
152+
-Allocs: 36
153+
-Retain: 160
154154
+Leaks: 182
155155
+Freed: 18
156156
+Reused: 17
157157
+Allocs: 183
158158
+Retain: 0
159159

160-
-Unifications: 157
161-
-Conjuncts: 447
162-
-Disjuncts: 297
160+
-Unifications: 167
161+
-Conjuncts: 486
162+
-Disjuncts: 325
163163
+Unifications: 170
164164
+Conjuncts: 996
165165
+Disjuncts: 30
166166
-- out/eval/stats --
167-
Leaks: 19
168-
Freed: 202
169-
Reused: 187
170-
Allocs: 34
171-
Retain: 141
167+
Leaks: 24
168+
Freed: 219
169+
Reused: 207
170+
Allocs: 36
171+
Retain: 160
172172

173-
Unifications: 157
174-
Conjuncts: 447
175-
Disjuncts: 297
173+
Unifications: 167
174+
Conjuncts: 486
175+
Disjuncts: 325
176176
-- out/evalalpha --
177177
Errors:
178178
issue3590.full.result."conflicting-A".item: conflicting values "B" and "A":
@@ -398,32 +398,27 @@ Result:
398398
diff old new
399399
--- old
400400
+++ new
401-
@@ -1,19 +1,14 @@
402-
Errors:
403-
issue3590.full.result."conflicting-A".item: conflicting values "B" and "A":
404-
./issue3590.cue:33:6
405-
- ./issue3590.cue:41:2
406-
- ./issue3590.cue:42:14
407-
- ./issue3590.cue:43:14
408-
- ./issue3590.cue:46:12
409-
- ./issue3590.cue:49:33
401+
@@ -1,4 +1,18 @@
402+
-(struct){
403+
+Errors:
404+
+issue3590.full.result."conflicting-A".item: conflicting values "B" and "A":
405+
+ ./issue3590.cue:33:6
410406
+issue3590.full.result."conflicting-B".item: conflicting values "B" and "A":
411407
+ ./issue3590.cue:33:6
412-
issue3590.reduced.result."conflicting-A".item: conflicting values "B" and "A":
413-
./issue3590.cue:5:9
414-
./issue3590.cue:6:9
415-
- ./issue3590.cue:9:2
416-
- ./issue3590.cue:10:14
417-
- ./issue3590.cue:14:14
418-
- ./issue3590.cue:17:10
419-
- ./issue3590.cue:20:33
408+
+issue3590.reduced.result."conflicting-A".item: conflicting values "B" and "A":
409+
+ ./issue3590.cue:5:9
410+
+ ./issue3590.cue:6:9
420411
+issue3590.reduced.result."conflicting-B".item: conflicting values "B" and "A":
421412
+ ./issue3590.cue:5:9
422413
+ ./issue3590.cue:6:9
423-
424-
Result:
425-
(_|_){
426-
@@ -76,23 +71,19 @@
414+
+
415+
+Result:
416+
+(_|_){
417+
+ // [eval]
418+
t1: (struct){
419+
x: (struct){
420+
a: (int){ int }
421+
@@ -57,23 +71,19 @@
427422
}
428423
y: (struct){
429424
let X#2 = (struct){
@@ -460,19 +455,30 @@ diff old new
460455
c: (int){ 1 }
461456
}
462457
v: (int){ 1 }
463-
@@ -124,15 +115,15 @@
464-
// [eval] issue3590.reduced.result."conflicting-A".item: conflicting values "B" and "A":
465-
// ./issue3590.cue:5:9
466-
// ./issue3590.cue:6:9
467-
- // ./issue3590.cue:9:2
468-
- // ./issue3590.cue:10:14
469-
- // ./issue3590.cue:14:14
470-
- // ./issue3590.cue:17:10
471-
- // ./issue3590.cue:20:33
472-
- }
458+
@@ -93,14 +103,27 @@
459+
}
460+
}
461+
}
462+
- issue3590: (struct){
463+
- reduced: (struct){
464+
- result: (struct){
465+
- "conflicting-A": (struct){
466+
- item: (string){ "A" }
473467
- }
474468
- "conflicting-B": (struct){
475469
- item: (string){ "B" }
470+
+ issue3590: (_|_){
471+
+ // [eval]
472+
+ reduced: (_|_){
473+
+ // [eval]
474+
+ result: (_|_){
475+
+ // [eval]
476+
+ "conflicting-A": (_|_){
477+
+ // [eval]
478+
+ item: (_|_){
479+
+ // [eval] issue3590.reduced.result."conflicting-A".item: conflicting values "B" and "A":
480+
+ // ./issue3590.cue:5:9
481+
+ // ./issue3590.cue:6:9
476482
+ }
477483
+ }
478484
+ "conflicting-B": (_|_){
@@ -485,30 +491,40 @@ diff old new
485491
}
486492
}
487493
_input: (struct){
488-
@@ -151,10 +142,6 @@
494+
@@ -119,22 +142,28 @@
489495
// [eval] issue3590.reduced.Items.item: conflicting values "B" and "A":
490496
// ./issue3590.cue:5:9
491497
// ./issue3590.cue:6:9
492498
- // ./issue3590.cue:9:2
493499
- // ./issue3590.cue:10:14
494500
- // ./issue3590.cue:14:14
495501
- // ./issue3590.cue:17:10
496-
}
497-
}
498-
}
499-
@@ -169,15 +156,14 @@
500-
item: (_|_){
501-
// [eval] issue3590.full.result."conflicting-A".item: conflicting values "B" and "A":
502-
// ./issue3590.cue:33:6
503-
- // ./issue3590.cue:41:2
504-
- // ./issue3590.cue:42:14
505-
- // ./issue3590.cue:43:14
506-
- // ./issue3590.cue:46:12
507-
- // ./issue3590.cue:49:33
508-
- }
502+
- }
503+
- }
504+
- }
505+
- full: (struct){
506+
- #Result: (#struct){
507+
- }
508+
- result: (#struct){
509+
- "conflicting-A": (#struct){
510+
- item: (string){ "A" }
509511
- }
510512
- "conflicting-B": (#struct){
511513
- item: (string){ "B" }
514+
+ }
515+
+ }
516+
+ }
517+
+ full: (_|_){
518+
+ // [eval]
519+
+ #Result: (#struct){
520+
+ }
521+
+ result: (_|_){
522+
+ // [eval]
523+
+ "conflicting-A": (_|_){
524+
+ // [eval]
525+
+ item: (_|_){
526+
+ // [eval] issue3590.full.result."conflicting-A".item: conflicting values "B" and "A":
527+
+ // ./issue3590.cue:33:6
512528
+ }
513529
+ }
514530
+ "conflicting-B": (_|_){
@@ -520,7 +536,7 @@ diff old new
520536
}
521537
}
522538
#Input: (#struct){
523-
@@ -198,16 +184,14 @@
539+
@@ -155,24 +184,20 @@
524540
item: (_|_){
525541
// [eval] issue3590.full.Items.item: conflicting values "B" and "A":
526542
// ./issue3590.cue:33:6
@@ -540,7 +556,15 @@ diff old new
540556
#Result: (#struct){
541557
}
542558
result: (#struct){
543-
@@ -229,19 +213,7 @@
559+
"missing-items-A": (#struct){
560+
- item: (string){ "A" }
561+
}
562+
"missing-items-B": (#struct){
563+
- item: (string){ "B" }
564+
}
565+
}
566+
#Input: (#struct){
567+
@@ -188,19 +213,7 @@
544568
}
545569
let Var1#9multi = 〈1;v〉.p
546570
let Var2#Amulti = 〈0;let Var1#9〉
@@ -561,29 +585,13 @@ diff old new
561585
}
562586
}
563587
}
588+
-- diff/todo/p1 --
589+
issue3590: spurious conflicts
590+
issue3591: missing fields
564591
-- diff/todo/p4 --
565592
Reduce conjunct group size. Semantically correct, though.
566593
-- out/eval --
567-
Errors:
568-
issue3590.full.result."conflicting-A".item: conflicting values "B" and "A":
569-
./issue3590.cue:33:6
570-
./issue3590.cue:41:2
571-
./issue3590.cue:42:14
572-
./issue3590.cue:43:14
573-
./issue3590.cue:46:12
574-
./issue3590.cue:49:33
575-
issue3590.reduced.result."conflicting-A".item: conflicting values "B" and "A":
576-
./issue3590.cue:5:9
577-
./issue3590.cue:6:9
578-
./issue3590.cue:9:2
579-
./issue3590.cue:10:14
580-
./issue3590.cue:14:14
581-
./issue3590.cue:17:10
582-
./issue3590.cue:20:33
583-
584-
Result:
585-
(_|_){
586-
// [eval]
594+
(struct){
587595
t1: (struct){
588596
x: (struct){
589597
a: (int){ int }
@@ -678,24 +686,11 @@ Result:
678686
}
679687
}
680688
}
681-
issue3590: (_|_){
682-
// [eval]
683-
reduced: (_|_){
684-
// [eval]
685-
result: (_|_){
686-
// [eval]
687-
"conflicting-A": (_|_){
688-
// [eval]
689-
item: (_|_){
690-
// [eval] issue3590.reduced.result."conflicting-A".item: conflicting values "B" and "A":
691-
// ./issue3590.cue:5:9
692-
// ./issue3590.cue:6:9
693-
// ./issue3590.cue:9:2
694-
// ./issue3590.cue:10:14
695-
// ./issue3590.cue:14:14
696-
// ./issue3590.cue:17:10
697-
// ./issue3590.cue:20:33
698-
}
689+
issue3590: (struct){
690+
reduced: (struct){
691+
result: (struct){
692+
"conflicting-A": (struct){
693+
item: (string){ "A" }
699694
}
700695
"conflicting-B": (struct){
701696
item: (string){ "B" }
@@ -724,23 +719,12 @@ Result:
724719
}
725720
}
726721
}
727-
full: (_|_){
728-
// [eval]
722+
full: (struct){
729723
#Result: (#struct){
730724
}
731-
result: (_|_){
732-
// [eval]
733-
"conflicting-A": (_|_){
734-
// [eval]
735-
item: (_|_){
736-
// [eval] issue3590.full.result."conflicting-A".item: conflicting values "B" and "A":
737-
// ./issue3590.cue:33:6
738-
// ./issue3590.cue:41:2
739-
// ./issue3590.cue:42:14
740-
// ./issue3590.cue:43:14
741-
// ./issue3590.cue:46:12
742-
// ./issue3590.cue:49:33
743-
}
725+
result: (#struct){
726+
"conflicting-A": (#struct){
727+
item: (string){ "A" }
744728
}
745729
"conflicting-B": (#struct){
746730
item: (string){ "B" }
@@ -778,8 +762,10 @@ Result:
778762
}
779763
result: (#struct){
780764
"missing-items-A": (#struct){
765+
item: (string){ "A" }
781766
}
782767
"missing-items-B": (#struct){
768+
item: (string){ "B" }
783769
}
784770
}
785771
#Input: (#struct){

‎cue/testdata/export/issue2244.txtar

+5-5
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ m: #step & {
3232
if: _#isReleaseTag
3333
}
3434
-- out/eval/stats --
35-
Leaks: 24
36-
Freed: 14
37-
Reused: 10
38-
Allocs: 28
35+
Leaks: 16
36+
Freed: 17
37+
Reused: 13
38+
Allocs: 20
3939
Retain: 30
4040

4141
Unifications: 24
4242
Conjuncts: 58
43-
Disjuncts: 39
43+
Disjuncts: 40
4444
-- diff/explanation --
4545
New evaluator should ultimately disallow new definitions in closed structs
4646
and not allow #pattern in #step

‎cue/testdata/references/let.txtar

+13-13
Original file line numberDiff line numberDiff line change
@@ -285,15 +285,15 @@ issue1116: {
285285
}
286286
}
287287
-- out/eval/stats --
288-
Leaks: 2
289-
Freed: 114
288+
Leaks: 3
289+
Freed: 112
290290
Reused: 107
291-
Allocs: 9
292-
Retain: 14
291+
Allocs: 8
292+
Retain: 10
293293

294-
Unifications: 116
295-
Conjuncts: 166
296-
Disjuncts: 121
294+
Unifications: 115
295+
Conjuncts: 169
296+
Disjuncts: 117
297297
-- out/evalalpha --
298298
(struct){
299299
a1list: (#list){
@@ -569,9 +569,9 @@ diff old new
569569
}
570570
b: (string){
571571
"b"
572-
- let List#11 = (#list){
573-
- 0: (string){ "a" }
574-
- 1: (string){ "b" }
572+
- let List#11 = (_|_){
573+
- // [incomplete] issue1116.b.List: cycle error referencing #a:
574+
- // ./in.cue:96:14
575575
- }
576576
+ let List#11 = ~(issue1116.b.#a)
577577
#a: (#list){
@@ -753,9 +753,9 @@ diff old new
753753
}
754754
b: (string){
755755
"b"
756-
let List#11 = (#list){
757-
0: (string){ "a" }
758-
1: (string){ "b" }
756+
let List#11 = (_|_){
757+
// [incomplete] issue1116.b.List: cycle error referencing #a:
758+
// ./in.cue:96:14
759759
}
760760
#a: (#list){
761761
0: (string){ "a" }

‎internal/core/adt/expr.go

+3
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,9 @@ func (x *LetReference) resolve(ctx *OpContext, state combinedFlags) *Vertex {
948948

949949
// We should only partly finalize the result here as it is not safe to
950950
// finalize any references made by the let.
951+
if !ctx.isDevVersion() {
952+
arc.Finalize(ctx)
953+
}
951954
b := arc.Bottom()
952955
if !arc.MultiLet && b == nil {
953956
return arc

0 commit comments

Comments
 (0)
Please sign in to comment.