this repo has no description
0
fork

Configure Feed

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

internal/core/adt: add wrapper for inline Vertex

When working on the evaluator and changing the
representation of Vertex, it is important to consider all
instantiations of it. A common case is an "inline" Vertex,
which does not have a place in the evaluation tree (does not
correspond to a CUE path), but is part of the computation.
This is treated slightly different for structural cycle detection.

Creating these with a special wrapper reduces the number of
literal Vertex values in the code.

Signed-off-by: Marcel van Lohuizen <mpvl@gmail.com>
Change-Id: I5b9732973bb961c3f5be6192223b7752fa534667
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/551887
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>
Unity-Result: CUEcueckoo <cueckoo@cuelang.org>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>

+21 -32
+2 -4
internal/core/adt/binop.go
··· 205 205 }, 206 206 } 207 207 208 - n := &Vertex{} 209 - n.AddConjunct(MakeConjunct(c.Env(0), list, c.ci)) 208 + n := c.newInlineVertex(nil, nil, MakeConjunct(c.Env(0), list, c.ci)) 210 209 n.CompleteArcs(c) 211 210 212 211 return n ··· 267 266 return err 268 267 } 269 268 270 - n := &Vertex{} 271 - n.AddConjunct(MakeConjunct(c.Env(0), list, c.ci)) 269 + n := c.newInlineVertex(nil, nil, MakeConjunct(c.Env(0), list, c.ci)) 272 270 n.CompleteArcs(c) 273 271 274 272 return n
+12
internal/core/adt/composite.go
··· 230 230 Structs []*StructInfo 231 231 } 232 232 233 + // newInlineVertex creates a Vertex that is needed for computation, but for 234 + // which there is no CUE path defined from the root Vertex. 235 + func (ctx *OpContext) newInlineVertex(parent *Vertex, v BaseValue, a ...Conjunct) *Vertex { 236 + return &Vertex{ 237 + Parent: parent, 238 + BaseValue: v, 239 + IsDynamic: true, 240 + ArcType: ArcMember, 241 + Conjuncts: a, 242 + } 243 + } 244 + 233 245 // updateArcType updates v.ArcType if t is more restrictive. 234 246 func (v *Vertex) updateArcType(t ArcType) { 235 247 if t < v.ArcType {
+2 -9
internal/core/adt/context.go
··· 1302 1302 } 1303 1303 1304 1304 func (c *OpContext) newList(src ast.Node, parent *Vertex) *Vertex { 1305 - return &Vertex{ 1306 - Parent: parent, 1307 - BaseValue: &ListMarker{}, 1308 - IsDynamic: true, 1309 - } 1305 + return c.newInlineVertex(parent, &ListMarker{}) 1310 1306 } 1311 1307 1312 1308 // Str reports a debug string of x. ··· 1321 1317 func (c *OpContext) NewList(values ...Value) *Vertex { 1322 1318 // TODO: consider making this a literal list instead. 1323 1319 list := &ListLit{} 1324 - v := &Vertex{ 1325 - IsDynamic: true, 1326 - Conjuncts: []Conjunct{{Env: nil, x: list}}, 1327 - } 1320 + v := c.newInlineVertex(nil, nil, Conjunct{Env: nil, x: list}) 1328 1321 1329 1322 for _, x := range values { 1330 1323 list.Elems = append(list.Elems, x)
+5 -19
internal/core/adt/expr.go
··· 73 73 74 74 func (x *StructLit) evaluate(c *OpContext, state vertexStatus) Value { 75 75 e := c.Env(0) 76 - v := &Vertex{ 77 - Parent: e.Vertex, 78 - IsDynamic: true, 79 - Conjuncts: []Conjunct{{e, x, c.ci}}, 80 - } 76 + v := c.newInlineVertex(e.Vertex, nil, Conjunct{e, x, c.ci}) 81 77 // evaluate may not finalize a field, as the resulting value may be 82 78 // used in a context where more conjuncts are added. It may also lead 83 79 // to disjuncts being in a partially expanded state, leading to ··· 287 283 288 284 func (x *ListLit) evaluate(c *OpContext, state vertexStatus) Value { 289 285 e := c.Env(0) 290 - v := &Vertex{ 291 - Parent: e.Vertex, 292 - IsDynamic: true, 293 - Conjuncts: []Conjunct{{e, x, c.ci}}, 294 - } 286 + v := c.newInlineVertex(e.Vertex, nil, Conjunct{e, x, c.ci}) 295 287 v.CompleteArcs(c) 296 288 return v 297 289 } ··· 1239 1231 func (x *BinaryExpr) evaluate(c *OpContext, state vertexStatus) Value { 1240 1232 env := c.Env(0) 1241 1233 if x.Op == AndOp { 1242 - v := &Vertex{ 1243 - IsDynamic: true, 1244 - Conjuncts: []Conjunct{makeAnonymousConjunct(env, x, c.ci.Refs)}, 1245 - } 1234 + v := c.newInlineVertex(nil, nil, makeAnonymousConjunct(env, x, c.ci.Refs)) 1246 1235 1247 1236 // Do not fully evaluate the Vertex: if it is embedded within a 1248 1237 // struct with arcs that are referenced from within this expression, ··· 1602 1591 if _, ok := v.(*BasicType); !ok { 1603 1592 env := c.Env(0) 1604 1593 x := &BinaryExpr{Op: AndOp, X: v, Y: a} 1605 - n := &Vertex{ 1606 - IsDynamic: true, 1607 - Conjuncts: []Conjunct{{env, x, c.ci}}, 1608 - } 1594 + n := c.newInlineVertex(nil, nil, Conjunct{env, x, c.ci}) 1609 1595 n.Finalize(c) 1610 1596 if _, ok := n.BaseValue.(*Bottom); ok { 1611 1597 c.addErrf(0, pos(a), ··· 1740 1726 1741 1727 func (x *DisjunctionExpr) evaluate(c *OpContext, state vertexStatus) Value { 1742 1728 e := c.Env(0) 1743 - v := &Vertex{Conjuncts: []Conjunct{{e, x, c.ci}}} 1729 + v := c.newInlineVertex(nil, nil, Conjunct{e, x, c.ci}) 1744 1730 v.Finalize(c) // TODO: also partial okay? 1745 1731 // TODO: if the disjunction result originated from a literal value, we may 1746 1732 // consider the result closed to create more permanent errors.