this repo has no description
0
fork

Configure Feed

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

internal/core/adt: move cycle state saving logic to Expr

The and builtin uses EvaluateKeepState to weave
cycle information into further evaluation. This should
generally be done if Expr is used. We therefore move that
logic to Expr directly, so that this complicated piece
of code does not proliferate.

Issue #3649

Signed-off-by: Marcel van Lohuizen <mpvl@gmail.com>
Change-Id: Ib9460b0cf8e09065dc3a9b5a42f9f349c03d6fdc
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1208687
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Matthew Sackman <matthew@cue.works>

+7 -6
+5 -2
internal/core/adt/call.go
··· 75 75 // 76 76 // This method of getting an argument should be used when the argument is used 77 77 // as a schema and may contain cycles. 78 - func (c *CallContext) Expr(i int) Expr { 78 + func (c *CallContext) Expr(i int) Value { 79 79 // If the call context represents a validator call, the argument will be 80 80 // offset by 1. 81 81 if c.isValidator { ··· 85 85 } 86 86 i-- 87 87 } 88 - return c.call.Args[i] 88 + x := c.call.Args[i] 89 + 90 + // Evaluated while keeping any cycle information in the context. 91 + return c.ctx.EvaluateKeepState(x) 89 92 } 90 93 91 94 func (c *CallContext) Errf(format string, args ...interface{}) *Bottom {
+1 -1
internal/core/adt/context.go
··· 563 563 return val, true 564 564 } 565 565 566 - // EvaluateKeepState does an evaluate, but leaves any errors an cycle info 566 + // EvaluateKeepState does an evaluate, but leaves any errors and cycle info 567 567 // within the context. 568 568 func (c *OpContext) EvaluateKeepState(x Expr) (result Value) { 569 569 src := c.src
+1 -3
internal/core/compile/builtin.go
··· 120 120 c := call.OpContext() 121 121 arg := call.Expr(0) 122 122 123 - // Pass through the cycle information from evaluating the first argument. 124 - v := c.EvaluateKeepState(arg) 125 - list := c.RawElems(v) 123 + list := c.RawElems(arg) 126 124 if len(list) == 0 { 127 125 return &adt.Top{} 128 126 }