Skip to content

Commit 2d4263e

Browse files
committed
internal/core/adt: simplify recursive getReqSets calls
The call can be skipped entirely if n.dropParentRequirements is true, given that the result goes entirely unused. Similarly, a is empty if we don't append from the recursive call, so move the call to filterNonRecursive inside the conditional too. While here, set computedCloseInfo to true once we set reqSets. Resetting the length of reqSets upfront is also unnecessary, as it's always 0 when we start here. No visible change to the two benchmarks I'm using for #3881, but this is still helping clarify that the code is not doing something else that isn't obvious here, like a side effect. Signed-off-by: Daniel Martí <[email protected]> Change-Id: I321b561ecf56667dcd91fccc351727ca80c093e5 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1217195 Reviewed-by: Marcel van Lohuizen <[email protected]> Unity-Result: CUE porcuepine <[email protected]> TryBot-Result: CUEcueckoo <[email protected]>
1 parent 450ba7f commit 2d4263e

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

internal/core/adt/typocheck.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -883,19 +883,14 @@ func getReqSets(n *nodeContext) reqSets {
883883
if n.computedCloseInfo {
884884
return n.reqSets
885885
}
886-
n.reqSets = n.reqSets[:0]
887-
n.computedCloseInfo = true
888886

889887
a := n.reqSets
890888
v := n.node
891889

892-
if p := v.Parent; p != nil {
893-
aReq := getReqSets(p.state)
894-
if !n.dropParentRequirements {
895-
a = append(a, aReq...)
896-
}
890+
if p := v.Parent; p != nil && !n.dropParentRequirements {
891+
a = append(a, getReqSets(p.state)...)
892+
a.filterNonRecursive()
897893
}
898-
a.filterNonRecursive()
899894

900895
last := len(a) - 1
901896

@@ -972,6 +967,7 @@ outer:
972967

973968
a.filterTop(n.conjunctInfo, parentConjuncts)
974969

970+
n.computedCloseInfo = true
975971
n.reqSets = a
976972
return a
977973
}

0 commit comments

Comments
 (0)