Skip to content

Commit 13f38c9

Browse files
committed
internal/core/adt: simplify linkNotify
This CL simplifies the arguments to linkNotify to make it a bit easier to understand the invariants that hold between various closeContexts involved. Signed-off-by: Marcel van Lohuizen <[email protected]> Change-Id: Ibb38b519d947ae326ad185ee64bc1b87df457818 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1207443 Reviewed-by: Daniel Martí <[email protected]> TryBot-Result: CUEcueckoo <[email protected]> Unity-Result: CUE porcuepine <[email protected]>
1 parent 9f913e0 commit 13f38c9

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

internal/core/adt/conjunct.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,11 @@ func (n *nodeContext) insertAndSkipConjuncts(c Conjunct, id CloseInfo, depth int
521521
}
522522

523523
func (n *nodeContext) addNotify2(v *Vertex, c CloseInfo) []receiver {
524+
// scheduleConjunct should ensure that the closeContext of of c is aligned
525+
// with v. We rely on this to be the case here. We enforce this invariant
526+
// here for clarity and to ensure correctness.
527+
n.ctx.Assertf(token.NoPos, c.cc.src == v, "close context not aligned with vertex")
528+
524529
// No need to do the notification mechanism if we are already complete.
525530
old := n.notify
526531
switch {
@@ -543,15 +548,15 @@ func (n *nodeContext) addNotify2(v *Vertex, c CloseInfo) []receiver {
543548
}
544549

545550
for _, r := range n.notify {
546-
if r.v == v && r.cc == c.cc {
551+
if r.cc == c.cc {
547552
return old
548553
}
549554
}
550555

551556
cc := c.cc
552557

553-
if root.linkNotify(n.ctx, v, cc, c.CycleInfo) {
554-
n.notify = append(n.notify, receiver{v, cc})
558+
if root.linkNotify(n.ctx, cc) {
559+
n.notify = append(n.notify, receiver{cc.src, cc})
555560
}
556561

557562
return old

internal/core/adt/eval.go

+2
Original file line numberDiff line numberDiff line change
@@ -1192,6 +1192,8 @@ type nodeContextState struct {
11921192
}
11931193

11941194
// A receiver receives notifications.
1195+
// cc is used for V3 and is nil in V2.
1196+
// v is equal to cc.src._cc in V3.
11951197
type receiver struct {
11961198
v *Vertex
11971199
cc *closeContext

internal/core/adt/fields.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -463,14 +463,14 @@ func (cc *closeContext) getKeyedCC(ctx *OpContext, key *closeContext, c CycleInf
463463
return arc
464464
}
465465

466-
func (cc *closeContext) linkNotify(ctx *OpContext, dst *Vertex, key *closeContext, c CycleInfo) bool {
466+
func (cc *closeContext) linkNotify(ctx *OpContext, key *closeContext) bool {
467467
for _, a := range cc.arcs {
468468
if a.key == key {
469469
return false
470470
}
471471
}
472472

473-
cc.addDependency(ctx, NOTIFY, false, key, key, dst.cc())
473+
cc.addDependency(ctx, NOTIFY, false, key, key, key.src.cc())
474474
return true
475475
}
476476

0 commit comments

Comments
 (0)