Skip to content

Commit 7d159b3

Browse files
committed
internal/core/adt: hoist dependency code
It is important that the dependency handling code is called after all allocations of closeContext have been called. We are not aware that the allocCC called in initCloneCC actually allocates new ones, but just to be sure. Signed-off-by: Marcel van Lohuizen <[email protected]> Change-Id: I29873c2f21df1e5d7b143433440be08b7e4f75ed Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1207454 Unity-Result: CUE porcuepine <[email protected]> TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Daniel Martí <[email protected]>
1 parent 4d3eafa commit 7d159b3

File tree

1 file changed

+39
-31
lines changed

1 file changed

+39
-31
lines changed

internal/core/adt/overlay.go

+39-31
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ func (ctx *overlayContext) cloneRoot(root *nodeContext) *nodeContext {
9797
ctx.initCloneCC(cc)
9898
}
9999

100+
for _, cc := range ctx.closeContexts {
101+
ctx.finishDependencies(cc)
102+
}
103+
100104
// TODO: walk overlay vertices and decrement counters of non-disjunction
101105
// running tasks?
102106
// TODO: find a faster way to do this. Walking over vertices would
@@ -380,37 +384,6 @@ func (ctx *overlayContext) initCloneCC(x *closeContext) {
380384
// panic("unexpected overlay in next")
381385
}
382386

383-
for _, d := range x.dependencies {
384-
if d.decremented {
385-
continue
386-
}
387-
388-
if d.dependency.overlay == nil {
389-
// This dependency is irrelevant for the current overlay. We can
390-
// eliminate it as long as we decrement the accompanying counter.
391-
if o.conjunctCount < 2 {
392-
// This node can only be relevant if it has at least one other
393-
// dependency. Check that we are not decrementing the counter
394-
// to 0.
395-
// TODO: this currently panics for some tests. Disabling does
396-
// not seem to harm, though. Reconsider whether this is an issue.
397-
// panic("unexpected conjunctCount: must be at least 2")
398-
}
399-
o.conjunctCount--
400-
continue
401-
}
402-
403-
dep := d.dependency
404-
if dep.overlay != nil {
405-
dep = dep.overlay
406-
}
407-
o.dependencies = append(o.dependencies, &ccDep{
408-
dependency: dep,
409-
kind: d.kind,
410-
decremented: false,
411-
})
412-
}
413-
414387
switch p := x.parentConjuncts.(type) {
415388
case *closeContext:
416389
if p.overlay == nil {
@@ -462,6 +435,41 @@ func (ctx *overlayContext) initCloneCC(x *closeContext) {
462435
// be resolved in the base anyway.
463436
}
464437

438+
func (ctx *overlayContext) finishDependencies(x *closeContext) {
439+
o := x.overlay
440+
441+
for _, d := range x.dependencies {
442+
if d.decremented {
443+
continue
444+
}
445+
446+
if d.dependency.overlay == nil {
447+
// This dependency is irrelevant for the current overlay. We can
448+
// eliminate it as long as we decrement the accompanying counter.
449+
if o.conjunctCount < 2 {
450+
// This node can only be relevant if it has at least one other
451+
// dependency. Check that we are not decrementing the counter
452+
// to 0.
453+
// TODO: this currently panics for some tests. Disabling does
454+
// not seem to harm, though. Reconsider whether this is an issue.
455+
// panic("unexpected conjunctCount: must be at least 2")
456+
}
457+
o.conjunctCount--
458+
continue
459+
}
460+
461+
dep := d.dependency
462+
if dep.overlay != nil {
463+
dep = dep.overlay
464+
}
465+
o.dependencies = append(o.dependencies, &ccDep{
466+
dependency: dep,
467+
kind: d.kind,
468+
decremented: false,
469+
})
470+
}
471+
}
472+
465473
func (ctx *overlayContext) cloneScheduler(dst, src *nodeContext) {
466474
ss := &src.scheduler
467475
ds := &dst.scheduler

0 commit comments

Comments
 (0)