internal/core/eval: strip arcs for nodes with structural cycles

This prevents a Finalized Vertex from not having
and descendent arcs that are not Finalized.

This, in turn, prevents accidental triggering of
evaluation in an API that may disect the Vertex.

Change-Id: I4f4727393d9fdf2b55558512f2f850124ec48d5c
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/8241
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/cue/testdata/compile/scope.txtar b/cue/testdata/compile/scope.txtar
index 1b69449..76d1dcf 100644
--- a/cue/testdata/compile/scope.txtar
+++ b/cue/testdata/compile/scope.txtar
@@ -104,8 +104,6 @@
     // [structural cycle]
     next: (_|_){
       // [structural cycle] schema.next: structural cycle
-      next: (_|_){// 〈1;let _schema_1〉
-      }
     }
   }
 }
diff --git a/cue/testdata/cycle/disjunction.txtar b/cue/testdata/cycle/disjunction.txtar
index b6e6af1..e6ebc9b 100644
--- a/cue/testdata/cycle/disjunction.txtar
+++ b/cue/testdata/cycle/disjunction.txtar
@@ -48,8 +48,6 @@
     // [structural cycle]
     a: (_|_){
       // [structural cycle] cycle.a: structural cycle
-      a: (_|_){// 〈1;cycle〉
-      }
     }
   }
   r1a: (int){ int }
diff --git a/cue/testdata/cycle/issue306.txtar b/cue/testdata/cycle/issue306.txtar
index a83b30f..f5bb102 100644
--- a/cue/testdata/cycle/issue306.txtar
+++ b/cue/testdata/cycle/issue306.txtar
@@ -18,10 +18,6 @@
       // [structural cycle]
       controller: (_|_){
         // [structural cycle] #Controller.settings.controller: structural cycle
-        settings: (_|_){// {
-          //   controller: 〈2;#Controller〉
-          // }
-        }
       }
     }
   }
diff --git a/cue/testdata/cycle/structural.txtar b/cue/testdata/cycle/structural.txtar
index fcf9c3c..0c30e6c 100644
--- a/cue/testdata/cycle/structural.txtar
+++ b/cue/testdata/cycle/structural.txtar
@@ -503,8 +503,6 @@
       // [structural cycle]
       0: (_|_){
         // [structural cycle] a1.f.0: structural cycle
-        0: (_|_){// 〈0;f〉
-        }
       }
     }
   }
@@ -517,8 +515,6 @@
       // [structural cycle]
       g: (_|_){
         // [structural cycle] a3.f.g: structural cycle
-        g: (_|_){// 〈1;f〉
-        }
       }
     }
   }
@@ -630,8 +626,6 @@
         // [structural cycle]
         0: (_|_){
           // [structural cycle] b6.x.a.0: structural cycle
-          0: (_|_){// 〈0;a〉
-          }
         }
       }
     }
@@ -752,8 +746,6 @@
         //     ./in.cue:144:10
         tail: (_|_){
           // [structural cycle] b12b.#list.tail.tail: structural cycle
-          tail: (_|_){// 〈1;#list〉
-          }
         }
       }
     }
@@ -776,10 +768,6 @@
           // [structural cycle]
           0: (_|_){
             // [structural cycle] b13.root.a.0.0: structural cycle
-            0: (_|_){// {
-              //   〈1;x〉
-              // }
-            }
           }
         }
       }
@@ -801,14 +789,6 @@
           }
           1: (_|_){
             // [structural cycle] b14.root.b.1.1: structural cycle
-            0: (_|_){// {
-              //   〈1;x〉
-              // }
-            }
-            1: (_|_){// {
-              //   〈1;x〉
-              // }
-            }
           }
         }
       }
@@ -852,14 +832,6 @@
           // [structural cycle]
           link: (_|_){
             // [structural cycle] p2.#T.a.b.link: structural cycle
-            a: (_|_){// {
-              //   [string]: {
-              //     link: 〈3;#T〉
-              //   }
-              // } & {
-              //   b: {}
-              // }
-            }
           }
         }
       }
@@ -896,14 +868,6 @@
             // [structural cycle]
             link: (_|_){
               // [structural cycle] p3.#U.#T.a.b.link: structural cycle
-              a: (_|_){// {
-                //   [string]: {
-                //     link: 〈3;#T〉
-                //   }
-                // } & {
-                //   b: {}
-                // }
-              }
             }
           }
         }
