Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

Commit

Permalink
internal/core/adt: remove all closedness IDs in ToData
Browse files Browse the repository at this point in the history
The current algorithm missed some, causing closedness
to be misalligned down the line.

Fixes #526

Change-Id: I177a8f65ae5e8322328baf4224b69ce52c6a5d1e
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/7142
Reviewed-by: Paul Jolly <paul@myitcv.org.uk>
  • Loading branch information
mpvl committed Sep 17, 2020
1 parent 1e1fe6f commit f5fa009
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
12 changes: 12 additions & 0 deletions cmd/cue/cmd/testdata/script/issue526.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
cue cmd gengithub

-- x.cue --
package x

test: #Workflow
#Workflow: 1 | [_]

-- x_tool.cue --
package x

command: gengithub: {}
38 changes: 34 additions & 4 deletions internal/core/adt/composite.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,17 +279,50 @@ func (v *Vertex) ToDataAll() *Vertex {
arcs[i] = a.ToDataAll()
}
w := *v

w.Value = toDataAll(w.Value)
w.Arcs = arcs
w.isData = true
w.Conjuncts = make([]Conjunct, len(v.Conjuncts))
copy(w.Conjuncts, v.Conjuncts)
for i := range w.Conjuncts {
for i, c := range w.Conjuncts {
w.Conjuncts[i].CloseID = 0
if v, _ := c.x.(Value); v != nil {
w.Conjuncts[i].x = toDataAll(v)
}
}
w.Closed = nil
return &w
}

func toDataAll(v Value) Value {
switch x := v.(type) {
default:
return x

case *Vertex:
return x.ToDataAll()

// The following cases are always erroneous, but we handle them anyway
// to avoid issues with the closedness algorithm down the line.
case *Disjunction:
d := *x
d.Values = make([]*Vertex, len(x.Values))
for i, v := range x.Values {
d.Values[i] = v.ToDataAll()
}
return &d

case *Conjunction:
c := *x
c.Values = make([]Value, len(x.Values))
for i, v := range x.Values {
c.Values[i] = toDataAll(v)
}
return &c
}
}

// func (v *Vertex) IsEvaluating() bool {
// return v.Value == cycle
// }
Expand All @@ -314,9 +347,6 @@ func (v *Vertex) Err(c *OpContext, state VertexStatus) *Bottom {
// func (v *Vertex) Evaluate()

func (v *Vertex) Finalize(c *OpContext) {
if c == nil {
fmt.Println("WOT?")
}
c.Unify(c, v, Finalized)
}

Expand Down

0 comments on commit f5fa009

Please sign in to comment.