this repo has no description
0
fork

Configure Feed

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

internal/core: search harder for BinExprs in toposort

Finding explicit unifications (`a & b`) is essential for correct
construction of the graph of nodes, which is central to toposort. By
searching through a vertex's structinfo's Decls, we can find more
BinExprs, and so build more correct graphs.

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

+31 -21
+4 -4
internal/core/toposort/testdata/t.txtar
··· 202 202 t: 10 203 203 } 204 204 d6: { 205 + x: 3 206 + w: 4 205 207 z: 1 206 208 y: 2 207 - x: 3 208 - w: 4 209 209 za: 11 210 210 t: 10 211 211 } ··· 414 414 - w: 4 415 415 - z: 1 416 416 - y: 2 417 + + x: 3 418 + + w: 4 417 419 + z: 1 418 420 + y: 2 419 - + x: 3 420 - + w: 4 421 421 + za: 11 422 422 t: 10 423 423 }
+27 -17
internal/core/toposort/vertex.go
··· 291 291 }) 292 292 } 293 293 294 - // Explore our own conjuncts to find explicit unifications and 295 - // record as appropriate in the structMetas. 294 + // Explore our own conjuncts, and the decls from our StructList, to 295 + // find explicit unifications, and mark structMetas accordingly. 296 + var worklist []adt.Expr 296 297 v.VisitLeafConjuncts(func(c adt.Conjunct) bool { 297 298 debug("self conjunct field %p :: %T, expr %p :: %T\n", 298 299 c.Field(), c.Field(), c.Expr(), c.Expr()) 299 - worklist := []adt.Expr{c.Expr()} 300 - for len(worklist) != 0 { 301 - expr := worklist[0] 302 - worklist = worklist[1:] 303 - 304 - binExpr, ok := expr.(*adt.BinaryExpr) 305 - if !ok || binExpr.Op != adt.AndOp { 306 - continue 300 + worklist = append(worklist, c.Expr()) 301 + return true 302 + }) 303 + for _, si := range structInfos { 304 + for _, decl := range si.StructLit.Decls { 305 + if expr, ok := decl.(adt.Expr); ok { 306 + worklist = append(worklist, expr) 307 307 } 308 - for _, expr := range []adt.Expr{binExpr.X, binExpr.Y} { 309 - for _, sMeta := range nodeToStructMeta[expr] { 310 - sMeta.isExplicit = true 311 - } 308 + } 309 + } 310 + 311 + for len(worklist) != 0 { 312 + expr := worklist[0] 313 + worklist = worklist[1:] 314 + 315 + binExpr, ok := expr.(*adt.BinaryExpr) 316 + if !ok || binExpr.Op != adt.AndOp { 317 + continue 318 + } 319 + for _, expr := range []adt.Expr{binExpr.X, binExpr.Y} { 320 + for _, sMeta := range nodeToStructMeta[expr] { 321 + sMeta.isExplicit = true 322 + debug(" now explicit: %v\n", sMeta) 312 323 } 313 - worklist = append(worklist, binExpr.X, binExpr.Y) 314 324 } 315 - return true 316 - }) 325 + worklist = append(worklist, binExpr.X, binExpr.Y) 326 + } 317 327 318 328 return roots, outgoing 319 329 }