@@ -955,14 +919,6 @@
           // [structural cycle]
           link: (_|_){
             // [structural cycle] p5.#T.a.0.link: structural cycle
-            a: (_|_){// [
-              //   ...{
-              //     link: 〈2;#T〉
-              //   },
-              // ] & [
-              //   {},
-              // ]
-            }
           }
         }
       }
@@ -999,14 +955,6 @@
             // [structural cycle]
             link: (_|_){
               // [structural cycle] p6.#U.#T.a.0.link: structural cycle
-              a: (_|_){// [
-                //   ...{
-                //     link: 〈2;#T〉
-                //   },
-                // ] & [
-                //   {},
-                // ]
-              }
             }
           }
         }
@@ -1038,10 +986,6 @@
         }
         c: (_|_){
           // [structural cycle] c1.a.c.c: structural cycle
-          b: (_|_){// {}
-          }
-          c: (_|_){// (〈1;a〉 & 〈0;b〉)
-          }
         }
       }
     }
@@ -1059,13 +1003,6 @@
             h: (int){ int }
             t: (_|_){
               // [structural cycle] d1.a.b.c.d.t: structural cycle
-              c: (_|_){// {
-                //   d: {
-                //     h: int
-                //     t: 〈4;r〉
-                //   }
-                // }
-              }
             }
           }
         }
@@ -1162,16 +1099,12 @@
       // [structural cycle]
       c: (_|_){
         // [structural cycle] e1.a.c: structural cycle
-        c: (_|_){// 〈1;a〉
-        }
       }
     }
     b: (_|_){
       // [structural cycle]
       c: (_|_){
         // [structural cycle] e1.b.c: structural cycle
-        c: (_|_){// 〈1;b〉
-        }
       }
     }
   }
@@ -1181,16 +1114,12 @@
       // [structural cycle]
       c: (_|_){
         // [structural cycle] e2.a.c: structural cycle
-        c: (_|_){// 〈1;a〉
-        }
       }
     }
     b: (_|_){
       // [structural cycle]
       c: (_|_){
         // [structural cycle] e2.b.c: structural cycle
-        c: (_|_){// 〈1;b〉
-        }
       }
     }
   }
@@ -1206,10 +1135,6 @@
         //     ./in.cue:309:8
         //     ./in.cue:309:11
         // e3.a.c: structural cycle
-        c: (_|_){// 〈1;a〉
-        }
-        0: (_|_){// 〈0;a〉
-        }
       }
       0: (_|_){
         // [eval] e3.a.0: conflicting values [a] and {c:a} (mismatched types list and struct):
@@ -1217,10 +1142,6 @@
         //     ./in.cue:308:9
         //     ./in.cue:309:8
         // e3.a.0: structural cycle
-        c: (_|_){// 〈1;a〉
-        }
-        0: (_|_){// 〈0;a〉
-        }
       }
     }
     b: (_|_){
@@ -1233,10 +1154,6 @@
         //     ./in.cue:312:8
         //     ./in.cue:312:11
         // e3.b.c: structural cycle
-        c: (_|_){// 〈1;b〉
-        }
-        0: (_|_){// 〈0;b〉
-        }
       }
       0: (_|_){
         // [eval] e3.b.0: conflicting values [b] and {c:b} (mismatched types list and struct):
@@ -1244,10 +1161,6 @@
         //     ./in.cue:311:9
         //     ./in.cue:312:8
         // e3.b.0: structural cycle
-        c: (_|_){// 〈1;b〉
-        }
-        0: (_|_){// 〈0;b〉
-        }
       }
     }
   }
diff --git a/internal/core/adt/eval.go b/internal/core/adt/eval.go
index 766f339..a194e9e 100644
--- a/internal/core/adt/eval.go
+++ b/internal/core/adt/eval.go
@@ -558,6 +558,9 @@
 				Value: n.node.Value(),
 				// TODO: probably, this should have the referenced arc.
 			})
+		// Don't process Arcs. This is mostly to ensure that no Arcs with
+		// an Unprocessed status remain in the output.
+		n.node.Arcs = nil
 	} else {
 		// Visit arcs recursively to validate and compute error.
 		for _, a := range n.node.Arcs {