Skip to content

Commit

Permalink
internal/core/adt: use Vertex.Indirect in more places
Browse files Browse the repository at this point in the history
This prepares for several things, including the
implementation of disjunctions and structure sharing.

Issue #2851
Issue #2884
Issue #2854

Signed-off-by: Marcel van Lohuizen <mpvl@gmail.com>
Change-Id: I831d5419e6b035667aae6f254f45456b34dfd93c
  • Loading branch information
mpvl committed Apr 2, 2024
1 parent 8cb84f5 commit 12df29f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
10 changes: 10 additions & 0 deletions internal/core/adt/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,11 @@ func (c *OpContext) evalState(v Expr, state combinedFlags) (result Value) {
if arc == nil {
return nil
}
// XXX: this should be in a standalone CL if it is on the path of
// the old evaluator as well.
// TODO: consider moving this after markCycle, depending on how we
// implement markCycle.
arc = arc.Indirect()

// Save the old CloseInfo and restore after evaluate to avoid detecting
// spurious cycles.
Expand Down Expand Up @@ -823,6 +828,11 @@ func (c *OpContext) unifyNode(v Expr, state combinedFlags) (result Value) {
if v == nil {
return nil
}
// XXX: this should be in a standalone CL if it is on the path of
// the old evaluator as well.
// TODO: consider moving this after markCycle, depending on how we
// implement markCycle.
v = v.Indirect()

if c.isDevVersion() {
if n := v.getState(c); n != nil {
Expand Down
3 changes: 3 additions & 0 deletions internal/core/adt/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ func processResolver(ctx *OpContext, t *task, mode runMode) {
// TODO: yield instead?
return
}
// TODO: consider moving after markCycle.
arc = arc.Indirect()

// A reference that points to itself indicates equality. In that case
// we are done computing and we can return the arc as is.
ci, skip := t.node.markCycle(arc, t.env, r, t.id)
Expand Down
11 changes: 11 additions & 0 deletions internal/core/adt/unify.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,17 @@ func (v *Vertex) unify(c *OpContext, needs condition, mode runMode) bool {

nodeOnlyNeeds := needs &^ (subFieldsProcessed)
n.process(nodeOnlyNeeds, mode)
w := v.Indirect() // Dereference the disjunction result.
if w != v {
if w.Closed {
// Should resolve with dereference.
v.Closed = true
}
v.ArcType = w.ArcType
v.ChildErrors = CombineErrors(nil, v.ChildErrors, w.ChildErrors)
v.Arcs = nil
return w.state.meets(needs)
}
n.updateScalar()

// First process all but the subfields.
Expand Down
1 change: 1 addition & 0 deletions internal/core/debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ func (w *printer) interpolation(x *adt.Interpolation) {
func (w *printer) node(n adt.Node) {
switch x := n.(type) {
case *adt.Vertex:
x = x.Indirect()
var kind adt.Kind
if x.BaseValue != nil {
kind = x.BaseValue.Kind()
Expand Down

0 comments on commit 12df29f

Please sign in to comment.