Skip to content

Commit bf54346

Browse files
committed
internal/core/adt: split updateCyclicStatus based on version
This makes it easier to track the code from which this function is called for a specific version of the evaluator. Issue #2850 Signed-off-by: Marcel van Lohuizen <[email protected]> Change-Id: I0dcaf339d931a6a8979a92b644588fcc06874790 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1201893 TryBot-Result: CUEcueckoo <[email protected]> Unity-Result: CUE porcuepine <[email protected]> Reviewed-by: Matthew Sackman <[email protected]>
1 parent 6b73188 commit bf54346

File tree

3 files changed

+31
-22
lines changed

3 files changed

+31
-22
lines changed

internal/core/adt/conjunct.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ func (n *nodeContext) scheduleConjunct(c Conjunct, id CloseInfo) {
181181
n.unshare()
182182

183183
// At this point we known we have at least an empty list.
184-
n.updateCyclicStatus(id)
184+
n.updateCyclicStatusV3(id)
185185

186186
env := &Environment{
187187
Up: env,
@@ -234,7 +234,7 @@ func (n *nodeContext) scheduleConjunct(c Conjunct, id CloseInfo) {
234234
func (n *nodeContext) scheduleStruct(env *Environment,
235235
s *StructLit,
236236
ci CloseInfo) {
237-
n.updateCyclicStatus(ci)
237+
n.updateCyclicStatusV3(ci)
238238

239239
// NOTE: This is a crucial point in the code:
240240
// Unification dereferencing happens here. The child nodes are set to
@@ -537,7 +537,7 @@ func (n *nodeContext) addNotify2(v *Vertex, c CloseInfo) []receiver {
537537
// Literal conjuncts
538538

539539
func (n *nodeContext) insertValueConjunct(env *Environment, v Value, id CloseInfo) {
540-
n.updateCyclicStatus(id)
540+
n.updateCyclicStatusV3(id)
541541

542542
ctx := n.ctx
543543

@@ -571,7 +571,7 @@ func (n *nodeContext) insertValueConjunct(env *Environment, v Value, id CloseInf
571571
panic(fmt.Sprintf("invalid type %T", x.BaseValue))
572572

573573
case *ListMarker:
574-
n.updateCyclicStatus(id)
574+
n.updateCyclicStatusV3(id)
575575

576576
// TODO: arguably we know now that the type _must_ be a list.
577577
n.scheduleTask(handleListVertex, env, x, id)

internal/core/adt/cycle.go

+26-17
Original file line numberDiff line numberDiff line change
@@ -575,20 +575,30 @@ func getNonCyclicCount(c Conjunct) int {
575575
}
576576
}
577577

578+
// updateCyclicStatusV3 looks for proof of non-cyclic conjuncts to override
579+
// a structural cycle.
580+
func (n *nodeContext) updateCyclicStatusV3(c CloseInfo) {
581+
if !c.IsCyclic {
582+
n.hasNonCycle = true
583+
for _, c := range n.cyclicConjuncts {
584+
ci := c.c.CloseInfo
585+
ci.cc = n.node.rootCloseContext(n.ctx)
586+
n.scheduleVertexConjuncts(c.c, c.arc, ci)
587+
n.node.cc.decDependent(n.ctx, DEFER, nil)
588+
}
589+
n.cyclicConjuncts = n.cyclicConjuncts[:0]
590+
}
591+
}
592+
578593
// updateCyclicStatus looks for proof of non-cyclic conjuncts to override
579594
// a structural cycle.
580595
func (n *nodeContext) updateCyclicStatus(c CloseInfo) {
596+
unreachableForDev(n.ctx)
597+
581598
if !c.IsCyclic {
582599
n.hasNonCycle = true
583600
for _, c := range n.cyclicConjuncts {
584-
if n.ctx.isDevVersion() {
585-
ci := c.c.CloseInfo
586-
ci.cc = n.node.rootCloseContext(n.ctx)
587-
n.scheduleVertexConjuncts(c.c, c.arc, ci)
588-
n.node.cc.decDependent(n.ctx, DEFER, nil)
589-
} else {
590-
n.addVertexConjuncts(c.c, c.arc, false)
591-
}
601+
n.addVertexConjuncts(c.c, c.arc, false)
592602
}
593603
n.cyclicConjuncts = n.cyclicConjuncts[:0]
594604
}
@@ -611,15 +621,14 @@ func assertStructuralCycle(n *nodeContext) bool {
611621
}
612622

613623
func (n *nodeContext) reportCycleError() {
614-
n.setBaseValue(CombineErrors(nil,
615-
n.node.Value(),
616-
&Bottom{
617-
Code: StructuralCycleError,
618-
Err: n.ctx.Newf("structural cycle"),
619-
Value: n.node.Value(),
620-
Node: n.node,
621-
// TODO: probably, this should have the referenced arc.
622-
}))
624+
b := &Bottom{
625+
Code: StructuralCycleError,
626+
Err: n.ctx.Newf("structural cycle"),
627+
Value: n.node.Value(),
628+
Node: n.node,
629+
// TODO: probably, this should have the referenced arc.
630+
}
631+
n.setBaseValue(CombineErrors(nil, n.node.Value(), b))
623632
n.node.Arcs = nil
624633
}
625634

internal/core/adt/tasks.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ func processListLit(c *OpContext, t *task, mode runMode) {
201201

202202
l := t.x.(*ListLit)
203203

204-
n.updateCyclicStatus(t.id)
204+
n.updateCyclicStatusV3(t.id)
205205

206206
var ellipsis Node
207207

0 commit comments

Comments
 (0)