this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

internal/core/compile: return Disjunction directly from or() builtin

Return a Disjunction value directly from the or() builtin, mirroring
how and() already returns a Conjunction. This avoids creating a temporary
Vertex with a DisjunctionExpr and eagerly evaluating it via CompleteArcs
with allKnown+finalize. Instead, the Disjunction is evaluated lazily
by the caller's disjunction scheduling machinery.

│ old │ new │
│ B/op │ B/op vs base │
VetInventory 3.631Gi ± ∞ ¹ 3.560Gi ± ∞ ¹ -1.95% (p=1.000 n=1)

│ old │ new │
│ allocs/op │ allocs/op vs base │
VetInventory 32.72M ± ∞ ¹ 31.70M ± ∞ ¹ -3.14% (p=1.000 n=1)

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: I30060b101a4f99221b7563475c60d23a205a4e05
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1234029
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Marcel van Lohuizen <mpvl@gmail.com>

+112 -97
+14 -14
cue/testdata/benchmarks/issue3514.txtar
··· 37 37 } 38 38 -- out/evalalpha/stats -- 39 39 Leaks: 27 40 - Freed: 3575 41 - Reused: 2436 42 - Allocs: 1166 40 + Freed: 2431 41 + Reused: 1293 42 + Allocs: 1165 43 43 Retain: 0 44 44 45 - Unifications: 50 46 - Conjuncts: 7010 47 - Disjuncts: 2362 45 + Unifications: 48 46 + Conjuncts: 3580 47 + Disjuncts: 1220 48 48 Notifications: 2 49 49 50 - NumCloseIDs: 5733 50 + NumCloseIDs: 2876 51 51 -- diff/-out/evalalpha/stats<==>+out/eval/stats -- 52 52 diff old new 53 53 --- old ··· 62 62 -Unifications: 189 63 63 -Conjuncts: 92950 64 64 -Disjuncts: 31139 65 - +Freed: 3575 66 - +Reused: 2436 67 - +Allocs: 1166 65 + +Freed: 2431 66 + +Reused: 1293 67 + +Allocs: 1165 68 68 +Retain: 0 69 69 + 70 - +Unifications: 50 71 - +Conjuncts: 7010 72 - +Disjuncts: 2362 70 + +Unifications: 48 71 + +Conjuncts: 3580 72 + +Disjuncts: 1220 73 73 +Notifications: 2 74 74 + 75 - +NumCloseIDs: 5733 75 + +NumCloseIDs: 2876 76 76 -- out/eval/stats -- 77 77 Leaks: 27 78 78 Freed: 31092
+14 -14
cue/testdata/cycle/comprehension.txtar
··· 453 453 } 454 454 -- out/evalalpha/stats -- 455 455 Leaks: 91 456 - Freed: 1007 457 - Reused: 975 456 + Freed: 821 457 + Reused: 789 458 458 Allocs: 123 459 459 Retain: 0 460 460 461 - Unifications: 650 462 - Conjuncts: 1925 463 - Disjuncts: 237 461 + Unifications: 554 462 + Conjuncts: 1547 463 + Disjuncts: 147 464 464 Notifications: 14 465 465 466 - NumCloseIDs: 813 466 + NumCloseIDs: 594 467 467 468 - ConjunctInfos: 1258 468 + ConjunctInfos: 1048 469 469 MaxConjunctInfos: 10 470 470 MaxReqSets: 12 471 471 MaxRedirect: 1 ··· 1400 1400 - 1401 1401 -NumCloseIDs: 16 1402 1402 +Leaks: 91 1403 - +Freed: 1007 1404 - +Reused: 975 1403 + +Freed: 821 1404 + +Reused: 789 1405 1405 +Allocs: 123 1406 1406 +Retain: 0 1407 1407 + 1408 - +Unifications: 650 1409 - +Conjuncts: 1925 1410 - +Disjuncts: 237 1408 + +Unifications: 554 1409 + +Conjuncts: 1547 1410 + +Disjuncts: 147 1411 1411 +Notifications: 14 1412 1412 + 1413 - +NumCloseIDs: 813 1413 + +NumCloseIDs: 594 1414 1414 + 1415 - +ConjunctInfos: 1258 1415 + +ConjunctInfos: 1048 1416 1416 +MaxConjunctInfos: 10 1417 1417 +MaxReqSets: 12 1418 1418 +MaxRedirect: 1
+48 -28
cue/testdata/cycle/evaluate.txtar
··· 124 124 } 125 125 -- out/evalalpha/stats -- 126 126 Leaks: 10 127 - Freed: 116 128 - Reused: 93 127 + Freed: 114 128 + Reused: 91 129 129 Allocs: 33 130 130 Retain: 0 131 131 132 - Unifications: 105 133 - Conjuncts: 152 134 - Disjuncts: 5 132 + Unifications: 104 133 + Conjuncts: 150 134 + Disjuncts: 4 135 135 136 136 NumCloseIDs: 47 137 137 -- diff/-out/evalalpha/stats<==>+out/eval/stats -- ··· 153 153 - 154 154 -NumCloseIDs: 6 155 155 +Leaks: 10 156 - +Freed: 116 157 - +Reused: 93 156 + +Freed: 114 157 + +Reused: 91 158 158 +Allocs: 33 159 159 +Retain: 0 160 160 + 161 - +Unifications: 105 162 - +Conjuncts: 152 163 - +Disjuncts: 5 161 + +Unifications: 104 162 + +Conjuncts: 150 163 + +Disjuncts: 4 164 164 + 165 165 +NumCloseIDs: 47 166 166 -- out/eval/stats -- ··· 183 183 closeFail.x.b: field not allowed: 184 184 ./in.cue:104:6 185 185 ./in.cue:107:5 186 + forCycle.#B.b: structural cycle 186 187 letCycleFail.t1.a.c: structural cycle 187 188 printCycle.a.X: structural cycle 188 189 structCycle.c: structural cycle 189 190 disjunctionCycle.b: cannot use 1 (type int) as list in argument 1 to and: 190 191 ./in.cue:56:9 191 - b: structural cycle: 192 - ./in.cue:62:6 193 192 listAddCycle.c: structural cycle: 194 193 ./in.cue:91:5 195 194 listMulCycle.c: structural cycle: ··· 264 263 // [structural cycle] 265 264 #A: (_|_){ 266 265 // [structural cycle] 267 - a: (_|_){ 268 - // [structural cycle] b: structural cycle: 269 - // ./in.cue:62:6 270 - } 266 + a: ~(forCycle.#B) 271 267 } 272 268 #B: (_|_){ 273 - // [structural cycle] b: structural cycle: 274 - // ./in.cue:62:6 269 + // [structural cycle] 270 + b: (_|_){ 271 + // [structural cycle] forCycle.#B.b: structural cycle 272 + } 275 273 } 276 274 } 277 275 letCycleWithAnd: (struct){ ··· 380 378 diff old new 381 379 --- old 382 380 +++ new 383 - @@ -1,33 +1,19 @@ 381 + @@ -1,33 +1,18 @@ 384 382 Errors: 385 383 -closeCycle.a: structural cycle 386 384 -closeCycle.b.d: structural cycle ··· 390 388 - ./in.cue:105:12 391 389 - ./in.cue:106:6 392 390 ./in.cue:107:5 391 + +forCycle.#B.b: structural cycle 393 392 letCycleFail.t1.a.c: structural cycle 394 393 -structCycle.a: structural cycle 395 394 -structCycle.b.d: structural cycle ··· 401 400 - ./in.cue:56:9 402 401 -disjunctionCycle.c: cannot use 1 (type int) as type list: 403 402 - ./in.cue:56:5 404 - +printCycle.a.X: structural cycle 405 - +structCycle.c: structural cycle 406 - +disjunctionCycle.b: cannot use 1 (type int) as list in argument 1 to and: 407 - ./in.cue:56:9 408 - b: structural cycle: 409 - ./in.cue:62:6 403 + - ./in.cue:56:9 404 + -b: structural cycle: 405 + - ./in.cue:62:6 410 406 -closeCycle.c: structural cycle: 411 407 - ./in.cue:73:15 412 408 -structCycle.c: structural cycle: ··· 415 411 - ./in.cue:85:11 416 412 -printCycle.a.X.X: structural cycle: 417 413 - ./in.cue:113:6 414 + +printCycle.a.X: structural cycle 415 + +structCycle.c: structural cycle 416 + +disjunctionCycle.b: cannot use 1 (type int) as list in argument 1 to and: 417 + + ./in.cue:56:9 418 418 +listAddCycle.c: structural cycle: 419 419 + ./in.cue:91:5 420 420 +listMulCycle.c: structural cycle: ··· 422 422 423 423 Result: 424 424 (_|_){ 425 - @@ -65,14 +51,8 @@ 425 + @@ -65,14 +50,8 @@ 426 426 } 427 427 t2: (struct){ 428 428 a: (struct){ ··· 439 439 } 440 440 x: (struct){ 441 441 y: (string){ "" } 442 - @@ -88,18 +68,15 @@ 442 + @@ -88,18 +67,15 @@ 443 443 disjunctionCycle: (_|_){ 444 444 // [eval] 445 445 a: (_|_){ ··· 467 467 // ./in.cue:56:9 468 468 } 469 469 } 470 - @@ -145,12 +122,11 @@ 470 + @@ -107,14 +83,13 @@ 471 + // [structural cycle] 472 + #A: (_|_){ 473 + // [structural cycle] 474 + - a: (_|_){ 475 + - // [structural cycle] b: structural cycle: 476 + - // ./in.cue:62:6 477 + - } 478 + + a: ~(forCycle.#B) 479 + } 480 + #B: (_|_){ 481 + - // [structural cycle] b: structural cycle: 482 + - // ./in.cue:62:6 483 + + // [structural cycle] 484 + + b: (_|_){ 485 + + // [structural cycle] forCycle.#B.b: structural cycle 486 + + } 487 + } 488 + } 489 + letCycleWithAnd: (struct){ 490 + @@ -145,12 +120,11 @@ 471 491 b: (_|_){ 472 492 // [structural cycle] 473 493 d: (_|_){
+14 -14
cue/testdata/eval/bulk.txtar
··· 143 143 } 144 144 -- out/evalalpha/stats -- 145 145 Leaks: 20 146 - Freed: 207 147 - Reused: 184 146 + Freed: 183 147 + Reused: 160 148 148 Allocs: 43 149 149 Retain: 0 150 150 151 - Unifications: 154 152 - Conjuncts: 371 153 - Disjuncts: 53 154 - Notifications: 15 151 + Unifications: 148 152 + Conjuncts: 329 153 + Disjuncts: 35 154 + Notifications: 6 155 155 156 - NumCloseIDs: 98 156 + NumCloseIDs: 80 157 157 -- diff/-out/evalalpha/stats<==>+out/eval/stats -- 158 158 diff old new 159 159 --- old ··· 173 173 - 174 174 -NumCloseIDs: 4 175 175 +Leaks: 20 176 - +Freed: 207 177 - +Reused: 184 176 + +Freed: 183 177 + +Reused: 160 178 178 +Allocs: 43 179 179 +Retain: 0 180 180 + 181 - +Unifications: 154 182 - +Conjuncts: 371 183 - +Disjuncts: 53 184 - +Notifications: 15 181 + +Unifications: 148 182 + +Conjuncts: 329 183 + +Disjuncts: 35 184 + +Notifications: 6 185 185 + 186 - +NumCloseIDs: 98 186 + +NumCloseIDs: 80 187 187 -- out/eval/stats -- 188 188 Leaks: 4 189 189 Freed: 269
+14 -14
cue/testdata/eval/issue3672.txtar
··· 301 301 } 302 302 -- out/evalalpha/stats -- 303 303 Leaks: 345 304 - Freed: 1760 305 - Reused: 1702 304 + Freed: 1738 305 + Reused: 1680 306 306 Allocs: 403 307 307 Retain: 0 308 308 309 - Unifications: 386 310 - Conjuncts: 2354 311 - Disjuncts: 576 309 + Unifications: 368 310 + Conjuncts: 2310 311 + Disjuncts: 572 312 312 313 - NumCloseIDs: 821 313 + NumCloseIDs: 803 314 314 315 - ConjunctInfos: 886 315 + ConjunctInfos: 860 316 316 MaxConjunctInfos: 7 317 317 MaxReqSets: 15 318 318 MaxRedirect: 6 ··· 331 331 -Conjuncts: 468967 332 332 -Disjuncts: 330375 333 333 +Leaks: 345 334 - +Freed: 1760 335 - +Reused: 1702 334 + +Freed: 1738 335 + +Reused: 1680 336 336 +Allocs: 403 337 337 +Retain: 0 338 338 + 339 - +Unifications: 386 340 - +Conjuncts: 2354 341 - +Disjuncts: 576 339 + +Unifications: 368 340 + +Conjuncts: 2310 341 + +Disjuncts: 572 342 342 + 343 - +NumCloseIDs: 821 343 + +NumCloseIDs: 803 344 344 + 345 - +ConjunctInfos: 886 345 + +ConjunctInfos: 860 346 346 +MaxConjunctInfos: 7 347 347 +MaxReqSets: 15 348 348 +MaxRedirect: 6
+8 -13
internal/core/compile/builtin.go
··· 241 241 Func: func(call adt.BuiltinCallContext) adt.Expr { 242 242 c := call.OpContext() 243 243 244 - d := []adt.Disjunct{} 245 - for c := range c.RawElems(call.Value(0)) { 246 - d = append(d, adt.Disjunct{Val: c, Default: false}) 244 + var values []adt.Value 245 + for v := range c.RawElems(call.Value(0)) { 246 + values = append(values, v) 247 247 } 248 - if len(d) == 0 { 248 + if len(values) == 0 { 249 249 // TODO(manifest): This should not be unconditionally incomplete, 250 250 // but it requires results from comprehensions and all to have 251 251 // some special status. Maybe this can be solved by having results ··· 259 259 Err: errors.Newf(c.Pos(), "empty list in call to or"), 260 260 } 261 261 } 262 - v := &adt.Vertex{} 263 - // TODO: make a Disjunction. 264 - closeInfo := c.CloseInfo() 265 - v.AddConjunct(adt.MakeConjunct(nil, 266 - &adt.DisjunctionExpr{Values: d, HasDefaults: false}, 267 - closeInfo, 268 - )) 269 - v.CompleteArcs(c) 270 - return v 262 + if len(values) == 1 { 263 + return values[0] 264 + } 265 + return &adt.Disjunction{Values: values} 271 266 }, 272 267 } 273 268