Skip to content

Commit 86fdd97

Browse files
committed
internal/core/adt: fix simplifcation of validators
Now Validators can be NonConcrete, arguments are not necessarily fully evaluated. This is now addressed. The also prevents other issues in an upcoming CL. Issue #3165 Fixes #3418 Signed-off-by: Marcel van Lohuizen <[email protected]> Change-Id: Ie103c9710eb9a89ee796a2486a9f4d365760f404 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1202211 Reviewed-by: Matthew Sackman <[email protected]> TryBot-Result: CUEcueckoo <[email protected]> Unity-Result: CUE porcuepine <[email protected]>
1 parent b51914f commit 86fdd97

File tree

9 files changed

+129
-90
lines changed

9 files changed

+129
-90
lines changed

cue/testdata/builtins/validators.txtar

+114-61
Original file line numberDiff line numberDiff line change
@@ -188,15 +188,15 @@ issue3474: topValidator: failType: {
188188
}
189189

190190
-- out/eval/stats --
191-
Leaks: 5
192-
Freed: 109
193-
Reused: 102
194-
Allocs: 12
191+
Leaks: 1
192+
Freed: 117
193+
Reused: 110
194+
Allocs: 8
195195
Retain: 12
196196

197-
Unifications: 114
198-
Conjuncts: 222
199-
Disjuncts: 123
197+
Unifications: 118
198+
Conjuncts: 226
199+
Disjuncts: 131
200200
-- out/evalalpha --
201201
Errors:
202202
issue3418.0: conflicting values 2 and 1:
@@ -418,29 +418,42 @@ Result:
418418
diff old new
419419
--- old
420420
+++ new
421-
@@ -1,32 +1,28 @@
421+
@@ -1,49 +1,28 @@
422422
Errors:
423+
-callOfCallToValidator.e: cannot call previously called validator b:
424+
- ./in.cue:94:5
425+
-issue3418.t1: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.0: conflicting values 2 and 1))): conflicting values 2 and 1:
426+
- ./issue3418.cue:1:24
427+
- ./issue3418.cue:1:16
428+
- ./issue3418.cue:1:31
423429
+issue3418.0: conflicting values 2 and 1:
424-
+ ./issue3418.cue:1:35
425-
+ ./issue3418.cue:1:37
426-
+issue3418.t3.0: conflicting values 2 and 1:
427-
+ ./issue3418.cue:6:16
428-
+ ./issue3418.cue:6:18
429-
+issue3418.t4.0: conflicting values 2 and 1:
430-
+ ./issue3418.cue:10:16
431-
+ ./issue3418.cue:10:18
432-
callOfCallToValidator.e: cannot call previously called validator b:
433-
./in.cue:94:5
434-
-issue3418.t2: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.0: conflicting values 2 and 1))): 0 matched, expected 1:
430+
./issue3418.cue:1:35
431+
./issue3418.cue:1:37
432+
-issue3418.t2: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.0: conflicting values 2 and 1))): conflicting values 2 and 1:
435433
- ./issue3418.cue:2:41
436434
- ./issue3418.cue:2:16
437435
- ./issue3418.cue:2:48
438-
-issue3418.t3.x: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.t3.0: conflicting values 2 and 1))): 0 matched, expected 1:
436+
- ./issue3418.cue:2:52
437+
- ./issue3418.cue:2:54
438+
-issue3418.t3.x: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.t3.0: conflicting values 2 and 1))): conflicting values 2 and 1:
439439
- ./issue3418.cue:6:5
440440
- ./issue3418.cue:4:5
441441
- ./issue3418.cue:5:5
442442
- ./issue3418.cue:6:12
443+
+issue3418.t3.0: conflicting values 2 and 1:
444+
./issue3418.cue:6:16
445+
./issue3418.cue:6:18
446+
-issue3418.t4.x: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.t4.0: conflicting values 2 and 1))): conflicting values 2 and 1:
447+
- ./issue3418.cue:10:5
448+
- ./issue3418.cue:9:5
449+
- ./issue3418.cue:10:12
450+
+issue3418.t4.0: conflicting values 2 and 1:
451+
./issue3418.cue:10:16
452+
./issue3418.cue:10:18
453+
- ./issue3418.cue:11:5
443454
-issue3474.structValidator.failAfter.A: invalid value {C:true,B*:if true true} (does not satisfy struct.MaxFields(1)): len(fields) > MaxFields(1) (2 > 1):
455+
+callOfCallToValidator.e: cannot call previously called validator b:
456+
+ ./in.cue:94:5
444457
+issue3474.structValidator.failAfter.A: invalid value {C:true,B:true} (does not satisfy struct.MaxFields(1)): len(fields) > MaxFields(1) (2 > 1):
445458
./issue3474.cue:12:5
446459
./issue3474.cue:12:22
@@ -461,23 +474,23 @@ diff old new
461474

