Skip to content

Commit

Permalink
internal/core/adt: support bulk adding of conjuncts
Browse files Browse the repository at this point in the history
This allows us to remove references to
Vertex.Conjuncts in a few more occasions.

It is assumed that in all cases we are modifying
nodes pre evaluation.

Signed-off-by: Marcel van Lohuizen <mpvl@gmail.com>
Change-Id: Ia2bedb0ea4f2a73e3b31cdcbdca78e7792ac14cf
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1202661
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Matthew Sackman <matthew@cue.works>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
  • Loading branch information
mpvl committed Oct 21, 2024
1 parent d21405c commit b990eb7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
6 changes: 6 additions & 0 deletions internal/core/adt/composite.go
Original file line number Diff line number Diff line change
Expand Up @@ -1252,6 +1252,12 @@ func (v *Vertex) InsertConjunct(c Conjunct) {
v.Conjuncts = append(v.Conjuncts, c)
}

// InsertConjunctsFrom is a low-level method to insert a conjuncts into a Vertex
// from another Vertex.
func (v *Vertex) InsertConjunctsFrom(w *Vertex) {
v.Conjuncts = append(v.Conjuncts, w.Conjuncts...)
}

// AddConjunct adds the given Conjuncts to v if it doesn't already exist.
func (v *Vertex) AddConjunct(c Conjunct) *Bottom {
if v.BaseValue != nil && !isCyclePlaceholder(v.BaseValue) {
Expand Down
16 changes: 4 additions & 12 deletions pkg/list/sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,8 @@ func (s *valueSorter) Less(i, j int) bool {
saveX := *s.x
saveY := *s.y

for _, c := range x.V.Conjuncts {
s.x.AddConjunct(c)
}
for _, c := range y.V.Conjuncts {
s.y.AddConjunct(c)
}
s.x.InsertConjunctsFrom(x.V)
s.y.InsertConjunctsFrom(y.V)

// TODO(perf): if we can determine that the comparator values for
// x and y are idempotent (no arcs and a basevalue being top or
Expand Down Expand Up @@ -121,12 +117,8 @@ func (s *valueSorter) lessNew(i, j int) bool {
s.a[i].Core(&x)
s.a[j].Core(&y)

for _, c := range x.V.Conjuncts {
xa.AddConjunct(c)
}
for _, c := range y.V.Conjuncts {
ya.AddConjunct(c)
}
xa.InsertConjunctsFrom(x.V)
ya.InsertConjunctsFrom(y.V)

// TODO(perf): if we can determine that the comparator values for
// x and y are idempotent (no arcs and a basevalue being top or
Expand Down
2 changes: 1 addition & 1 deletion tools/trim/trim.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func (t *trimmer) addDominators(d, v *adt.Vertex, hasDisjunction bool) (doms *ad
Label: v.Label,
}
if d != nil && hasDisjunction {
doms.Conjuncts = append(doms.Conjuncts, d.Conjuncts...)
doms.InsertConjunctsFrom(d)
}

hasDoms := false
Expand Down

0 comments on commit b990eb7

Please sign in to comment.