cuelang.org/go@v0.10.1/cue/testdata/cycle/051_resolved_self-reference_cycles_with_disjunction.txtar (about)

     1  #name: resolved self-reference cycles with disjunction
     2  #evalPartial
     3  
     4  // TODO(cycle)
     5  //
     6  // Some of these examples used to work, but the changes corresponding to this
     7  // addition, it ceased to do so. Fixing these cycle issues seemed more
     8  // important than keeping this esoteric case working, which was already broken
     9  // in the last release anyway.
    10  //
    11  // Reproducer of underlying problem. Still works, but triggers unexpected
    12  // condition.
    13  //
    14  // xb1: xb2
    15  // xb2: xb3
    16  // xb3: xb2 + 0
    17  
    18  -- in.cue --
    19  // The second disjunct in xa1 is not resolvable and can be
    20  // eliminated:
    21  //   xa4 & 9
    22  //   (xa2 + 2) & 9
    23  //   ((xa3 + 2) + 2) & 9
    24  //   (((6 & xa1-2) + 2) + 2) & 9
    25  //   ((6 + 2) + 2) & 9 // 6 == xa1-2
    26  //   10 & 9 => _|_
    27  // The remaining values resolve.
    28  xa1: (xa2 & 8) | (xa4 & 9)
    29  xa2: xa3 + 2
    30  xa3: 6 & xa1-2
    31  xa4: xa2 + 2
    32  
    33  xb1: (xb2 & 8) | (xb4 & 9)
    34  xb2: xb3 + 2
    35  xb3: (6 & (xb1 - 2)) | (xb4 & 9)
    36  xb4: xb2 + 2
    37  
    38  // Another variant with more disjunctions. xc1 remains with two
    39  // possibilities. Technically, only the first value is valid.
    40  // However, to fully determine that, all options of the remaining
    41  // disjunction will have to be evaluated algebraically, which is
    42  // not done.
    43  xc1: xc2 & 8 | xc4 & 9 | xc5 & 9
    44  xc2: xc3 + 2
    45  xc3: 6 & xc1-2
    46  xc4: xc2 + 1
    47  xc5: xc2 + 2
    48  
    49  // The below is resolved by setting xd1 explicitly.
    50  xd1: xd2 & 8 | xd4 & 9 | xd5 & 9
    51  xd2: xd3 + 2
    52  xd3: 6 & xd1-2
    53  xd4: xd2 + 1
    54  xd5: xd2 + 2
    55  xd1: 8
    56  
    57  // The below is resolved by setting xd1 explicitly to the wrong
    58  // value, resulting in an error.
    59  xe1: xe2 & 8 | xe4 & 9 | xe5 & 9
    60  xe2: xe3 + 2
    61  xe3: 6 & xe1-2
    62  xe4: xe2 + 1
    63  xe5: xe2 + 2
    64  xe1: 9
    65  
    66  xf1: xf2 & 8 | xf4 & 9
    67  xf2: xf3 + 2
    68  xf3: 6 & xf1-2 | xf4 & 9
    69  xf4: xf2 + 2
    70  
    71  z1: z2+1 | z3+5 // +3 for fun
    72  z2: z3 + 2
    73  z3: z1 - 3
    74  z3: 8
    75  -- out/def --
    76  // The second disjunct in xa1 is not resolvable and can be
    77  // eliminated:
    78  //   xa4 & 9
    79  //   (xa2 + 2) & 9
    80  //   ((xa3 + 2) + 2) & 9
    81  //   (((6 & xa1-2) + 2) + 2) & 9
    82  //   ((6 + 2) + 2) & 9 // 6 == xa1-2
    83  //   10 & 9 => _|_
    84  // The remaining values resolve.
    85  xa1: 8
    86  xa2: 8
    87  xa4: 10
    88  xa3: 6
    89  
    90  // The second disjunct in xb4 can be eliminated as both disjuncts
    91  // of xb3 result in an incompatible sum when substituted.
    92  xb1: 8
    93  xb2: 8
    94  xb4: 10
    95  xb3: 6
    96  
    97  // Another variant with more disjunctions. xc1 remains with two
    98  // possibilities. Technically, only the first value is valid.
    99  // However, to fully determine that, all options of the remaining
   100  // disjunction will have to be evaluated algebraically, which is
   101  // not done.
   102  xc1: xc2 & 8 | xc4 & 9 | xc5 & 9
   103  xc2: xc3 + 2
   104  xc4: xc2 + 1
   105  xc5: xc2 + 2
   106  xc3: 6 & xc1-2
   107  
   108  // The above is resolved by setting xd1 explicitly.
   109  xd1: 8
   110  xd2: 8
   111  xd4: 9
   112  xd5: 10
   113  xd3: 6
   114  
   115  // The above is resolved by setting xd1 explicitly to the wrong
   116  // value, resulting in an error.
   117  xe1: _|_ // conflicting values 6 and 7
   118  xe2: _|_ // conflicting values 6 and 7
   119  xe4: _|_ // conflicting values 6 and 7
   120  xe5: _|_ // conflicting values 6 and 7
   121  xe3: _|_ // conflicting values 6 and 7
   122  
   123  // Only one solution.
   124  xf1: 8
   125  xf2: 8
   126  xf4: 10
   127  xf3: 6
   128  z1:  z2+1 | z3+5
   129  z2:  z3 + 2
   130  z3:  z1-3 & 8
   131  -- out/legacy-debug --
   132  <0>{xa1: 8, xa2: 8, xa4: 10, xa3: 6, xb1: 8, xb2: 8, xb4: 10, xb3: 6, xc1: ((<1>.xc2 & 8) | (<1>.xc4 & 9) | (<1>.xc5 & 9)), xc2: (<1>.xc3 + 2), xc4: (<1>.xc2 + 1), xc5: (<1>.xc2 + 2), xc3: (6 & (<1>.xc1 - 2)), xd1: 8, xd2: 8, xd4: 9, xd5: 10, xd3: 6, xe1: _|_((6 & 7):conflicting values 6 and 7), xe2: _|_((6 & 7):conflicting values 6 and 7), xe4: _|_((6 & 7):conflicting values 6 and 7), xe5: _|_((6 & 7):conflicting values 6 and 7), xe3: _|_((6 & 7):conflicting values 6 and 7), xf1: 8, xf2: 8, xf4: 10, xf3: 6, z1: ((<1>.z2 + 1) | (<1>.z3 + 5)), z2: (<1>.z3 + 2), z3: ((<1>.z1 - 3) & 8)}
   133  -- out/compile --
   134  --- in.cue
   135  {
   136    xa1: ((〈0;xa2〉 & 8)|(〈0;xa4〉 & 9))
   137    xa2: (〈0;xa3〉 + 2)
   138    xa3: (6 & (〈0;xa1〉 - 2))
   139    xa4: (〈0;xa2〉 + 2)
   140    xb1: ((〈0;xb2〉 & 8)|(〈0;xb4〉 & 9))
   141    xb2: (〈0;xb3〉 + 2)
   142    xb3: ((6 & (〈0;xb1〉 - 2))|(〈0;xb4〉 & 9))
   143    xb4: (〈0;xb2〉 + 2)
   144    xc1: ((〈0;xc2〉 & 8)|(〈0;xc4〉 & 9)|(〈0;xc5〉 & 9))
   145    xc2: (〈0;xc3〉 + 2)
   146    xc3: (6 & (〈0;xc1〉 - 2))
   147    xc4: (〈0;xc2〉 + 1)
   148    xc5: (〈0;xc2〉 + 2)
   149    xd1: ((〈0;xd2〉 & 8)|(〈0;xd4〉 & 9)|(〈0;xd5〉 & 9))
   150    xd2: (〈0;xd3〉 + 2)
   151    xd3: (6 & (〈0;xd1〉 - 2))
   152    xd4: (〈0;xd2〉 + 1)
   153    xd5: (〈0;xd2〉 + 2)
   154    xd1: 8
   155    xe1: ((〈0;xe2〉 & 8)|(〈0;xe4〉 & 9)|(〈0;xe5〉 & 9))
   156    xe2: (〈0;xe3〉 + 2)
   157    xe3: (6 & (〈0;xe1〉 - 2))
   158    xe4: (〈0;xe2〉 + 1)
   159    xe5: (〈0;xe2〉 + 2)
   160    xe1: 9
   161    xf1: ((〈0;xf2〉 & 8)|(〈0;xf4〉 & 9))
   162    xf2: (〈0;xf3〉 + 2)
   163    xf3: ((6 & (〈0;xf1〉 - 2))|(〈0;xf4〉 & 9))
   164    xf4: (〈0;xf2〉 + 2)
   165    z1: ((〈0;z2〉 + 1)|(〈0;z3〉 + 5))
   166    z2: (〈0;z3〉 + 2)
   167    z3: (〈0;z1〉 - 3)
   168    z3: 8
   169  }
   170  -- out/eval/stats --
   171  Leaks:  0
   172  Freed:  52
   173  Reused: 44
   174  Allocs: 8
   175  Retain: 24
   176  
   177  Unifications: 31
   178  Conjuncts:    128
   179  Disjuncts:    60
   180  -- out/evalalpha --
   181  Errors:
   182  xe1: conflicting values 8 and 9:
   183      ./in.cue:41:12
   184      ./in.cue:46:6
   185  
   186  Result:
   187  (_|_){
   188    // [eval]
   189    xa1: (int){ 8 }
   190    xa2: (int){ 8 }
   191    xa3: (int){ 6 }
   192    xa4: (int){ 10 }
   193    xb1: (int){ 8 }
   194    xb2: (int){ 11 }
   195    xb3: (int){ 6 }
   196    xb4: (int){ 13 }
   197    xc1: (int){ |((int){ 8 }, (int){ 9 }) }
   198    xc2: (int){ 8 }
   199    xc3: (int){ 6 }
   200    xc4: (int){ 9 }
   201    xc5: (int){ 10 }
   202    xd1: (int){ 8 }
   203    xd2: (int){ 8 }
   204    xd3: (int){ 6 }
   205    xd4: (int){ 9 }
   206    xd5: (int){ 10 }
   207    xe1: (_|_){
   208      // [eval] xe1: conflicting values 8 and 9:
   209      //     ./in.cue:41:12
   210      //     ./in.cue:46:6
   211    }
   212    xe2: (_|_){
   213      // [eval] xe1: conflicting values 8 and 9:
   214      //     ./in.cue:41:12
   215      //     ./in.cue:46:6
   216    }
   217    xe3: (_|_){
   218      // [eval] xe1: conflicting values 8 and 9:
   219      //     ./in.cue:41:12
   220      //     ./in.cue:46:6
   221    }
   222    xe4: (_|_){
   223      // [eval] xe1: conflicting values 8 and 9:
   224      //     ./in.cue:41:12
   225      //     ./in.cue:46:6
   226    }
   227    xe5: (_|_){
   228      // [eval] xe1: conflicting values 8 and 9:
   229      //     ./in.cue:41:12
   230      //     ./in.cue:46:6
   231    }
   232    xf1: (int){ 8 }
   233    xf2: (int){ 11 }
   234    xf3: (int){ 6 }
   235    xf4: (int){ 13 }
   236    z1: (int){ |((int){ 11 }, (int){ 13 }) }
   237    z2: (int){ 10 }
   238    z3: (int){ 8 }
   239  }
   240  -- diff/-out/evalalpha<==>+out/eval --
   241  diff old new
   242  --- old
   243  +++ new
   244  @@ -1,7 +1,7 @@
   245   Errors:
   246  -xe3: conflicting values 7 and 6:
   247  -    ./in.cue:43:6
   248  -    ./in.cue:43:10
   249  +xe1: conflicting values 8 and 9:
   250  +    ./in.cue:41:12
   251  +    ./in.cue:46:6
   252   
   253   Result:
   254   (_|_){
   255  @@ -10,28 +10,13 @@
   256     xa2: (int){ 8 }
   257     xa3: (int){ 6 }
   258     xa4: (int){ 10 }
   259  -  xb1: (_|_){
   260  -    // [incomplete] xb1: 2 errors in empty disjunction:
   261  -    // xb1: unresolved disjunction 6 | 9 (type int):
   262  -    //     ./in.cue:16:6
   263  -    // xb2: unresolved disjunction 6 | 9 (type int):
   264  -    //     ./in.cue:16:6
   265  -  }
   266  -  xb2: (_|_){
   267  -    // [incomplete] xb2: unresolved disjunction 6 | 9 (type int):
   268  -    //     ./in.cue:16:6
   269  -  }
   270  -  xb3: (int){ |((int){ 6 }, (int){ 9 }) }
   271  -  xb4: (_|_){
   272  -    // [incomplete] xb2: unresolved disjunction 6 | 9 (type int):
   273  -    //     ./in.cue:16:6
   274  -  }
   275  +  xb1: (int){ 8 }
   276  +  xb2: (int){ 11 }
   277  +  xb3: (int){ 6 }
   278  +  xb4: (int){ 13 }
   279     xc1: (int){ |((int){ 8 }, (int){ 9 }) }
   280     xc2: (int){ 8 }
   281  -  xc3: (_|_){
   282  -    // [incomplete] xc3: unresolved disjunction 8 | 9 (type int):
   283  -    //     ./in.cue:27:10
   284  -  }
   285  +  xc3: (int){ 6 }
   286     xc4: (int){ 9 }
   287     xc5: (int){ 10 }
   288     xd1: (int){ 8 }
   289  @@ -39,35 +24,36 @@
   290     xd3: (int){ 6 }
   291     xd4: (int){ 9 }
   292     xd5: (int){ 10 }
   293  -  xe1: (int){ 9 }
   294  -  xe2: (int){ 8 }
   295  +  xe1: (_|_){
   296  +    // [eval] xe1: conflicting values 8 and 9:
   297  +    //     ./in.cue:41:12
   298  +    //     ./in.cue:46:6
   299  +  }
   300  +  xe2: (_|_){
   301  +    // [eval] xe1: conflicting values 8 and 9:
   302  +    //     ./in.cue:41:12
   303  +    //     ./in.cue:46:6
   304  +  }
   305     xe3: (_|_){
   306  -    // [eval] xe3: conflicting values 7 and 6:
   307  -    //     ./in.cue:43:6
   308  -    //     ./in.cue:43:10
   309  -  }
   310  -  xe4: (int){ 9 }
   311  -  xe5: (int){ 10 }
   312  -  xf1: (_|_){
   313  -    // [incomplete] xf1: 2 errors in empty disjunction:
   314  -    // xf1: unresolved disjunction 6 | 9 (type int):
   315  -    //     ./in.cue:49:6
   316  -    // xf2: unresolved disjunction 6 | 9 (type int):
   317  -    //     ./in.cue:49:6
   318  -  }
   319  -  xf2: (_|_){
   320  -    // [incomplete] xf2: unresolved disjunction 6 | 9 (type int):
   321  -    //     ./in.cue:49:6
   322  -  }
   323  -  xf3: (int){ |((int){ 6 }, (int){ 9 }) }
   324  -  xf4: (_|_){
   325  -    // [incomplete] xf2: unresolved disjunction 6 | 9 (type int):
   326  -    //     ./in.cue:49:6
   327  -  }
   328  +    // [eval] xe1: conflicting values 8 and 9:
   329  +    //     ./in.cue:41:12
   330  +    //     ./in.cue:46:6
   331  +  }
   332  +  xe4: (_|_){
   333  +    // [eval] xe1: conflicting values 8 and 9:
   334  +    //     ./in.cue:41:12
   335  +    //     ./in.cue:46:6
   336  +  }
   337  +  xe5: (_|_){
   338  +    // [eval] xe1: conflicting values 8 and 9:
   339  +    //     ./in.cue:41:12
   340  +    //     ./in.cue:46:6
   341  +  }
   342  +  xf1: (int){ 8 }
   343  +  xf2: (int){ 11 }
   344  +  xf3: (int){ 6 }
   345  +  xf4: (int){ 13 }
   346     z1: (int){ |((int){ 11 }, (int){ 13 }) }
   347     z2: (int){ 10 }
   348  -  z3: (_|_){
   349  -    // [incomplete] z3: unresolved disjunction 11 | 13 (type int):
   350  -    //     ./in.cue:55:5
   351  -  }
   352  +  z3: (int){ 8 }
   353   }
   354  -- diff/todo/p1 --
   355  x(b|f)(2|4): resolve incorrectly. This is related to completeNodeTasks.
   356  -- diff/explanation --
   357  x(e|f)*: is better to have an error at each field.
   358  z3: include the "unchecked" validator.
   359  In general, new evaluator seems better.
   360  -- out/eval --
   361  Errors:
   362  xe3: conflicting values 7 and 6:
   363      ./in.cue:43:6
   364      ./in.cue:43:10
   365  
   366  Result:
   367  (_|_){
   368    // [eval]
   369    xa1: (int){ 8 }
   370    xa2: (int){ 8 }
   371    xa3: (int){ 6 }
   372    xa4: (int){ 10 }
   373    xb1: (_|_){
   374      // [incomplete] xb1: 2 errors in empty disjunction:
   375      // xb1: unresolved disjunction 6 | 9 (type int):
   376      //     ./in.cue:16:6
   377      // xb2: unresolved disjunction 6 | 9 (type int):
   378      //     ./in.cue:16:6
   379    }
   380    xb2: (_|_){
   381      // [incomplete] xb2: unresolved disjunction 6 | 9 (type int):
   382      //     ./in.cue:16:6
   383    }
   384    xb3: (int){ |((int){ 6 }, (int){ 9 }) }
   385    xb4: (_|_){
   386      // [incomplete] xb2: unresolved disjunction 6 | 9 (type int):
   387      //     ./in.cue:16:6
   388    }
   389    xc1: (int){ |((int){ 8 }, (int){ 9 }) }
   390    xc2: (int){ 8 }
   391    xc3: (_|_){
   392      // [incomplete] xc3: unresolved disjunction 8 | 9 (type int):
   393      //     ./in.cue:27:10
   394    }
   395    xc4: (int){ 9 }
   396    xc5: (int){ 10 }
   397    xd1: (int){ 8 }
   398    xd2: (int){ 8 }
   399    xd3: (int){ 6 }
   400    xd4: (int){ 9 }
   401    xd5: (int){ 10 }
   402    xe1: (int){ 9 }
   403    xe2: (int){ 8 }
   404    xe3: (_|_){
   405      // [eval] xe3: conflicting values 7 and 6:
   406      //     ./in.cue:43:6
   407      //     ./in.cue:43:10
   408    }
   409    xe4: (int){ 9 }
   410    xe5: (int){ 10 }
   411    xf1: (_|_){
   412      // [incomplete] xf1: 2 errors in empty disjunction:
   413      // xf1: unresolved disjunction 6 | 9 (type int):
   414      //     ./in.cue:49:6
   415      // xf2: unresolved disjunction 6 | 9 (type int):
   416      //     ./in.cue:49:6
   417    }
   418    xf2: (_|_){
   419      // [incomplete] xf2: unresolved disjunction 6 | 9 (type int):
   420      //     ./in.cue:49:6
   421    }
   422    xf3: (int){ |((int){ 6 }, (int){ 9 }) }
   423    xf4: (_|_){
   424      // [incomplete] xf2: unresolved disjunction 6 | 9 (type int):
   425      //     ./in.cue:49:6
   426    }
   427    z1: (int){ |((int){ 11 }, (int){ 13 }) }
   428    z2: (int){ 10 }
   429    z3: (_|_){
   430      // [incomplete] z3: unresolved disjunction 11 | 13 (type int):
   431      //     ./in.cue:55:5
   432    }
   433  }