Skip to content

Commit bae8bbf

Browse files
committed
internal/core/adt: avoid loops in debug printing
Printing adt values can cause infinite loops with structure sharing enabled. This is especially the case for partially evaluated Vertices, if a shared Vertex is printed for which the structural cycle is not yet detected. We use the recently added cycle detection mechanism to whether a node is cyclic and/or shared in a Vertex. This is a rather conservative method and may mark false positives. This is okay as it serves the purpose of avoiding printing cycles only and is not otherwise involved in operations. We could enabled printing with structure sharing in more tests, but this would produce rather large diffs. We could still consider this later, especially once the old evaluator has been removed and the output from the new evaluator become the new golden files. Issue #2884 Signed-off-by: Marcel van Lohuizen <[email protected]> Change-Id: Icc5641446c8b5b9a4d4f67b584ccaa7114939890 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1193845 TryBot-Result: CUEcueckoo <[email protected]> Unity-Result: CUE porcuepine <[email protected]> Reviewed-by: Daniel Martí <[email protected]>
1 parent 831374c commit bae8bbf

File tree

12 files changed

+319
-295
lines changed

12 files changed

+319
-295
lines changed

cue/testdata/benchmarks/listdisj.txtar

Lines changed: 58 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,26 +64,16 @@ Retain: 0
6464
Unifications: 15
6565
Conjuncts: 43
6666
Disjuncts: 4
67-
-- out/eval --
67+
-- out/evalalpha --
6868
(struct){
6969
#T: (list){
7070
0: (string){ "d" }
7171
}
72-
x: (list){
73-
0: (string){ "d" }
74-
}
75-
y: (list){
76-
0: (string){ "d" }
77-
}
78-
z: (list){
79-
0: (string){ "d" }
80-
}
81-
v: (list){
82-
0: (string){ "d" }
83-
}
84-
#X: (list){
85-
0: (string){ "d" }
86-
}
72+
x: ~(#T)
73+
y: ~(#T)
74+
z: ~(#T)
75+
v: ~(#T)
76+
#X: ~(#T)
8777
}
8878
-- diff/-out/evalalpha/stats<==>+out/eval/stats --
8979
diff old new
@@ -106,6 +96,58 @@ diff old new
10696
+Unifications: 15
10797
+Conjuncts: 43
10898
+Disjuncts: 4
99+
-- diff/-out/evalalpha<==>+out/eval --
100+
diff old new
101+
--- old
102+
+++ new
103+
@@ -2,19 +2,9 @@
104+
#T: (list){
105+
0: (string){ "d" }
106+
}
107+
- x: (list){
108+
- 0: (string){ "d" }
109+
- }
110+
- y: (list){
111+
- 0: (string){ "d" }
112+
- }
113+
- z: (list){
114+
- 0: (string){ "d" }
115+
- }
116+
- v: (list){
117+
- 0: (string){ "d" }
118+
- }
119+
- #X: (list){
120+
- 0: (string){ "d" }
121+
- }
122+
+ x: ~(#T)
123+
+ y: ~(#T)
124+
+ z: ~(#T)
125+
+ v: ~(#T)
126+
+ #X: ~(#T)
127+
}
128+
-- out/eval --
129+
(struct){
130+
#T: (list){
131+
0: (string){ "d" }
132+
}
133+
x: (list){
134+
0: (string){ "d" }
135+
}
136+
y: (list){
137+
0: (string){ "d" }
138+
}
139+
z: (list){
140+
0: (string){ "d" }
141+
}
142+
v: (list){
143+
0: (string){ "d" }
144+
}
145+
#X: (list){
146+
0: (string){ "d" }
147+
}
148+
}
149+
-- diff/explanation --
150+
Differences fully due to rendered structure sharing.
109151
-- out/eval/stats --
110152
Leaks: 0
111153
Freed: 447

cue/testdata/cycle/constraints.txtar

Lines changed: 26 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -664,15 +664,7 @@ Result:
664664
// [structural cycle]
665665
t1: (_|_){
666666
// [structural cycle]
667-
a: (_|_){
668-
// [structural cycle]
669-
b: (_|_){
670-
// [structural cycle]
671-
b: (_|_){
672-
// [structural cycle] selfTriggerCycle.t1.#T.b.b: structural cycle
673-
}
674-
}
675-
}
667+
a: ~(selfTriggerCycle.t1.#T)
676668
#T: (_|_){
677669
// [structural cycle]
678670
b: (_|_){
@@ -735,49 +727,16 @@ Result:
735727
link: (#struct){
736728
a: (#struct){
737729
two: (#struct){
738-
link: (_|_){
739-
// [structural cycle]
740-
a: (_|_){
741-
// [structural cycle]
742-
b: (_|_){
743-
// [structural cycle]
744-
link: (_|_){
745-
// [structural cycle] selfTriggerCycle.issue1503.#T.a.b.link: structural cycle
746-
}
747-
}
748-
}
749-
}
730+
link: ~(selfTriggerCycle.issue1503.#T)
750731
}
751732
b: (#struct){
752-
link: (_|_){
753-
// [structural cycle]
754-
a: (_|_){
755-
// [structural cycle]
756-
b: (_|_){
757-
// [structural cycle]
758-
link: (_|_){
759-
// [structural cycle] selfTriggerCycle.issue1503.#T.a.b.link: structural cycle
760-
}
761-
}
762-
}
763-
}
733+
link: ~(selfTriggerCycle.issue1503.#T)
764734
}
765735
}
766736
}
767737
}
768738
b: (#struct){
769-
link: (_|_){
770-
// [structural cycle]
771-
a: (_|_){
772-
// [structural cycle]
773-
b: (_|_){
774-
// [structural cycle]
775-
link: (_|_){
776-
// [structural cycle] selfTriggerCycle.issue1503.#T.a.b.link: structural cycle
777-
}
778-
}
779-
}
780-
}
739+
link: ~(selfTriggerCycle.issue1503.#T)
781740
}
782741
}
783742
}
@@ -854,17 +813,21 @@ diff old new
854813
}
855814
}
856815
}
857-
@@ -222,6 +222,9 @@
816+
@@ -218,12 +218,7 @@
817+
// [structural cycle]
818+
t1: (_|_){
819+
// [structural cycle]
820+
- a: (_|_){
821+
- // [structural cycle]
822+
- b: (_|_){
823+
- // [structural cycle]
824+
- }
825+
- }
826+
+ a: ~(selfTriggerCycle.t1.#T)
827+
#T: (_|_){
858828
// [structural cycle]
859829
b: (_|_){
860-
// [structural cycle]
861-
+ b: (_|_){
862-
+ // [structural cycle] selfTriggerCycle.t1.#T.b.b: structural cycle
863-
+ }
864-
}
865-
}
866-
#T: (_|_){
867-
@@ -280,22 +283,52 @@
830+
@@ -280,25 +275,22 @@
868831
}
869832
issue1503: (_|_){
870833
// [structural cycle]
@@ -884,55 +847,28 @@ diff old new
884847
- // [structural cycle]
885848
- a: (struct){
886849
- two: (struct){
850+
- }
851+
- }
852+
- }
887853
+ a: (#struct){
888854
+ a: (#struct){
889855
+ one: (#struct){
890856
+ link: (#struct){
891857
+ a: (#struct){
892858
+ two: (#struct){
893-
+ link: (_|_){
894-
+ // [structural cycle]
895-
+ a: (_|_){
896-
+ // [structural cycle]
897-
+ b: (_|_){
898-
+ // [structural cycle]
899-
+ link: (_|_){
900-
+ // [structural cycle] selfTriggerCycle.issue1503.#T.a.b.link: structural cycle
901-
+ }
902-
+ }
903-
+ }
904-
+ }
859+
+ link: ~(selfTriggerCycle.issue1503.#T)
905860
+ }
906861
+ b: (#struct){
907-
+ link: (_|_){
908-
+ // [structural cycle]
909-
+ a: (_|_){
910-
+ // [structural cycle]
911-
+ b: (_|_){
912-
+ // [structural cycle]
913-
+ link: (_|_){
914-
+ // [structural cycle] selfTriggerCycle.issue1503.#T.a.b.link: structural cycle
915-
+ }
916-
+ }
917-
+ }
918-
+ }
862+
+ link: ~(selfTriggerCycle.issue1503.#T)
919863
+ }
920864
+ }
921865
+ }
922866
+ }
923867
+ b: (#struct){
924-
+ link: (_|_){
925-
+ // [structural cycle]
926-
+ a: (_|_){
927-
+ // [structural cycle]
928-
+ b: (_|_){
929-
+ // [structural cycle]
930-
+ link: (_|_){
931-
+ // [structural cycle] selfTriggerCycle.issue1503.#T.a.b.link: structural cycle
932-
+ }
933-
}
934-
}
935-
}
868+
+ link: ~(selfTriggerCycle.issue1503.#T)
869+
}
870+
}
871+
}
936872
-- diff/todo/p2 --
937873
issue1503: cycle detected too late (but not super late)
938874
selfTriggerCycle.t1.a.b.b: cycle detected slightly too late

0 commit comments

Comments
 (0)