Skip to content

Commit db6a8b9

Browse files
committedJan 20, 2025
internal/core/adt: hoist closedness related code
We would like to hoist all dependency-related code into dep.go. But before doing that we first hoist code not related to this out. Signed-off-by: Marcel van Lohuizen <[email protected]> Change-Id: Idff4c168d546976af314e7217deeb03f35708033 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1207447 Reviewed-by: Daniel Martí <[email protected]> TryBot-Result: CUEcueckoo <[email protected]> Unity-Result: CUE porcuepine <[email protected]>
1 parent 6a60de5 commit db6a8b9

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed
 

‎internal/core/adt/fields.go

+24-13
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,26 @@ func (c *closeContext) decDependent(ctx *OpContext, kind depKind, dependant *clo
689689
cc.decDependent(ctx, NOTIFY, c)
690690
}
691691

692+
if !c.updateClosedInfo(ctx) {
693+
return
694+
}
695+
696+
p := c.parent
697+
698+
p.decDependent(ctx, PARENT, c) // REF(decrement: spawn)
699+
700+
// If we have started decrementing a child closeContext, the parent started
701+
// as well. If it is still marked as needing an EVAL decrement, which can
702+
// happen if processing started before the node was added, it is safe to
703+
// decrement it now. In this case the NOTIFY and ARC dependencies will keep
704+
// the nodes alive until they can be completed.
705+
if dep := p.needsCloseInSchedule; dep != nil {
706+
p.needsCloseInSchedule = nil
707+
p.decDependent(ctx, EVAL, dep)
708+
}
709+
}
710+
711+
func (c *closeContext) updateClosedInfo(ctx *OpContext) bool {
692712
p := c.parent
693713

694714
if c.isDef && !c.isTotal && (!c.hasTop || c.hasNonTop) {
@@ -708,6 +728,7 @@ func (c *closeContext) decDependent(ctx *OpContext, kind depKind, dependant *clo
708728
c.finalizePattern()
709729

710730
if p == nil {
731+
v := c.src
711732
// Root pattern, set allowed patterns.
712733
if pcs := v.PatternConstraints; pcs != nil {
713734
if pcs.Allowed != nil {
@@ -716,9 +737,9 @@ func (c *closeContext) decDependent(ctx *OpContext, kind depKind, dependant *clo
716737
// panic("unexpected allowed set")
717738
}
718739
pcs.Allowed = c.Expr
719-
return
740+
return false
720741
}
721-
return
742+
return false
722743
}
723744

724745
if c.hasTop {
@@ -745,17 +766,7 @@ func (c *closeContext) decDependent(ctx *OpContext, kind depKind, dependant *clo
745766
p.linkPatterns(c)
746767
}
747768

748-
p.decDependent(ctx, PARENT, c) // REF(decrement: spawn)
749-
750-
// If we have started decrementing a child closeContext, the parent started
751-
// as well. If it is still marked as needing an EVAL decrement, which can
752-
// happen if processing started before the node was added, it is safe to
753-
// decrement it now. In this case the NOTIFY and ARC dependencies will keep
754-
// the nodes alive until they can be completed.
755-
if dep := p.needsCloseInSchedule; dep != nil {
756-
p.needsCloseInSchedule = nil
757-
p.decDependent(ctx, EVAL, dep)
758-
}
769+
return true
759770
}
760771

761772
// incDisjunct increases disjunction-related counters. We require kind to be

0 commit comments

Comments
 (0)
Please sign in to comment.