cuelang.org/go@v0.13.0/cue/testdata/basicrewrite/018_self-reference_cycles.txtar (about)

     1  #name: self-reference cycles
     2  #evalPartial
     3  -- in.cue --
     4  a: b - 100
     5  b: a + 100
     6  
     7  c: [c[1], c[0]]
     8  
     9  d: e - 1
    10  e: 1 + d
    11  e: *2 | 0
    12  -- disjunction.cue --
    13  oneway: {
    14      t1: {
    15          a: *1 | int
    16          a: b + 1
    17          b: <a
    18      }
    19      t2: t1 & {
    20          a: 3
    21      }
    22  }
    23  // This should report a cycle error. TODO: this should also resolve.
    24  issue3669: {
    25  	#Schema: {
    26  		two: 1 + one
    27  		one: two - 1
    28  	}
    29  
    30  	out: #Schema & {
    31  		two: 0 | *2
    32  	}
    33  }
    34  -- issue3737.cue --
    35  issue3737: reduced1: {
    36      #A: {
    37          a: b * 12
    38          b: a / 12
    39      }
    40  
    41      x: #A
    42      x: b: 1000.0
    43  
    44      y: #A | *x
    45      y: b: x.b * 0.7
    46  }
    47  issue3737: reduced2: {
    48      x: #TimeSpan & {
    49          start: y.start
    50          end: 1000.0
    51      }
    52      y: #TimeSpan & {
    53          duration: 100.0
    54          end: x.end
    55      }
    56      #TimeSpan: {
    57          start:    end - duration
    58          duration: end - start
    59          end:      start + duration
    60      }
    61  }
    62  -- out/def --
    63  a: b - 100
    64  b: a + 100
    65  c: [c[1], c[0]]
    66  -- out/legacy-debug --
    67  <0>{a: (<1>.b - 100), b: (<1>.a + 100), c: [<1>.c[1],<1>.c[0]]}
    68  -- out/compile --
    69  --- disjunction.cue
    70  {
    71    oneway: {
    72      t1: {
    73        a: (*1|int)
    74        a: (〈0;b〉 + 1)
    75        b: <〈0;a〉
    76      }
    77      t2: (〈0;t1〉 & {
    78        a: 3
    79      })
    80    }
    81    issue3669: {
    82      #Schema: {
    83        two: (1 + 〈0;one〉)
    84        one: (〈0;two〉 - 1)
    85      }
    86      out: (〈0;#Schema〉 & {
    87        two: (0|*2)
    88      })
    89    }
    90  }
    91  --- in.cue
    92  {
    93    a: (〈0;b〉 - 100)
    94    b: (〈0;a〉 + 100)
    95    c: [
    96      〈1;c〉[1],
    97      〈1;c〉[0],
    98    ]
    99    d: (〈0;e〉 - 1)
   100    e: (1 + 〈0;d〉)
   101    e: (*2|0)
   102  }
   103  --- issue3737.cue
   104  {
   105    issue3737: {
   106      reduced1: {
   107        #A: {
   108          a: (〈0;b〉 * 12)
   109          b: (〈0;a〉 / 12)
   110        }
   111        x: 〈0;#A〉
   112        x: {
   113          b: 1000.0
   114        }
   115        y: (〈0;#A〉|*〈0;x〉)
   116        y: {
   117          b: (〈1;x〉.b * 0.7)
   118        }
   119      }
   120    }
   121    issue3737: {
   122      reduced2: {
   123        x: (〈0;#TimeSpan〉 & {
   124          start: 〈1;y〉.start
   125          end: 1000.0
   126        })
   127        y: (〈0;#TimeSpan〉 & {
   128          duration: 100.0
   129          end: 〈1;x〉.end
   130        })
   131        #TimeSpan: {
   132          start: (〈0;end〉 - 〈0;duration〉)
   133          duration: (〈0;end〉 - 〈0;start〉)
   134          end: (〈0;start〉 + 〈0;duration〉)
   135        }
   136      }
   137    }
   138  }
   139  -- out/evalalpha/stats --
   140  Leaks:  59
   141  Freed:  0
   142  Reused: 0
   143  Allocs: 59
   144  Retain: 0
   145  
   146  Unifications: 47
   147  Conjuncts:    91
   148  Disjuncts:    10
   149  
   150  CloseIDElems: 17
   151  NumCloseIDs: 10
   152  -- diff/-out/evalalpha/stats<==>+out/eval/stats --
   153  diff old new
   154  --- old
   155  +++ new
   156  @@ -1,9 +1,12 @@
   157  -Leaks:  1
   158  -Freed:  57
   159  -Reused: 46
   160  -Allocs: 12
   161  -Retain: 166
   162  -
   163  -Unifications: 48
   164  -Conjuncts:    285
   165  -Disjuncts:    88
   166  +Leaks:  59
   167  +Freed:  0
   168  +Reused: 0
   169  +Allocs: 59
   170  +Retain: 0
   171  +
   172  +Unifications: 47
   173  +Conjuncts:    91
   174  +Disjuncts:    10
   175  +
   176  +CloseIDElems: 17
   177  +NumCloseIDs: 10
   178  -- out/eval/stats --
   179  Leaks:  1
   180  Freed:  57
   181  Reused: 46
   182  Allocs: 12
   183  Retain: 166
   184  
   185  Unifications: 48
   186  Conjuncts:    285
   187  Disjuncts:    88
   188  -- out/evalalpha --
   189  (struct){
   190    oneway: (struct){
   191      t1: (struct){
   192        a: (_|_){
   193          // [cycle] oneway.t1.a: cycle with field: b:
   194          //     ./disjunction.cue:4:12
   195          // oneway.t1.b: cycle with field: a:
   196          //     ./disjunction.cue:5:13
   197        }
   198        b: (_|_){
   199          // [cycle] oneway.t1.a: cycle with field: b:
   200          //     ./disjunction.cue:4:12
   201          // oneway.t1.b: cycle with field: a:
   202          //     ./disjunction.cue:5:13
   203        }
   204      }
   205      t2: (struct){
   206        a: (_|_){
   207          // [incomplete] oneway.t2.a: 2 errors in empty disjunction:
   208          // oneway.t2.a: conflicting values 1 and 3:
   209          //     ./disjunction.cue:3:13
   210          //     ./disjunction.cue:8:12
   211          // oneway.t2.a: non-concrete value <3 in operand to +:
   212          //     ./disjunction.cue:4:12
   213          //     ./disjunction.cue:5:12
   214        }
   215        b: (number){ <3 }
   216      }
   217    }
   218    issue3669: (struct){
   219      #Schema: (#struct){
   220        two: (_|_){
   221          // [cycle] issue3669.#Schema.two: cycle with field: one:
   222          //     ./disjunction.cue:14:12
   223          // issue3669.#Schema.one: cycle with field: two:
   224          //     ./disjunction.cue:15:8
   225        }
   226        one: (_|_){
   227          // [cycle] issue3669.#Schema.two: cycle with field: one:
   228          //     ./disjunction.cue:14:12
   229          // issue3669.#Schema.one: cycle with field: two:
   230          //     ./disjunction.cue:15:8
   231        }
   232      }
   233      out: (#struct){
   234        two: (_|_){
   235          // [cycle] issue3669.out.two: cycle with field: one:
   236          //     ./disjunction.cue:14:12
   237          // issue3669.out.one: cycle with field: two:
   238          //     ./disjunction.cue:15:8
   239        }
   240        one: (_|_){
   241          // [cycle] issue3669.out.two: cycle with field: one:
   242          //     ./disjunction.cue:14:12
   243          // issue3669.out.one: cycle with field: two:
   244          //     ./disjunction.cue:15:8
   245        }
   246      }
   247    }
   248    a: (_|_){
   249      // [cycle] a: cycle with field: b:
   250      //     ./in.cue:1:4
   251      // b: cycle with field: a:
   252      //     ./in.cue:2:4
   253    }
   254    b: (_|_){
   255      // [cycle] a: cycle with field: b:
   256      //     ./in.cue:1:4
   257      // b: cycle with field: a:
   258      //     ./in.cue:2:4
   259    }
   260    c: (#list){
   261      0: (_){ _ }
   262      1: (_){ _ }
   263    }
   264    d: (int){ 1 }
   265    e: (int){ |(*(int){ 2 }, (int){ 0 }) }
   266    issue3737: (struct){
   267      reduced1: (struct){
   268        #A: (#struct){
   269          a: (_|_){
   270            // [cycle] issue3737.reduced1.#A.a: cycle with field: b:
   271            //     ./issue3737.cue:3:12
   272            // issue3737.reduced1.#A.b: cycle with field: a:
   273            //     ./issue3737.cue:4:12
   274          }
   275          b: (_|_){
   276            // [cycle] issue3737.reduced1.#A.a: cycle with field: b:
   277            //     ./issue3737.cue:3:12
   278            // issue3737.reduced1.#A.b: cycle with field: a:
   279            //     ./issue3737.cue:4:12
   280          }
   281        }
   282        x: (#struct){
   283          b: (float){ 1000.0 }
   284          a: (float){ 12000.0 }
   285        }
   286        y: (#struct){
   287          b: (float){ 700.00 }
   288          a: (float){ 8400.00 }
   289        }
   290      }
   291      reduced2: (struct){
   292        x: (#struct){
   293          start: (float){ 900.0 }
   294          end: (float){ 1000.0 }
   295          duration: (float){ 100.0 }
   296        }
   297        y: (#struct){
   298          duration: (float){ 100.0 }
   299          end: (float){ 1000.0 }
   300          start: (float){ 900.0 }
   301        }
   302        #TimeSpan: (#struct){
   303          start: (_|_){
   304            // [cycle] issue3737.reduced2.#TimeSpan.start: cycle with field: end:
   305            //     ./issue3737.cue:23:19
   306            // issue3737.reduced2.#TimeSpan.end: cycle with field: start:
   307            //     ./issue3737.cue:25:19
   308            // issue3737.reduced2.#TimeSpan.end: cycle with field: duration:
   309            //     ./issue3737.cue:25:27
   310          }
   311          duration: (_|_){
   312            // [cycle] issue3737.reduced2.#TimeSpan.start: cycle with field: end:
   313            //     ./issue3737.cue:23:19
   314            // issue3737.reduced2.#TimeSpan.end: cycle with field: start:
   315            //     ./issue3737.cue:25:19
   316            // issue3737.reduced2.#TimeSpan.end: cycle with field: duration:
   317            //     ./issue3737.cue:25:27
   318          }
   319          end: (_|_){
   320            // [cycle] issue3737.reduced2.#TimeSpan.start: cycle with field: end:
   321            //     ./issue3737.cue:23:19
   322            // issue3737.reduced2.#TimeSpan.end: cycle with field: start:
   323            //     ./issue3737.cue:25:19
   324            // issue3737.reduced2.#TimeSpan.end: cycle with field: duration:
   325            //     ./issue3737.cue:25:27
   326          }
   327        }
   328      }
   329    }
   330  }
   331  -- diff/-out/evalalpha<==>+out/eval --
   332  diff old new
   333  --- old
   334  +++ new
   335  @@ -2,11 +2,17 @@
   336     oneway: (struct){
   337       t1: (struct){
   338         a: (_|_){
   339  -        // [incomplete] oneway.t1.a: non-concrete value <1 in operand to +:
   340  -        //     ./disjunction.cue:4:12
   341  -        //     ./disjunction.cue:5:12
   342  -      }
   343  -      b: (number){ <1 }
   344  +        // [cycle] oneway.t1.a: cycle with field: b:
   345  +        //     ./disjunction.cue:4:12
   346  +        // oneway.t1.b: cycle with field: a:
   347  +        //     ./disjunction.cue:5:13
   348  +      }
   349  +      b: (_|_){
   350  +        // [cycle] oneway.t1.a: cycle with field: b:
   351  +        //     ./disjunction.cue:4:12
   352  +        // oneway.t1.b: cycle with field: a:
   353  +        //     ./disjunction.cue:5:13
   354  +      }
   355       }
   356       t2: (struct){
   357         a: (_|_){
   358  @@ -13,7 +19,6 @@
   359           // [incomplete] oneway.t2.a: 2 errors in empty disjunction:
   360           // oneway.t2.a: conflicting values 1 and 3:
   361           //     ./disjunction.cue:3:13
   362  -        //     ./disjunction.cue:7:9
   363           //     ./disjunction.cue:8:12
   364           // oneway.t2.a: non-concrete value <3 in operand to +:
   365           //     ./disjunction.cue:4:12
   366  @@ -25,57 +30,70 @@
   367     issue3669: (struct){
   368       #Schema: (#struct){
   369         two: (_|_){
   370  -        // [cycle] cycle error:
   371  -        //     ./disjunction.cue:14:8
   372  -      }
   373  -      one: (_|_){
   374  -        // [cycle] cycle error:
   375  -        //     ./disjunction.cue:14:8
   376  +        // [cycle] issue3669.#Schema.two: cycle with field: one:
   377  +        //     ./disjunction.cue:14:12
   378  +        // issue3669.#Schema.one: cycle with field: two:
   379  +        //     ./disjunction.cue:15:8
   380  +      }
   381  +      one: (_|_){
   382  +        // [cycle] issue3669.#Schema.two: cycle with field: one:
   383  +        //     ./disjunction.cue:14:12
   384  +        // issue3669.#Schema.one: cycle with field: two:
   385  +        //     ./disjunction.cue:15:8
   386         }
   387       }
   388       out: (#struct){
   389         two: (_|_){
   390  -        // [cycle] cycle error:
   391  -        //     ./disjunction.cue:14:8
   392  -      }
   393  -      one: (int){ -1 }
   394  +        // [cycle] issue3669.out.two: cycle with field: one:
   395  +        //     ./disjunction.cue:14:12
   396  +        // issue3669.out.one: cycle with field: two:
   397  +        //     ./disjunction.cue:15:8
   398  +      }
   399  +      one: (_|_){
   400  +        // [cycle] issue3669.out.two: cycle with field: one:
   401  +        //     ./disjunction.cue:14:12
   402  +        // issue3669.out.one: cycle with field: two:
   403  +        //     ./disjunction.cue:15:8
   404  +      }
   405       }
   406     }
   407     a: (_|_){
   408  -    // [cycle] cycle error:
   409  -    //     ./in.cue:1:4
   410  +    // [cycle] a: cycle with field: b:
   411  +    //     ./in.cue:1:4
   412  +    // b: cycle with field: a:
   413  +    //     ./in.cue:2:4
   414     }
   415     b: (_|_){
   416  -    // [cycle] cycle error:
   417  -    //     ./in.cue:1:4
   418  +    // [cycle] a: cycle with field: b:
   419  +    //     ./in.cue:1:4
   420  +    // b: cycle with field: a:
   421  +    //     ./in.cue:2:4
   422     }
   423     c: (#list){
   424       0: (_){ _ }
   425       1: (_){ _ }
   426     }
   427  -  d: (_|_){
   428  -    // [cycle] cycle error:
   429  -    //     ./in.cue:6:4
   430  -  }
   431  -  e: (_|_){
   432  -    // [cycle] cycle error:
   433  -    //     ./in.cue:6:4
   434  -  }
   435  +  d: (int){ 1 }
   436  +  e: (int){ |(*(int){ 2 }, (int){ 0 }) }
   437     issue3737: (struct){
   438       reduced1: (struct){
   439         #A: (#struct){
   440           a: (_|_){
   441  -          // [cycle] cycle error:
   442  -          //     ./issue3737.cue:3:12
   443  +          // [cycle] issue3737.reduced1.#A.a: cycle with field: b:
   444  +          //     ./issue3737.cue:3:12
   445  +          // issue3737.reduced1.#A.b: cycle with field: a:
   446  +          //     ./issue3737.cue:4:12
   447           }
   448           b: (_|_){
   449  -          // [cycle] cycle error:
   450  -          //     ./issue3737.cue:3:12
   451  -        }
   452  -      }
   453  -      x: (#struct){
   454  -        a: (float){ 12000.0 }
   455  +          // [cycle] issue3737.reduced1.#A.a: cycle with field: b:
   456  +          //     ./issue3737.cue:3:12
   457  +          // issue3737.reduced1.#A.b: cycle with field: a:
   458  +          //     ./issue3737.cue:4:12
   459  +        }
   460  +      }
   461  +      x: (#struct){
   462           b: (float){ 1000.0 }
   463  +        a: (float){ 12000.0 }
   464         }
   465         y: (#struct){
   466           b: (float){ 700.00 }
   467  @@ -85,28 +103,38 @@
   468       reduced2: (struct){
   469         x: (#struct){
   470           start: (float){ 900.0 }
   471  -        duration: (float){ 100.0 }
   472  -        end: (float){ 1000.0 }
   473  -      }
   474  -      y: (#struct){
   475  -        start: (float){ 900.0 }
   476  -        duration: (float){ 100.0 }
   477  -        end: (float){ 1000.0 }
   478  +        end: (float){ 1000.0 }
   479  +        duration: (float){ 100.0 }
   480  +      }
   481  +      y: (#struct){
   482  +        duration: (float){ 100.0 }
   483  +        end: (float){ 1000.0 }
   484  +        start: (float){ 900.0 }
   485         }
   486         #TimeSpan: (#struct){
   487           start: (_|_){
   488  -          // [cycle] cycle error:
   489  -          //     ./issue3737.cue:23:19
   490  +          // [cycle] issue3737.reduced2.#TimeSpan.start: cycle with field: end:
   491  +          //     ./issue3737.cue:23:19
   492  +          // issue3737.reduced2.#TimeSpan.end: cycle with field: start:
   493  +          //     ./issue3737.cue:25:19
   494  +          // issue3737.reduced2.#TimeSpan.end: cycle with field: duration:
   495  +          //     ./issue3737.cue:25:27
   496           }
   497           duration: (_|_){
   498  -          // [cycle] cycle error:
   499  -          //     ./issue3737.cue:24:19
   500  +          // [cycle] issue3737.reduced2.#TimeSpan.start: cycle with field: end:
   501  +          //     ./issue3737.cue:23:19
   502  +          // issue3737.reduced2.#TimeSpan.end: cycle with field: start:
   503  +          //     ./issue3737.cue:25:19
   504  +          // issue3737.reduced2.#TimeSpan.end: cycle with field: duration:
   505  +          //     ./issue3737.cue:25:27
   506           }
   507           end: (_|_){
   508  -          // [cycle] cycle error:
   509  -          //     ./issue3737.cue:23:19
   510  -          // cycle error:
   511  -          //     ./issue3737.cue:24:19
   512  +          // [cycle] issue3737.reduced2.#TimeSpan.start: cycle with field: end:
   513  +          //     ./issue3737.cue:23:19
   514  +          // issue3737.reduced2.#TimeSpan.end: cycle with field: start:
   515  +          //     ./issue3737.cue:25:19
   516  +          // issue3737.reduced2.#TimeSpan.end: cycle with field: duration:
   517  +          //     ./issue3737.cue:25:27
   518           }
   519         }
   520       }
   521  -- diff/explanations --
   522  issue3669: expressions are now allowed to refer to defaults within disjunctions,
   523     even in a cycle, as long as the results are consistent.
   524  -- out/eval --
   525  (struct){
   526    oneway: (struct){
   527      t1: (struct){
   528        a: (_|_){
   529          // [incomplete] oneway.t1.a: non-concrete value <1 in operand to +:
   530          //     ./disjunction.cue:4:12
   531          //     ./disjunction.cue:5:12
   532        }
   533        b: (number){ <1 }
   534      }
   535      t2: (struct){
   536        a: (_|_){
   537          // [incomplete] oneway.t2.a: 2 errors in empty disjunction:
   538          // oneway.t2.a: conflicting values 1 and 3:
   539          //     ./disjunction.cue:3:13
   540          //     ./disjunction.cue:7:9
   541          //     ./disjunction.cue:8:12
   542          // oneway.t2.a: non-concrete value <3 in operand to +:
   543          //     ./disjunction.cue:4:12
   544          //     ./disjunction.cue:5:12
   545        }
   546        b: (number){ <3 }
   547      }
   548    }
   549    issue3669: (struct){
   550      #Schema: (#struct){
   551        two: (_|_){
   552          // [cycle] cycle error:
   553          //     ./disjunction.cue:14:8
   554        }
   555        one: (_|_){
   556          // [cycle] cycle error:
   557          //     ./disjunction.cue:14:8
   558        }
   559      }
   560      out: (#struct){
   561        two: (_|_){
   562          // [cycle] cycle error:
   563          //     ./disjunction.cue:14:8
   564        }
   565        one: (int){ -1 }
   566      }
   567    }
   568    a: (_|_){
   569      // [cycle] cycle error:
   570      //     ./in.cue:1:4
   571    }
   572    b: (_|_){
   573      // [cycle] cycle error:
   574      //     ./in.cue:1:4
   575    }
   576    c: (#list){
   577      0: (_){ _ }
   578      1: (_){ _ }
   579    }
   580    d: (_|_){
   581      // [cycle] cycle error:
   582      //     ./in.cue:6:4
   583    }
   584    e: (_|_){
   585      // [cycle] cycle error:
   586      //     ./in.cue:6:4
   587    }
   588    issue3737: (struct){
   589      reduced1: (struct){
   590        #A: (#struct){
   591          a: (_|_){
   592            // [cycle] cycle error:
   593            //     ./issue3737.cue:3:12
   594          }
   595          b: (_|_){
   596            // [cycle] cycle error:
   597            //     ./issue3737.cue:3:12
   598          }
   599        }
   600        x: (#struct){
   601          a: (float){ 12000.0 }
   602          b: (float){ 1000.0 }
   603        }
   604        y: (#struct){
   605          b: (float){ 700.00 }
   606          a: (float){ 8400.00 }
   607        }
   608      }
   609      reduced2: (struct){
   610        x: (#struct){
   611          start: (float){ 900.0 }
   612          duration: (float){ 100.0 }
   613          end: (float){ 1000.0 }
   614        }
   615        y: (#struct){
   616          start: (float){ 900.0 }
   617          duration: (float){ 100.0 }
   618          end: (float){ 1000.0 }
   619        }
   620        #TimeSpan: (#struct){
   621          start: (_|_){
   622            // [cycle] cycle error:
   623            //     ./issue3737.cue:23:19
   624          }
   625          duration: (_|_){
   626            // [cycle] cycle error:
   627            //     ./issue3737.cue:24:19
   628          }
   629          end: (_|_){
   630            // [cycle] cycle error:
   631            //     ./issue3737.cue:23:19
   632            // cycle error:
   633            //     ./issue3737.cue:24:19
   634          }
   635        }
   636      }
   637    }
   638  }