this repo has no description
0
fork

Configure Feed

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

internal/core/adt: hoist dependency breaking code

Consolidate more dependency-related
code into dep.go.

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

+70 -50
+68
internal/core/adt/dep.go
··· 133 133 } 134 134 } 135 135 136 + // A ccArcRef x refers to the x.src.[arcs|notify][x.index] 137 + // 138 + // We use this instead of pointers, because the address may change when 139 + // growing a slice. We use this instead mechanism instead of a pointers so 140 + // that we do not need to maintain separate free buffers once we use pools of 141 + // closeContext. 142 + type ccArcRef struct { 143 + src *closeContext 144 + kind depKind 145 + index int 146 + } 147 + 136 148 // addArc adds a dependent arc to c. If child is an arc, child.src == key 137 149 func (c *closeContext) addArcDependency(ctx *OpContext, matched bool, key, child, root *closeContext) { 138 150 const kind = ARC ··· 322 334 p.decDependent(ctx, EVAL, dep) 323 335 } 324 336 } 337 + 338 + // breakIncomingArcs walks over incoming arcs and forces any remaining work to 339 + // be done. 340 + func (n *nodeContext) breakIncomingArcs(mode runMode) { 341 + v := n.node 342 + // Check: 343 + // - parents (done) 344 + // - incoming notifications 345 + // - pending arcs (or incoming COMPS) 346 + // TODO: replace with something more principled that does not piggyback on 347 + // debug information. 348 + for _, r := range v.cc().externalDeps { 349 + if r.kind != NOTIFY { 350 + continue 351 + } 352 + src := r.src 353 + a := &src.notify[r.index] 354 + if a.decremented { 355 + continue 356 + } 357 + if n := src.src.getState(n.ctx); n != nil { 358 + n.completeNodeTasks(mode) 359 + } 360 + } 361 + } 362 + 363 + // breakIncomingDeps breaks all incoming dependencies, which includes arcs and 364 + // pending notifications and attempts all remaining work. 365 + func (n *nodeContext) breakIncomingDeps() { 366 + // TODO: remove this block in favor of finalizing notification nodes, 367 + // or what have you. We have patched this to skip evaluating when using 368 + // disjunctions, but this is overall a brittle approach. 369 + for _, r := range n.node.cc().externalDeps { 370 + src := r.src 371 + // We should be careful to not evaluate parent nodes if we are inside a 372 + // disjunction, or at least ensure that there are no disjunction values 373 + // leaked into non-disjunction nodes through evaluating externalDeps. 374 + if src.src.IsDisjunct { 375 + continue 376 + } 377 + var a *ccArc 378 + switch r.kind { 379 + case ARC: 380 + a = &src.arcs[r.index] 381 + case NOTIFY: 382 + a = &src.notify[r.index] 383 + } 384 + if a.decremented { 385 + continue 386 + } 387 + a.decremented = true 388 + 389 + src.src.unify(n.ctx, needTasksDone, attemptOnly) 390 + a.dst.decDependent(n.ctx, r.kind, src) 391 + } 392 + }
-11
internal/core/adt/fields.go
··· 337 337 dst *closeContext 338 338 } 339 339 340 - // A ccArcRef x refers to the x.src.arcs[x.index]. 341 - // We use this instead of pointers, because the address may change when 342 - // growing a slice. We use this instead mechanism instead of a pointers so 343 - // that we do not need to maintain separate free buffers once we use pools of 344 - // closeContext. 345 - type ccArcRef struct { 346 - src *closeContext 347 - kind depKind 348 - index int 349 - } 350 - 351 340 type conjunctGrouper interface { 352 341 // Assign conjunct adds the conjunct and returns an arc to represent it, 353 342 // along with the position within the group.
+2 -39
internal/core/adt/unify.go
··· 486 486 // - pending arcs (or incoming COMPS) 487 487 // TODO: replace with something more principled that does not piggyback on 488 488 // debug information. 489 - for _, r := range v.cc().externalDeps { 490 - if r.kind != NOTIFY { 491 - continue 492 - } 493 - src := r.src 494 - a := &src.notify[r.index] 495 - if a.decremented { 496 - continue 497 - } 498 - if n := src.src.getState(n.ctx); n != nil { 499 - n.completeNodeTasks(mode) 500 - } 501 - } 489 + n.breakIncomingArcs(mode) 502 490 503 491 // As long as ancestors are not processed, it is still possible for 504 492 // conjuncts to be inserted. Until that time, it is not okay to decrement ··· 548 536 // Investigate how to work around this. 549 537 n.completeNodeTasks(finalize) 550 538 551 - // TODO: remove this block in favor of finalizing notification nodes, 552 - // or what have you. We have patched this to skip evaluating when using 553 - // disjunctions, but this is overall a brittle approach. 554 - for _, r := range n.node.cc().externalDeps { 555 - src := r.src 556 - // We should be careful to not evaluate parent nodes if we are inside a 557 - // disjunction, or at least ensure that there are no disjunction values 558 - // leaked into non-disjunction nodes through evaluating externalDeps. 559 - if src.src.IsDisjunct { 560 - continue 561 - } 562 - var a *ccArc 563 - switch r.kind { 564 - case ARC: 565 - a = &src.arcs[r.index] 566 - case NOTIFY: 567 - a = &src.notify[r.index] 568 - } 569 - if a.decremented { 570 - continue 571 - } 572 - a.decremented = true 573 - 574 - src.src.unify(n.ctx, needTasksDone, attemptOnly) 575 - a.dst.decDependent(n.ctx, r.kind, src) 576 - } 539 + n.breakIncomingDeps() 577 540 578 541 n.incDepth() 579 542 defer n.decDepth()