this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

internal/core/adt: remove requirement type

And change signature of containsDefID to
just take ID. This allows for some
optimizations down the line.

Issue #3981

Signed-off-by: Marcel van Lohuizen <mpvl@gmail.com>
Change-Id: Ia90df592e4cb4b05bdee01fd74236bb6dd63ef98
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1218724
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>

+15 -17
+15 -17
internal/core/adt/typocheck.go
··· 580 580 required = slices.Clone(required) 581 581 } 582 582 583 - n.filterSets(&required, func(n *nodeContext, a requirement) bool { 583 + n.filterSets(&required, func(n *nodeContext, a *reqSet) bool { 584 584 if hasParentEllipsis(n, a, n.conjunctInfo) { 585 585 a.removed = true 586 586 } ··· 644 644 func (n *nodeContext) hasEvidenceForOne(all reqSets, i uint32, conjuncts []conjunctInfo) bool { 645 645 a := all[i] 646 646 for _, x := range conjuncts { 647 - if n.containsDefID(&a, x.id) { 647 + if n.containsDefID(a.id, x.id) { 648 648 return true 649 649 } 650 650 } ··· 663 663 664 664 outer: 665 665 for _, c := range conjuncts { 666 - if n.containsDefID(&embedScope, c.embed) { 666 + if n.containsDefID(embedScope.id, c.embed) { 667 667 // Within the scope of the embedding. 668 668 continue outer 669 669 } ··· 675 675 // If this conjunct is within the outer struct, but outside the 676 676 // embedding scope, this means it was "added" and we do not have 677 677 // to verify it within the embedding scope. 678 - if n.containsDefID(&outerScope, c.id) { 678 + if n.containsDefID(outerScope.id, c.id) { 679 679 return true 680 680 } 681 681 } 682 682 return false 683 683 } 684 684 685 - func (n *nodeContext) containsDefID(node requirement, child defID) bool { 685 + func (n *nodeContext) containsDefID(node, child defID) bool { 686 686 // TODO(perf): cache result 687 687 // TODO(perf): we could keep track of the minimum defID that could map so 688 688 // that we can use this to bail out early. ··· 699 699 c.stats.MaxRedirect = int64(len(c.redirectsBuf)) 700 700 } 701 701 702 - return n.containsDefIDRec(node.id, child) 702 + return n.containsDefIDRec(node, child) 703 703 } 704 704 705 705 func (n *nodeContext) containsDefIDRec(node, child defID) bool { ··· 734 734 // elements, size indicates the number of entries in the set, including the 735 735 // head. For non-head elements, size is 0. 736 736 type reqSets []reqSet 737 - 738 - type requirement *reqSet 739 737 740 738 // A single reqID might be satisfied by multiple defIDs, if the definition 741 739 // associated with the reqID embeds other definitions, for instance. In this ··· 886 884 // If 'v' is a hidden field, then all reqSets in 'a' for which there is no 887 885 // corresponding entry in conjunctInfo should be removed from 'a'. 888 886 if allowedInClosed(v.Label) { 889 - n.filterSets(&a, func(n *nodeContext, a requirement) bool { 887 + n.filterSets(&a, func(n *nodeContext, a *reqSet) bool { 890 888 for _, c := range n.conjunctInfo { 891 - if n.containsDefID(requirement(a), c.id) { 889 + if n.containsDefID(a.id, c.id) { 892 890 return true // keep the set 893 891 } 894 892 } ··· 914 912 // If there is a top or ellipsis for all supported conjuncts, we have 915 913 // evidence that this node can be dropped. 916 914 func (n *nodeContext) filterTop(a *reqSets, conjuncts, parentConjuncts []conjunctInfo) (openLevel bool) { 917 - n.filterSets(a, func(n *nodeContext, a requirement) bool { 915 + n.filterSets(a, func(n *nodeContext, a *reqSet) bool { 918 916 var f conjunctFlags 919 917 hasAny := false 920 918 921 919 for _, c := range conjuncts { 922 - if n.containsDefID(requirement(a), c.id) { 920 + if n.containsDefID(a.id, c.id) { 923 921 hasAny = true 924 922 flags := c.flags 925 923 if c.id < a.id { ··· 945 943 // TODO: this is currently called twice. Consider an approach where we only need 946 944 // to filter this once for each node. Luckily we can avoid quadratic checks 947 945 // for any conjunct that is not an ellipsis, which is most. 948 - func hasParentEllipsis(n *nodeContext, a requirement, conjuncts []conjunctInfo) bool { 946 + func hasParentEllipsis(n *nodeContext, a *reqSet, conjuncts []conjunctInfo) bool { 949 947 for _, c := range conjuncts { 950 948 if !c.flags.hasEllipsis() { 951 949 continue 952 950 } 953 - if n.containsDefID(requirement(a), c.id) { 951 + if n.containsDefID(a.id, c.id) { 954 952 return true 955 953 } 956 954 } ··· 958 956 } 959 957 960 958 func (n *nodeContext) filterNonRecursive(a *reqSets) { 961 - n.filterSets(a, func(n *nodeContext, e requirement) bool { 959 + n.filterSets(a, func(n *nodeContext, e *reqSet) bool { 962 960 x := e 963 961 if x.once { // || x.id == 0 964 962 e.ignored = true ··· 968 966 } 969 967 970 968 // filter keeps all reqSets e in a for which f(e) and removes the rest. 971 - func (n *nodeContext) filterSets(a *reqSets, f func(n *nodeContext, e requirement) bool) { 969 + func (n *nodeContext) filterSets(a *reqSets, f func(n *nodeContext, e *reqSet) bool) { 972 970 temp := (*a)[:0] 973 971 for i := range *a { 974 972 set := (*a)[i] 975 973 976 - if f(n, requirement(&set)) { 974 + if f(n, &set) { 977 975 temp = append(temp, set) 978 976 } 979 977 }