...

Text file src/cuelang.org/go/cue/testdata/cycle/freeze.txtar

Documentation: cuelang.org/go/cue/testdata/cycle

     1// This files tests that values are properly "frozen" in case of mutual
     2// references. Non-structural cyclic references are okay, as long a property
     3// that is dependended upon in the cycle is not changed after the fact,
     4// that is, a value may not become more specific after it is used.
     5-- in.cue --
     6freezing: t1: ok: {
     7	#a: x: "a"
     8	len(#a) // 1
     9}
    10
    11-- comprehension.cue --
    12// This should be an incomplete error, as z is inserted in x, over which the
    13// comprehension loops. Adding a field z to x would fix this.
    14// This test would fail in the old evaluator, depending on ordering.
    15comprehension: t1: _
    16comprehension: t1: ok: p0: {
    17	x: y: {}
    18	// order of comprehensions matter in old evaluator.
    19	for _ in x {
    20		if true { x: z: a: {} }
    21	}
    22	if true {
    23		if true { x: z: a: {} }
    24	}
    25}
    26
    27comprehension: t1: ok: p1: {
    28	for _ in x {
    29		if true { x: z: a: {} }
    30	}
    31	x: y: {}
    32	if true {
    33		if true { x: z: a: {} }
    34	}
    35}
    36
    37comprehension: t1: ok: p2: {
    38	for _ in x {
    39		if true { x: z: a: {} }
    40	}
    41	if true {
    42		if true { x: z: a: {} }
    43	}
    44	x: y: {}
    45}
    46
    47comprehension: t1: ok: p3: {
    48	x: y: {}
    49	if true {
    50		if true { x: z: a: {} }
    51	}
    52	for _ in x {
    53		if true { x: z: a: {} }
    54	}
    55}
    56
    57comprehension: t1: ok: p4: {
    58	if true {
    59		if true { x: z: a: {} }
    60	}
    61	x: y: {}
    62	for _ in x {
    63		if true { x: z: a: {} }
    64	}
    65}
    66
    67comprehension: t1: ok: p5: {
    68	if true {
    69		if true { x: z: a: {} }
    70	}
    71	for _ in x {
    72		if true { x: z: a: {} }
    73	}
    74	x: y: {}
    75}
    76
    77
    78comprehension: t2: err: {
    79	a: {
    80		x: 1
    81		for k, v in a {
    82			(k+"q"): v // This increases the set of fields in a.
    83		}
    84	}
    85}
    86
    87comprehension: t3: err: {
    88	// mutual dependencies not okay in this case, as the set of fields grows.
    89	a: x: 1
    90	b: y: 1
    91	a: {
    92		for k, v in b {
    93			(k+"q"): v
    94		}
    95	}
    96	b: {
    97		for k, v in a {
    98			(k): v
    99		}
   100	}
   101}
   102
   103comprehension: t4: ok: {
   104	// It is okay to make x more specific as long as no fields are added.
   105	x: y: {}
   106	for _ in x {
   107		if true { x: y: a: {} }
   108	}
   109}
   110
   111comprehension: moreSpecific: ok: {
   112	a: {
   113		x: int
   114		for k, v in a {
   115			(k): 1
   116		}
   117	}
   118}
   119
   120comprehension: moreSpecific: err: {
   121	a: {
   122		x: {y: 1}
   123		// len(v) should free the size of x.
   124		for k, v in a if len(v) > 0 {
   125			(k): {z: 1}
   126		}
   127	}
   128}
   129-- out/eval/stats --
   130Leaks:  0
   131Freed:  67
   132Reused: 59
   133Allocs: 8
   134Retain: 12
   135
   136Unifications: 67
   137Conjuncts:    119
   138Disjuncts:    76
   139-- out/evalalpha --
   140Errors:
   141comprehension.t2.err.a: field xq not allowed by earlier comprehension or reference cycle:
   142    ./comprehension.cue:71:13
   143comprehension.t3.err.a: field xq not allowed by earlier comprehension or reference cycle:
   144    ./comprehension.cue:82:13
   145comprehension.moreSpecific.err.a: field z not allowed by earlier comprehension or reference cycle:
   146    ./comprehension.cue:114:9
   147
   148Result:
   149(_|_){
   150  // [eval]
   151  comprehension: (_|_){
   152    // [eval]
   153    t1: (struct){
   154      ok: (struct){
   155        p0: (_|_){
   156          // [incomplete] comprehension.t1.ok.p0: cyclic reference to field z:
   157          //     ./comprehension.cue:9:3
   158          // comprehension.t1.ok.p0.x.z.a: cyclic reference to field z:
   159          //     ./comprehension.cue:12:3
   160          x: (struct){
   161            y: (struct){
   162            }
   163          }
   164        }
   165        p1: (_|_){
   166          // [incomplete] comprehension.t1.ok.p1: cyclic reference to field z:
   167          //     ./comprehension.cue:18:3
   168          // comprehension.t1.ok.p1.x.z.a: cyclic reference to field z:
   169          //     ./comprehension.cue:22:3
   170          x: (struct){
   171            y: (struct){
   172            }
   173          }
   174        }
   175        p2: (_|_){
   176          // [incomplete] comprehension.t1.ok.p2: cyclic reference to field z:
   177          //     ./comprehension.cue:28:3
   178          // comprehension.t1.ok.p2.x.z.a: cyclic reference to field z:
   179          //     ./comprehension.cue:31:3
   180          x: (struct){
   181            y: (struct){
   182            }
   183          }
   184        }
   185        p3: (_|_){
   186          // [incomplete] comprehension.t1.ok.p3.x.z.a: cyclic reference to field z:
   187          //     ./comprehension.cue:39:3
   188          // comprehension.t1.ok.p3: cyclic reference to field z:
   189          //     ./comprehension.cue:42:3
   190          x: (struct){
   191            y: (struct){
   192            }
   193          }
   194        }
   195        p4: (_|_){
   196          // [incomplete] comprehension.t1.ok.p4.x.z.a: cyclic reference to field z:
   197          //     ./comprehension.cue:48:3
   198          // comprehension.t1.ok.p4: cyclic reference to field z:
   199          //     ./comprehension.cue:52:3
   200          x: (struct){
   201            y: (struct){
   202            }
   203          }
   204        }
   205        p5: (_|_){
   206          // [incomplete] comprehension.t1.ok.p5.x.z.a: cyclic reference to field z:
   207          //     ./comprehension.cue:58:3
   208          // comprehension.t1.ok.p5: cyclic reference to field z:
   209          //     ./comprehension.cue:61:3
   210          x: (struct){
   211            y: (struct){
   212            }
   213          }
   214        }
   215      }
   216    }
   217    t2: (_|_){
   218      // [eval]
   219      err: (_|_){
   220        // [eval]
   221        a: (_|_){
   222          // [eval] comprehension.t2.err.a: field xq not allowed by earlier comprehension or reference cycle:
   223          //     ./comprehension.cue:71:13
   224          x: (int){ 1 }
   225        }
   226      }
   227    }
   228    t3: (_|_){
   229      // [eval]
   230      err: (_|_){
   231        // [eval]
   232        a: (_|_){
   233          // [eval] comprehension.t3.err.a: field xq not allowed by earlier comprehension or reference cycle:
   234          //     ./comprehension.cue:82:13
   235          x: (int){ 1 }
   236        }
   237        b: (struct){
   238          y: (int){ 1 }
   239          x: (int){ 1 }
   240        }
   241      }
   242    }
   243    t4: (struct){
   244      ok: (struct){
   245        x: (struct){
   246          y: (struct){
   247            a: (struct){
   248            }
   249          }
   250        }
   251      }
   252    }
   253    moreSpecific: (_|_){
   254      // [eval]
   255      ok: (struct){
   256        a: (struct){
   257          x: (int){ 1 }
   258        }
   259      }
   260      err: (_|_){
   261        // [eval]
   262        a: (_|_){
   263          // [eval] comprehension.moreSpecific.err.a: field z not allowed by earlier comprehension or reference cycle:
   264          //     ./comprehension.cue:114:9
   265          x: (struct){
   266            y: (int){ 1 }
   267          }
   268        }
   269      }
   270    }
   271  }
   272  freezing: (struct){
   273    t1: (struct){
   274      ok: (int){
   275        1
   276        #a: (#struct){
   277          x: (string){ "a" }
   278        }
   279      }
   280    }
   281  }
   282}
   283-- diff/-out/evalalpha<==>+out/eval --
   284diff old new
   285--- old
   286+++ new
   287@@ -1,11 +1,10 @@
   288 Errors:
   289-comprehension.moreSpecific.err.a: field z not allowed by earlier comprehension or reference cycle
   290-comprehension.t1.ok.p0.x: field z not allowed by earlier comprehension or reference cycle
   291-comprehension.t1.ok.p1.x: field z not allowed by earlier comprehension or reference cycle
   292-comprehension.t1.ok.p2.x: field z not allowed by earlier comprehension or reference cycle
   293-comprehension.t2.err.a: field xq not allowed by earlier comprehension or reference cycle
   294-comprehension.t3.err.b: field x not allowed by earlier comprehension or reference cycle
   295-comprehension.t3.err.b: field yq not allowed by earlier comprehension or reference cycle
   296+comprehension.t2.err.a: field xq not allowed by earlier comprehension or reference cycle:
   297+    ./comprehension.cue:71:13
   298+comprehension.t3.err.a: field xq not allowed by earlier comprehension or reference cycle:
   299+    ./comprehension.cue:82:13
   300+comprehension.moreSpecific.err.a: field z not allowed by earlier comprehension or reference cycle:
   301+    ./comprehension.cue:114:9
   302 
   303 Result:
   304 (_|_){
   305@@ -12,73 +11,65 @@
   306   // [eval]
   307   comprehension: (_|_){
   308     // [eval]
   309-    t1: (_|_){
   310-      // [eval]
   311-      ok: (_|_){
   312-        // [eval]
   313+    t1: (struct){
   314+      ok: (struct){
   315         p0: (_|_){
   316-          // [eval]
   317-          x: (_|_){
   318-            // [eval] comprehension.t1.ok.p0.x: field z not allowed by earlier comprehension or reference cycle
   319-            y: (struct){
   320-            }
   321-            z: (struct){
   322-              a: (struct){
   323-              }
   324+          // [incomplete] comprehension.t1.ok.p0: cyclic reference to field z:
   325+          //     ./comprehension.cue:9:3
   326+          // comprehension.t1.ok.p0.x.z.a: cyclic reference to field z:
   327+          //     ./comprehension.cue:12:3
   328+          x: (struct){
   329+            y: (struct){
   330             }
   331           }
   332         }
   333         p1: (_|_){
   334-          // [eval]
   335-          x: (_|_){
   336-            // [eval] comprehension.t1.ok.p1.x: field z not allowed by earlier comprehension or reference cycle
   337-            y: (struct){
   338-            }
   339-            z: (struct){
   340-              a: (struct){
   341-              }
   342+          // [incomplete] comprehension.t1.ok.p1: cyclic reference to field z:
   343+          //     ./comprehension.cue:18:3
   344+          // comprehension.t1.ok.p1.x.z.a: cyclic reference to field z:
   345+          //     ./comprehension.cue:22:3
   346+          x: (struct){
   347+            y: (struct){
   348             }
   349           }
   350         }
   351         p2: (_|_){
   352-          // [eval]
   353-          x: (_|_){
   354-            // [eval] comprehension.t1.ok.p2.x: field z not allowed by earlier comprehension or reference cycle
   355-            y: (struct){
   356-            }
   357-            z: (struct){
   358-              a: (struct){
   359-              }
   360-            }
   361-          }
   362-        }
   363-        p3: (struct){
   364-          x: (struct){
   365-            y: (struct){
   366-            }
   367-            z: (struct){
   368-              a: (struct){
   369-              }
   370-            }
   371-          }
   372-        }
   373-        p4: (struct){
   374-          x: (struct){
   375-            y: (struct){
   376-            }
   377-            z: (struct){
   378-              a: (struct){
   379-              }
   380-            }
   381-          }
   382-        }
   383-        p5: (struct){
   384-          x: (struct){
   385-            y: (struct){
   386-            }
   387-            z: (struct){
   388-              a: (struct){
   389-              }
   390+          // [incomplete] comprehension.t1.ok.p2: cyclic reference to field z:
   391+          //     ./comprehension.cue:28:3
   392+          // comprehension.t1.ok.p2.x.z.a: cyclic reference to field z:
   393+          //     ./comprehension.cue:31:3
   394+          x: (struct){
   395+            y: (struct){
   396+            }
   397+          }
   398+        }
   399+        p3: (_|_){
   400+          // [incomplete] comprehension.t1.ok.p3.x.z.a: cyclic reference to field z:
   401+          //     ./comprehension.cue:39:3
   402+          // comprehension.t1.ok.p3: cyclic reference to field z:
   403+          //     ./comprehension.cue:42:3
   404+          x: (struct){
   405+            y: (struct){
   406+            }
   407+          }
   408+        }
   409+        p4: (_|_){
   410+          // [incomplete] comprehension.t1.ok.p4.x.z.a: cyclic reference to field z:
   411+          //     ./comprehension.cue:48:3
   412+          // comprehension.t1.ok.p4: cyclic reference to field z:
   413+          //     ./comprehension.cue:52:3
   414+          x: (struct){
   415+            y: (struct){
   416+            }
   417+          }
   418+        }
   419+        p5: (_|_){
   420+          // [incomplete] comprehension.t1.ok.p5.x.z.a: cyclic reference to field z:
   421+          //     ./comprehension.cue:58:3
   422+          // comprehension.t1.ok.p5: cyclic reference to field z:
   423+          //     ./comprehension.cue:61:3
   424+          x: (struct){
   425+            y: (struct){
   426             }
   427           }
   428         }
   429@@ -89,9 +80,9 @@
   430       err: (_|_){
   431         // [eval]
   432         a: (_|_){
   433-          // [eval] comprehension.t2.err.a: field xq not allowed by earlier comprehension or reference cycle
   434-          x: (int){ 1 }
   435-          xq: (int){ 1 }
   436+          // [eval] comprehension.t2.err.a: field xq not allowed by earlier comprehension or reference cycle:
   437+          //     ./comprehension.cue:71:13
   438+          x: (int){ 1 }
   439         }
   440       }
   441     }
   442@@ -99,16 +90,14 @@
   443       // [eval]
   444       err: (_|_){
   445         // [eval]
   446-        a: (struct){
   447-          x: (int){ 1 }
   448-          yq: (int){ 1 }
   449-        }
   450-        b: (_|_){
   451-          // [eval] comprehension.t3.err.b: field x not allowed by earlier comprehension or reference cycle
   452-          // comprehension.t3.err.b: field yq not allowed by earlier comprehension or reference cycle
   453+        a: (_|_){
   454+          // [eval] comprehension.t3.err.a: field xq not allowed by earlier comprehension or reference cycle:
   455+          //     ./comprehension.cue:82:13
   456+          x: (int){ 1 }
   457+        }
   458+        b: (struct){
   459           y: (int){ 1 }
   460           x: (int){ 1 }
   461-          yq: (int){ 1 }
   462         }
   463       }
   464     }
   465@@ -132,10 +121,10 @@
   466       err: (_|_){
   467         // [eval]
   468         a: (_|_){
   469-          // [eval] comprehension.moreSpecific.err.a: field z not allowed by earlier comprehension or reference cycle
   470+          // [eval] comprehension.moreSpecific.err.a: field z not allowed by earlier comprehension or reference cycle:
   471+          //     ./comprehension.cue:114:9
   472           x: (struct){
   473             y: (int){ 1 }
   474-            z: (int){ 1 }
   475           }
   476         }
   477       }
   478-- diff/explanation --
   479v0.7 fixes bugs in v0.6:
   480- t1 should be incomplete error, as it is fixable.
   481-- out/eval --
   482Errors:
   483comprehension.moreSpecific.err.a: field z not allowed by earlier comprehension or reference cycle
   484comprehension.t1.ok.p0.x: field z not allowed by earlier comprehension or reference cycle
   485comprehension.t1.ok.p1.x: field z not allowed by earlier comprehension or reference cycle
   486comprehension.t1.ok.p2.x: field z not allowed by earlier comprehension or reference cycle
   487comprehension.t2.err.a: field xq not allowed by earlier comprehension or reference cycle
   488comprehension.t3.err.b: field x not allowed by earlier comprehension or reference cycle
   489comprehension.t3.err.b: field yq not allowed by earlier comprehension or reference cycle
   490
   491Result:
   492(_|_){
   493  // [eval]
   494  comprehension: (_|_){
   495    // [eval]
   496    t1: (_|_){
   497      // [eval]
   498      ok: (_|_){
   499        // [eval]
   500        p0: (_|_){
   501          // [eval]
   502          x: (_|_){
   503            // [eval] comprehension.t1.ok.p0.x: field z not allowed by earlier comprehension or reference cycle
   504            y: (struct){
   505            }
   506            z: (struct){
   507              a: (struct){
   508              }
   509            }
   510          }
   511        }
   512        p1: (_|_){
   513          // [eval]
   514          x: (_|_){
   515            // [eval] comprehension.t1.ok.p1.x: field z not allowed by earlier comprehension or reference cycle
   516            y: (struct){
   517            }
   518            z: (struct){
   519              a: (struct){
   520              }
   521            }
   522          }
   523        }
   524        p2: (_|_){
   525          // [eval]
   526          x: (_|_){
   527            // [eval] comprehension.t1.ok.p2.x: field z not allowed by earlier comprehension or reference cycle
   528            y: (struct){
   529            }
   530            z: (struct){
   531              a: (struct){
   532              }
   533            }
   534          }
   535        }
   536        p3: (struct){
   537          x: (struct){
   538            y: (struct){
   539            }
   540            z: (struct){
   541              a: (struct){
   542              }
   543            }
   544          }
   545        }
   546        p4: (struct){
   547          x: (struct){
   548            y: (struct){
   549            }
   550            z: (struct){
   551              a: (struct){
   552              }
   553            }
   554          }
   555        }
   556        p5: (struct){
   557          x: (struct){
   558            y: (struct){
   559            }
   560            z: (struct){
   561              a: (struct){
   562              }
   563            }
   564          }
   565        }
   566      }
   567    }
   568    t2: (_|_){
   569      // [eval]
   570      err: (_|_){
   571        // [eval]
   572        a: (_|_){
   573          // [eval] comprehension.t2.err.a: field xq not allowed by earlier comprehension or reference cycle
   574          x: (int){ 1 }
   575          xq: (int){ 1 }
   576        }
   577      }
   578    }
   579    t3: (_|_){
   580      // [eval]
   581      err: (_|_){
   582        // [eval]
   583        a: (struct){
   584          x: (int){ 1 }
   585          yq: (int){ 1 }
   586        }
   587        b: (_|_){
   588          // [eval] comprehension.t3.err.b: field x not allowed by earlier comprehension or reference cycle
   589          // comprehension.t3.err.b: field yq not allowed by earlier comprehension or reference cycle
   590          y: (int){ 1 }
   591          x: (int){ 1 }
   592          yq: (int){ 1 }
   593        }
   594      }
   595    }
   596    t4: (struct){
   597      ok: (struct){
   598        x: (struct){
   599          y: (struct){
   600            a: (struct){
   601            }
   602          }
   603        }
   604      }
   605    }
   606    moreSpecific: (_|_){
   607      // [eval]
   608      ok: (struct){
   609        a: (struct){
   610          x: (int){ 1 }
   611        }
   612      }
   613      err: (_|_){
   614        // [eval]
   615        a: (_|_){
   616          // [eval] comprehension.moreSpecific.err.a: field z not allowed by earlier comprehension or reference cycle
   617          x: (struct){
   618            y: (int){ 1 }
   619            z: (int){ 1 }
   620          }
   621        }
   622      }
   623    }
   624  }
   625  freezing: (struct){
   626    t1: (struct){
   627      ok: (int){
   628        1
   629        #a: (#struct){
   630          x: (string){ "a" }
   631        }
   632      }
   633    }
   634  }
   635}
   636-- out/compile --
   637--- comprehension.cue
   638{
   639  comprehension: {
   640    t1: _
   641  }
   642  comprehension: {
   643    t1: {
   644      ok: {
   645        p0: {
   646          x: {
   647            y: {}
   648          }
   649          for _, _ in 〈0;x〉 {
   650            if true {
   651              x: {
   652                z: {
   653                  a: {}
   654                }
   655              }
   656            }
   657          }
   658          if true {
   659            if true {
   660              x: {
   661                z: {
   662                  a: {}
   663                }
   664              }
   665            }
   666          }
   667        }
   668      }
   669    }
   670  }
   671  comprehension: {
   672    t1: {
   673      ok: {
   674        p1: {
   675          for _, _ in 〈0;x〉 {
   676            if true {
   677              x: {
   678                z: {
   679                  a: {}
   680                }
   681              }
   682            }
   683          }
   684          x: {
   685            y: {}
   686          }
   687          if true {
   688            if true {
   689              x: {
   690                z: {
   691                  a: {}
   692                }
   693              }
   694            }
   695          }
   696        }
   697      }
   698    }
   699  }
   700  comprehension: {
   701    t1: {
   702      ok: {
   703        p2: {
   704          for _, _ in 〈0;x〉 {
   705            if true {
   706              x: {
   707                z: {
   708                  a: {}
   709                }
   710              }
   711            }
   712          }
   713          if true {
   714            if true {
   715              x: {
   716                z: {
   717                  a: {}
   718                }
   719              }
   720            }
   721          }
   722          x: {
   723            y: {}
   724          }
   725        }
   726      }
   727    }
   728  }
   729  comprehension: {
   730    t1: {
   731      ok: {
   732        p3: {
   733          x: {
   734            y: {}
   735          }
   736          if true {
   737            if true {
   738              x: {
   739                z: {
   740                  a: {}
   741                }
   742              }
   743            }
   744          }
   745          for _, _ in 〈0;x〉 {
   746            if true {
   747              x: {
   748                z: {
   749                  a: {}
   750                }
   751              }
   752            }
   753          }
   754        }
   755      }
   756    }
   757  }
   758  comprehension: {
   759    t1: {
   760      ok: {
   761        p4: {
   762          if true {
   763            if true {
   764              x: {
   765                z: {
   766                  a: {}
   767                }
   768              }
   769            }
   770          }
   771          x: {
   772            y: {}
   773          }
   774          for _, _ in 〈0;x〉 {
   775            if true {
   776              x: {
   777                z: {
   778                  a: {}
   779                }
   780              }
   781            }
   782          }
   783        }
   784      }
   785    }
   786  }
   787  comprehension: {
   788    t1: {
   789      ok: {
   790        p5: {
   791          if true {
   792            if true {
   793              x: {
   794                z: {
   795                  a: {}
   796                }
   797              }
   798            }
   799          }
   800          for _, _ in 〈0;x〉 {
   801            if true {
   802              x: {
   803                z: {
   804                  a: {}
   805                }
   806              }
   807            }
   808          }
   809          x: {
   810            y: {}
   811          }
   812        }
   813      }
   814    }
   815  }
   816  comprehension: {
   817    t2: {
   818      err: {
   819        a: {
   820          x: 1
   821          for k, v in 〈1;a〉 {
   822            (〈1;k〉 + "q"): 〈1;v〉
   823          }
   824        }
   825      }
   826    }
   827  }
   828  comprehension: {
   829    t3: {
   830      err: {
   831        a: {
   832          x: 1
   833        }
   834        b: {
   835          y: 1
   836        }
   837        a: {
   838          for k, v in 〈1;b〉 {
   839            (〈1;k〉 + "q"): 〈1;v〉
   840          }
   841        }
   842        b: {
   843          for k, v in 〈1;a〉 {
   844            〈1;k〉: 〈1;v〉
   845          }
   846        }
   847      }
   848    }
   849  }
   850  comprehension: {
   851    t4: {
   852      ok: {
   853        x: {
   854          y: {}
   855        }
   856        for _, _ in 〈0;x〉 {
   857          if true {
   858            x: {
   859              y: {
   860                a: {}
   861              }
   862            }
   863          }
   864        }
   865      }
   866    }
   867  }
   868  comprehension: {
   869    moreSpecific: {
   870      ok: {
   871        a: {
   872          x: int
   873          for k, v in 〈1;a〉 {
   874            〈1;k〉: 1
   875          }
   876        }
   877      }
   878    }
   879  }
   880  comprehension: {
   881    moreSpecific: {
   882      err: {
   883        a: {
   884          x: {
   885            y: 1
   886          }
   887          for k, v in 〈1;a〉 if (len(〈0;v〉) > 0) {
   888            〈1;k〉: {
   889              z: 1
   890            }
   891          }
   892        }
   893      }
   894    }
   895  }
   896}
   897--- in.cue
   898{
   899  freezing: {
   900    t1: {
   901      ok: {
   902        #a: {
   903          x: "a"
   904        }
   905        len(〈0;#a〉)
   906      }
   907    }
   908  }
   909}

View as plain text