Skip to content

Commit a1a53e5

Browse files
committed
cue/errors: use slices.CompactFunc to deduplicate errors
Rather than our own implementation. Note that our implementation kept the last element of a run of repeats, while slices.CompactFunc keeps the first. This seems to cause evalv2 to not lose some positions for certain cycle errors, which seems like a mild improvement. Either way that doesn't seem too important at this point, now that we are focused on evalv3. Signed-off-by: Daniel Martí <[email protected]> Change-Id: I48c383374677efc88e4106dd7748e9222d37e9c4 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1214724 Unity-Result: CUE porcuepine <[email protected]> TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Matthew Sackman <[email protected]>
1 parent 68dad74 commit a1a53e5

File tree

4 files changed

+68
-17
lines changed

4 files changed

+68
-17
lines changed

cue/errors/errors.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -420,16 +420,7 @@ func (p list) Sort() {
420420
// RemoveMultiples sorts an List and removes all but the first error per line.
421421
func (p *list) RemoveMultiples() {
422422
p.Sort()
423-
var last Error
424-
i := 0
425-
for _, e := range *p {
426-
if last == nil || !approximateEqual(last, e) {
427-
last = e
428-
(*p)[i] = e
429-
i++
430-
}
431-
}
432-
(*p) = (*p)[0:i]
423+
*p = slices.CompactFunc(*p, approximateEqual)
433424
}
434425

435426
func approximateEqual(a, b Error) bool {

cue/testdata/benchmarks/issue3517.txtar

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -308,11 +308,13 @@ diff old new
308308
./main.cue:50:19
309309

310310
Result:
311-
@@ -11,32 +8,37 @@
311+
@@ -11,36 +8,37 @@
312312
// [eval]
313313
#TimeSpan: (#struct){
314314
start: (_|_){
315315
- // [cycle] cycle error
316+
- // cycle error:
317+
- // ./main.cue:12:9
316318
+ // [incomplete] #TimeSpan.start: non-concrete value end for bound <=:
317319
+ // ./main.cue:12:11
318320
+ // #TimeSpan.start: non-concrete value float in operand to -:
@@ -349,6 +351,8 @@ diff old new
349351
- timeSpan: (#struct){
350352
- start: (_|_){
351353
- // [cycle] cycle error
354+
- // cycle error:
355+
- // ./main.cue:12:9
352356
- }
353357
- duration: (_|_){
354358
- // [cycle] cycle error:
@@ -363,13 +367,15 @@ diff old new
363367
}
364368
#TaskSet: (#struct){
365369
action: (string){ string }
366-
@@ -44,32 +46,38 @@
370+
@@ -48,41 +46,38 @@
367371
}
368372
tasks: (#list){
369373
}
370374
- timeSpan?: (#struct){
371375
- start: (_|_){
372376
- // [cycle] cycle error
377+
- // cycle error:
378+
- // ./main.cue:12:9
373379
- }
374380
- duration: (_|_){
375381
- // [cycle] cycle error:
@@ -387,13 +393,20 @@ diff old new
387393
timeSpan: (#struct){
388394
- start: (_|_){
389395
- // [cycle] cycle error
396+
- // cycle error:
397+
- // ./main.cue:12:9
390398
- }
391399
- duration: (_|_){
392400
- // [cycle] cycle error:
393401
- // ./main.cue:9:12
394402
- }
395403
- end: (_|_){
396404
- // [cycle] cycle error
405+
- // cycle error:
406+
- // ./main.cue:9:12
407+
- // ./main.cue:8:12
408+
- // cycle error:
409+
- // ./main.cue:12:9
397410
+ duration: (_|_){
398411
+ // [incomplete] #T1.timeSpan.start: non-concrete value end for bound <=:
399412
+ // ./main.cue:12:11
@@ -424,19 +437,26 @@ diff old new
424437
}
425438
}
426439
}
427-
@@ -76,15 +84,33 @@
440+
@@ -89,22 +84,33 @@
428441
#T2: (#struct){
429442
action: (string){ "Task 2" }
430443
timeSpan: (#struct){
431444
- start: (_|_){
432445
- // [cycle] cycle error
446+
- // cycle error:
447+
- // ./main.cue:12:9
433448
- }
434449
- duration: (_|_){
435450
- // [cycle] cycle error:
436451
- // ./main.cue:9:12
437452
- }
438453
- end: (_|_){
439454
- // [cycle] cycle error
455+
- // cycle error:
456+
- // ./main.cue:9:12
457+
- // ./main.cue:8:12
458+
- // cycle error:
459+
- // ./main.cue:12:9
440460
+ duration: (_|_){
441461
+ // [incomplete] #T2.timeSpan.start: non-concrete value end for bound <=:
442462
+ // ./main.cue:12:11
@@ -467,7 +487,7 @@ diff old new
467487
}
468488
}
469489
}
470-
@@ -93,66 +119,73 @@
490+
@@ -113,66 +119,73 @@
471491
action: (string){ "Task 1 and Task 2" }
472492
#tasks: (_|_){
473493
// [eval]
@@ -605,6 +625,8 @@ Result:
605625
#TimeSpan: (#struct){
606626
start: (_|_){
607627
// [cycle] cycle error
628+
// cycle error:
629+
// ./main.cue:12:9
608630
}
609631
duration: (_|_){
610632
// [cycle] cycle error:
@@ -620,6 +642,8 @@ Result:
620642
timeSpan: (#struct){
621643
start: (_|_){
622644
// [cycle] cycle error
645+
// cycle error:
646+
// ./main.cue:12:9
623647
}
624648
duration: (_|_){
625649
// [cycle] cycle error:
@@ -640,6 +664,8 @@ Result:
640664
timeSpan?: (#struct){
641665
start: (_|_){
642666
// [cycle] cycle error
667+
// cycle error:
668+
// ./main.cue:12:9
643669
}
644670
duration: (_|_){
645671
// [cycle] cycle error:
@@ -656,13 +682,20 @@ Result:
656682
timeSpan: (#struct){
657683
start: (_|_){
658684
// [cycle] cycle error
685+
// cycle error:
686+
// ./main.cue:12:9
659687
}
660688
duration: (_|_){
661689
// [cycle] cycle error:
662690
// ./main.cue:9:12
663691
}
664692
end: (_|_){
665693
// [cycle] cycle error
694+
// cycle error:
695+
// ./main.cue:9:12
696+
// ./main.cue:8:12
697+
// cycle error:
698+
// ./main.cue:12:9
666699
}
667700
}
668701
}
@@ -671,13 +704,20 @@ Result:
671704
timeSpan: (#struct){
672705
start: (_|_){
673706
// [cycle] cycle error
707+
// cycle error:
708+
// ./main.cue:12:9
674709
}
675710
duration: (_|_){
676711
// [cycle] cycle error:
677712
// ./main.cue:9:12
678713
}
679714
end: (_|_){
680715
// [cycle] cycle error
716+
// cycle error:
717+
// ./main.cue:9:12
718+
// ./main.cue:8:12
719+
// cycle error:
720+
// ./main.cue:12:9
681721
}
682722
}
683723
}

cue/testdata/cycle/issue3118.txtar

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,13 @@ the new evaluator includes positions with the cycle error and the old evaluator
174174
diff old new
175175
--- old
176176
+++ new
177-
@@ -1,14 +1,31 @@
177+
@@ -1,16 +1,31 @@
178178
(struct){
179179
#TimeSpan: (#struct){
180180
start: (_|_){
181181
- // [cycle] cycle error
182+
- // cycle error:
183+
- // ./in.cue:10:9
182184
+ // [incomplete] #TimeSpan.start: non-concrete value end for bound <=:
183185
+ // ./in.cue:10:11
184186
+ // #TimeSpan.start: non-concrete value float in operand to -:
@@ -210,18 +212,24 @@ diff old new
210212
// ./in.cue:8:12
211213
}
212214
}
213-
@@ -20,26 +37,56 @@
215+
@@ -22,32 +37,56 @@
214216
}
215217
eg2: (#struct){
216218
start: (_|_){
217219
- // [cycle] cycle error
220+
- // cycle error:
221+
- // ./in.cue:10:9
218222
- }
219223
- duration: (_|_){
220224
- // [cycle] cycle error:
221225
- // ./in.cue:7:12
222226
- }
223227
- end: (_|_){
224228
- // [cycle] cycle error
229+
- // cycle error:
230+
- // ./in.cue:7:12
231+
- // cycle error:
232+
- // ./in.cue:10:9
225233
+ // [incomplete] examples.eg2.start: non-concrete value end for bound <=:
226234
+ // ./in.cue:10:11
227235
+ // examples.eg2.start: non-concrete value float in operand to -:
@@ -288,6 +296,8 @@ diff old new
288296
#TimeSpan: (#struct){
289297
start: (_|_){
290298
// [cycle] cycle error
299+
// cycle error:
300+
// ./in.cue:10:9
291301
}
292302
duration: (_|_){
293303
// [cycle] cycle error:
@@ -307,13 +317,19 @@ diff old new
307317
eg2: (#struct){
308318
start: (_|_){
309319
// [cycle] cycle error
320+
// cycle error:
321+
// ./in.cue:10:9
310322
}
311323
duration: (_|_){
312324
// [cycle] cycle error:
313325
// ./in.cue:7:12
314326
}
315327
end: (_|_){
316328
// [cycle] cycle error
329+
// cycle error:
330+
// ./in.cue:7:12
331+
// cycle error:
332+
// ./in.cue:10:9
317333
}
318334
}
319335
eg3: (#struct){

cue/testdata/fulleval/026_dont_convert_incomplete_errors_to_non-incomplete.txtar

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ Disjuncts: 82
150150
diff old new
151151
--- old
152152
+++ new
153-
@@ -1,10 +1,16 @@
153+
@@ -1,12 +1,16 @@
154154
(struct){
155155
n1: (struct){
156156
min: (_|_){
@@ -162,6 +162,8 @@ diff old new
162162
}
163163
max: (_|_){
164164
- // [cycle] cycle error
165+
- // cycle error:
166+
- // ./in.cue:3:22
165167
+ // [cycle] n1.min: cycle with field: max:
166168
+ // ./in.cue:3:12
167169
+ // n1.max: cycle with field: min:
@@ -177,6 +179,8 @@ diff old new
177179
}
178180
max: (_|_){
179181
// [cycle] cycle error
182+
// cycle error:
183+
// ./in.cue:3:22
180184
}
181185
}
182186
n2: (_|_){

0 commit comments

Comments
 (0)