Skip to content

Commit 5ee4254

Browse files
committed
internal/core/adt: change signature
Prepare for refactoring Signed-off-by: Marcel van Lohuizen <mpvl@gmail.com> Change-Id: Ieac311cc87207269a46f802b0edbbf5c471c60cf Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1218693 Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com> TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
1 parent d987d88 commit 5ee4254

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

internal/core/adt/typocheck.go

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -560,8 +560,8 @@ func (n *nodeContext) checkTypos() {
560560
required.replaceIDs(ctx, na.replaceIDs...)
561561
}
562562

563-
required.filterSets(func(a []reqSet) bool {
564-
if hasParentEllipsis(a, n.conjunctInfo) {
563+
n.filterSets(&required, func(n *nodeContext, a requirement) bool {
564+
if hasParentEllipsis(n, a, n.conjunctInfo) {
565565
a[0].removed = true
566566
}
567567
return true
@@ -680,6 +680,8 @@ outer:
680680
// head. For non-head elements, size is 0.
681681
type reqSets []reqSet
682682

683+
type requirement []reqSet
684+
683685
// A single reqID might be satisfied by multiple defIDs, if the definition
684686
// associated with the reqID embeds other definitions, for instance. In this
685687
// case we keep a list of defIDs that may also be satisfied.
@@ -894,7 +896,7 @@ func getReqSets(n *nodeContext) reqSets {
894896

895897
if p := v.Parent; p != nil && !n.dropParentRequirements {
896898
a = append(a, getReqSets(p.state)...)
897-
a.filterNonRecursive()
899+
n.filterNonRecursive(&a)
898900
}
899901

900902
last := len(a) - 1
@@ -953,9 +955,9 @@ outer:
953955
// If 'v' is a hidden field, then all reqSets in 'a' for which there is no
954956
// corresponding entry in conjunctInfo should be removed from 'a'.
955957
if allowedInClosed(v.Label) {
956-
a.filterSets(func(a []reqSet) bool {
957-
for _, e := range a {
958-
for _, c := range n.conjunctInfo {
958+
n.filterSets(&a, func(n *nodeContext, a requirement) bool {
959+
for _, c := range n.conjunctInfo {
960+
for _, e := range a {
959961
if c.id == e.id {
960962
return true // keep the set
961963
}
@@ -970,7 +972,7 @@ outer:
970972
parentConjuncts = p.state.conjunctInfo
971973
}
972974

973-
a.filterTop(n.conjunctInfo, parentConjuncts)
975+
n.filterTop(&a, n.conjunctInfo, parentConjuncts)
974976

975977
n.computedCloseInfo = true
976978
n.reqSets = a
@@ -979,12 +981,12 @@ outer:
979981

980982
// If there is a top or ellipsis for all supported conjuncts, we have
981983
// evidence that this node can be dropped.
982-
func (a *reqSets) filterTop(conjuncts, parentConjuncts []conjunctInfo) (openLevel bool) {
983-
a.filterSets(func(a []reqSet) bool {
984+
func (n *nodeContext) filterTop(a *reqSets, conjuncts, parentConjuncts []conjunctInfo) (openLevel bool) {
985+
n.filterSets(a, func(n *nodeContext, a requirement) bool {
984986
var f conjunctFlags
985987
hasAny := false
986-
for _, e := range a {
987-
for _, c := range conjuncts {
988+
for _, c := range conjuncts {
989+
for _, e := range a {
988990
if e.id != c.id {
989991
continue
990992
}
@@ -999,7 +1001,7 @@ func (a *reqSets) filterTop(conjuncts, parentConjuncts []conjunctInfo) (openLeve
9991001
if (f.hasTop() && !f.hasStruct()) || f.forceOpen() {
10001002
return false
10011003
}
1002-
if !hasAny && hasParentEllipsis(a, parentConjuncts) {
1004+
if !hasAny && hasParentEllipsis(n, a, parentConjuncts) {
10031005
a[0].removed = true
10041006
}
10051007
return true
@@ -1013,7 +1015,7 @@ func (a *reqSets) filterTop(conjuncts, parentConjuncts []conjunctInfo) (openLeve
10131015
// TODO: this is currently called twice. Consider an approach where we only need
10141016
// to filter this once for each node. Luckily we can avoid quadratic checks
10151017
// for any conjunct that is not an ellipsis, which is most.
1016-
func hasParentEllipsis(a reqSets, conjuncts []conjunctInfo) bool {
1018+
func hasParentEllipsis(n *nodeContext, a requirement, conjuncts []conjunctInfo) bool {
10171019
for _, c := range conjuncts {
10181020
if !c.flags.hasEllipsis() {
10191021
continue
@@ -1027,8 +1029,8 @@ func hasParentEllipsis(a reqSets, conjuncts []conjunctInfo) bool {
10271029
return false
10281030
}
10291031

1030-
func (a *reqSets) filterNonRecursive() {
1031-
a.filterSets(func(e []reqSet) bool {
1032+
func (n *nodeContext) filterNonRecursive(a *reqSets) {
1033+
n.filterSets(a, func(n *nodeContext, e requirement) bool {
10321034
x := e[0]
10331035
if x.once { // || x.id == 0
10341036
e[0].ignored = true
@@ -1038,13 +1040,13 @@ func (a *reqSets) filterNonRecursive() {
10381040
}
10391041

10401042
// filter keeps all reqSets e in a for which f(e) and removes the rest.
1041-
func (a *reqSets) filterSets(f func(e []reqSet) bool) {
1043+
func (n *nodeContext) filterSets(a *reqSets, f func(n *nodeContext, e requirement) bool) {
10421044
temp := (*a)[:0]
10431045
for i := 0; i < len(*a); {
10441046
e := (*a)[i]
10451047
set := (*a)[i : i+int(e.size)]
10461048

1047-
if f(set) {
1049+
if f(n, requirement(set)) {
10481050
temp = append(temp, set...)
10491051
}
10501052

0 commit comments

Comments
 (0)