462475
Result:
463476
(_|_){
464-
@@ -46,7 +42,6 @@
477+
@@ -63,7 +42,6 @@
465478
kv: (_|_){
466479
// [incomplete] incompleteError2.MyType.kv: invalid value {} (does not satisfy struct.MinFields(1)): len(fields) < MinFields(1) (0 < 1):
467480
// ./in.cue:22:7
468481
- // ./in.cue:21:7
469482
// ./in.cue:22:24
470483
}
471484
}
472-
@@ -70,7 +65,6 @@
485+
@@ -87,7 +65,6 @@
473486
kv: (_|_){
474487
// [incomplete] violation.#MyType.kv: invalid value {} (does not satisfy struct.MinFields(1)): len(fields) < MinFields(1) (0 < 1):
475488
// ./in.cue:49:7
476489
- // ./in.cue:48:7
477490
// ./in.cue:49:24
478491
}
479492
}
480-
@@ -117,15 +111,10 @@
493+
@@ -134,15 +111,10 @@
481494
0: (int){ 1 }
482495
}
483496
}
@@ -494,53 +507,56 @@ diff old new
494507
// ./in.cue:112:20
495508
}
496509
}
497-
@@ -132,25 +121,31 @@
498-
}
510+
@@ -150,18 +122,12 @@
499511
issue3418: (_|_){
500512
// [eval]
501-
- t1: (string){ "foo" }
502-
+ t1: (_|_){
513+
t1: (_|_){
514+
- // [eval] issue3418.t1: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.0: conflicting values 2 and 1))): conflicting values 2 and 1:
515+
- // ./issue3418.cue:1:24
516+
- // ./issue3418.cue:1:16
517+
- // ./issue3418.cue:1:31
503518
+ // [eval] issue3418.0: conflicting values 2 and 1:
504-
+ // ./issue3418.cue:1:35
505-
+ // ./issue3418.cue:1:37
506-
+ }
519+
// ./issue3418.cue:1:35
520+
// ./issue3418.cue:1:37
521+
}
507522
t2: (_|_){
508-
- // [eval] issue3418.t2: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.0: conflicting values 2 and 1))): 0 matched, expected 1:
523+
- // [eval] issue3418.t2: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.0: conflicting values 2 and 1))): conflicting values 2 and 1:
509524
- // ./issue3418.cue:2:41
510525
- // ./issue3418.cue:2:16
511526
- // ./issue3418.cue:2:48
512527
+ // [eval] issue3418.0: conflicting values 2 and 1:
513-
+ // ./issue3418.cue:2:52
514-
+ // ./issue3418.cue:2:54
528+
// ./issue3418.cue:2:52
529+
// ./issue3418.cue:2:54
515530
}
531+
@@ -168,11 +134,7 @@
516532
t3: (_|_){
517533
// [eval]
518534
x: (_|_){
519-
- // [eval] issue3418.t3.x: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.t3.0: conflicting values 2 and 1))): 0 matched, expected 1:
535+
- // [eval] issue3418.t3.x: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.t3.0: conflicting values 2 and 1))): conflicting values 2 and 1:
520536
- // ./issue3418.cue:6:5
521537
- // ./issue3418.cue:4:5
522538
- // ./issue3418.cue:5:5
523539
- // ./issue3418.cue:6:12
524-
- }
525-
- }
526-
- t4: (struct){
527-
- x: (string){ "foo" }
528540
+ // [eval] issue3418.t3.0: conflicting values 2 and 1:
529-
+ // ./issue3418.cue:6:16
530-
+ // ./issue3418.cue:6:18
531-
+ }
532-
+ }
533-
+ t4: (_|_){
534-
+ // [eval]
535-
+ x: (_|_){
541+
// ./issue3418.cue:6:16
542+
// ./issue3418.cue:6:18
543+
}
544+
@@ -180,13 +142,9 @@
545+
t4: (_|_){
546+
// [eval]
547+
x: (_|_){
548+
- // [eval] issue3418.t4.x: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.t4.0: conflicting values 2 and 1))): conflicting values 2 and 1:
549+
- // ./issue3418.cue:10:5
550+
- // ./issue3418.cue:9:5
551+
- // ./issue3418.cue:10:12
536552
+ // [eval] issue3418.t4.0: conflicting values 2 and 1:
537-
+ // ./issue3418.cue:10:16
538-
+ // ./issue3418.cue:10:18
539-
+ }
553+
// ./issue3418.cue:10:16
554+
// ./issue3418.cue:10:18
555+
- // ./issue3418.cue:11:5
556+
}
540557
}
541558
}
542-
issue3474: (_|_){
543-
@@ -165,10 +160,9 @@
559+
@@ -202,10 +160,9 @@
544560
failAfter: (_|_){
545561
// [eval]
546562
A: (_|_){
@@ -552,23 +568,23 @@ diff old new
552568
C: (bool){ true }
553569
B: (bool){ true }
554570
}
555-
@@ -178,7 +172,6 @@
571+
@@ -215,7 +172,6 @@
556572
// [incomplete] issue3474.structValidator.incomplete.A: invalid value {} (does not satisfy struct.MinFields(1)): len(fields) < MinFields(1) (0 < 1):
557573
// ./issue3474.cue:20:5
558574
// ./issue3474.cue:20:22
559575
- // ./issue3474.cue:21:5
560576
}
561577
}
562578
failClosed: (_|_){
563-
@@ -187,7 +180,6 @@
579+
@@ -224,7 +180,6 @@
564580
// [eval] issue3474.structValidator.failClosed.#A: invalid value {} (does not satisfy struct.MinFields(1)): len(fields) < MinFields(1) (0 < 1):
565581
// ./issue3474.cue:27:6
566582
// ./issue3474.cue:27:23
567583
- // ./issue3474.cue:28:6
568584
}
569585
}
570586
}
571-
@@ -202,14 +194,12 @@
587+
@@ -239,14 +194,12 @@
572588
// [eval] issue3474.topValidator.fail.A: invalid value 1 (does not satisfy matchN(1, [>10])): 0 matched, expected 1:
573589
// ./issue3474.cue:41:5
574590
// ./issue3474.cue:41:12
@@ -584,7 +600,7 @@ diff old new
584600
}), int) }
585601
}
586602
failType: (_|_){
587-
@@ -218,7 +208,6 @@
603+
@@ -255,7 +208,6 @@
588604
// [eval] issue3474.topValidator.failType.A: invalid value {C:1} (does not satisfy matchN(1, [>10])): 0 matched, expected 1:
589605
// ./issue3474.cue:53:5
590606
// ./issue3474.cue:53:12
@@ -596,15 +612,32 @@ diff old new
596612
Errors:
597613
callOfCallToValidator.e: cannot call previously called validator b:
598614
./in.cue:94:5
599-
issue3418.t2: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.0: conflicting values 2 and 1))): 0 matched, expected 1:
615+
issue3418.t1: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.0: conflicting values 2 and 1))): conflicting values 2 and 1:
616+
./issue3418.cue:1:24
617+
./issue3418.cue:1:16
618+
./issue3418.cue:1:31
619+
./issue3418.cue:1:35
620+
./issue3418.cue:1:37
621+
issue3418.t2: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.0: conflicting values 2 and 1))): conflicting values 2 and 1:
600622
./issue3418.cue:2:41
601623
./issue3418.cue:2:16
602624
./issue3418.cue:2:48
603-
issue3418.t3.x: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.t3.0: conflicting values 2 and 1))): 0 matched, expected 1:
625+
./issue3418.cue:2:52
626+
./issue3418.cue:2:54
627+
issue3418.t3.x: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.t3.0: conflicting values 2 and 1))): conflicting values 2 and 1:
604628
./issue3418.cue:6:5
605629
./issue3418.cue:4:5
606630
./issue3418.cue:5:5
607631
./issue3418.cue:6:12
632+
./issue3418.cue:6:16
633+
./issue3418.cue:6:18
634+
issue3418.t4.x: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.t4.0: conflicting values 2 and 1))): conflicting values 2 and 1:
635+
./issue3418.cue:10:5
636+
./issue3418.cue:9:5
637+
./issue3418.cue:10:12
638+
./issue3418.cue:10:16
639+
./issue3418.cue:10:18
640+
./issue3418.cue:11:5
608641
issue3474.structValidator.failAfter.A: invalid value {C:true,B*:if true true} (does not satisfy struct.MaxFields(1)): len(fields) > MaxFields(1) (2 > 1):
609642
./issue3474.cue:12:5
610643
./issue3474.cue:12:22
@@ -727,25 +760,45 @@ Result:
727760
}
728761
issue3418: (_|_){
729762
// [eval]
730-
t1: (string){ "foo" }
763+
t1: (_|_){
764+
// [eval] issue3418.t1: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.0: conflicting values 2 and 1))): conflicting values 2 and 1:
765+
// ./issue3418.cue:1:24
766+
// ./issue3418.cue:1:16
767+
// ./issue3418.cue:1:31
768+
// ./issue3418.cue:1:35
769+
// ./issue3418.cue:1:37
770+
}
731771
t2: (_|_){
732-
// [eval] issue3418.t2: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.0: conflicting values 2 and 1))): 0 matched, expected 1:
772+
// [eval] issue3418.t2: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.0: conflicting values 2 and 1))): conflicting values 2 and 1:
733773
// ./issue3418.cue:2:41
734774
// ./issue3418.cue:2:16
735775
// ./issue3418.cue:2:48
776+
// ./issue3418.cue:2:52
777+
// ./issue3418.cue:2:54
736778
}
737779
t3: (_|_){
738780
// [eval]
739781
x: (_|_){
740-
// [eval] issue3418.t3.x: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.t3.0: conflicting values 2 and 1))): 0 matched, expected 1:
782+
// [eval] issue3418.t3.x: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.t3.0: conflicting values 2 and 1))): conflicting values 2 and 1:
741783
// ./issue3418.cue:6:5
742784
// ./issue3418.cue:4:5
743785
// ./issue3418.cue:5:5
744786
// ./issue3418.cue:6:12
787+
// ./issue3418.cue:6:16
788+
// ./issue3418.cue:6:18
745789
}
746790
}
747-
t4: (struct){
748-
x: (string){ "foo" }
791+
t4: (_|_){
792+
// [eval]
793+
x: (_|_){
794+
// [eval] issue3418.t4.x: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.t4.0: conflicting values 2 and 1))): conflicting values 2 and 1:
795+
// ./issue3418.cue:10:5
796+
// ./issue3418.cue:9:5
797+
// ./issue3418.cue:10:12
798+
// ./issue3418.cue:10:16
799+
// ./issue3418.cue:10:18
800+
// ./issue3418.cue:11:5
801+
}
749802
}
750803
}
751804
issue3474: (_|_){

encoding/jsonschema/external_teststats.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Generated by teststats. DO NOT EDIT
22
v2:
33
schema extract (pass / total): 993 / 1363 = 72.9%
4-
tests (pass / total): 3512 / 4803 = 73.1%
5-
tests on extracted schemas (pass / total): 3512 / 3801 = 92.4%
4+
tests (pass / total): 3517 / 4803 = 73.2%
5+
tests on extracted schemas (pass / total): 3517 / 3801 = 92.5%
66

77
v3:
88
schema extract (pass / total): 981 / 1363 = 72.0%

encoding/jsonschema/testdata/external/tests/draft2019-09/allOf.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -369,10 +369,7 @@
369369
{
370370
"description": "allOf: false, anyOf: true, oneOf: true",
371371
"data": 15,
372-
"valid": false,
373-
"skip": {
374-
"v2": "unexpected success"
375-
}
372+
"valid": false
376373
},
377374
{
378375
"description": "allOf: true, anyOf: false, oneOf: false",

encoding/jsonschema/testdata/external/tests/draft2020-12/allOf.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -369,10 +369,7 @@
369369
{
370370
"description": "allOf: false, anyOf: true, oneOf: true",
371371
"data": 15,
372-
"valid": false,
373-
"skip": {
374-
"v2": "unexpected success"
375-
}
372+
"valid": false
376373
},
377374
{
378375
"description": "allOf: true, anyOf: false, oneOf: false",

encoding/jsonschema/testdata/external/tests/draft4/allOf.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,7 @@
301301
{
302302
"description": "allOf: false, anyOf: true, oneOf: true",
303303
"data": 15,
304-
"valid": false,
305-
"skip": {
306-
"v2": "unexpected success"
307-
}
304+
"valid": false
308305
},
309306
{
310307
"description": "allOf: true, anyOf: false, oneOf: false",

encoding/jsonschema/testdata/external/tests/draft6/allOf.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -357,10 +357,7 @@
357357
{
358358
"description": "allOf: false, anyOf: true, oneOf: true",
359359
"data": 15,
360-
"valid": false,
361-
"skip": {
362-
"v2": "unexpected success"
363-
}
360+
"valid": false
364361
},
365362
{
366363
"description": "allOf: true, anyOf: false, oneOf: false",

encoding/jsonschema/testdata/external/tests/draft7/allOf.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -357,10 +357,7 @@
357357
{
358358
"description": "allOf: false, anyOf: true, oneOf: true",
359359
"data": 15,
360-
"valid": false,
361-
"skip": {
362-
"v2": "unexpected success"
363-
}
360+
"valid": false
364361
},
365362
{
366363
"description": "allOf: true, anyOf: false, oneOf: false",

internal/core/adt/composite.go

-6
Original file line numberDiff line numberDiff line change
@@ -707,12 +707,6 @@ func (v *Vertex) ToDataSingle() *Vertex {
707707
func (v *Vertex) ToDataAll(ctx *OpContext) *Vertex {
708708
v.Finalize(ctx)
709709

710-
// TODO(mpvl): this is to work around a bug in the old evaluator, where
711-
// finalize does not always work.
712-
if v.status == evaluating && ctx.isDevVersion() {
713-
return v.ToDataSingle()
714-
}
715-
716710
arcs := make([]*Vertex, 0, len(v.Arcs))
717711
for _, a := range v.Arcs {
718712
if !a.IsDefined(ctx) {

0 commit comments

Comments
 (0)