@@ -650,42 +650,19 @@ void PropertyBag::copyPropertiesFrom(const PropertyBag *next,
650
650
}
651
651
}
652
652
653
- // / Look for an property bag corresponding to the given key, returning nullptr
654
- // / if one has not been recorded.
655
- PropertyBag *
656
- PropertyMap::getPropertiesIfPresent (const MutableTerm &key) const {
657
- assert (!key.empty ());
658
-
659
- for (const auto &props : Map) {
660
- int compare = props->getKey ().compare (key, Protos);
661
- if (compare == 0 )
662
- return props.get ();
663
- if (compare > 0 )
664
- return nullptr ;
665
- }
666
-
667
- return nullptr ;
653
+ PropertyMap::~PropertyMap () {
654
+ Trie.updateHistograms (Context.PropertyTrieHistogram ,
655
+ Context.PropertyTrieRootHistogram );
656
+ clear ();
668
657
}
669
658
670
659
// / Look for an property bag corresponding to a suffix of the given key.
671
660
// /
672
661
// / Returns nullptr if no information is known about this key.
673
662
PropertyBag *
674
663
PropertyMap::lookUpProperties (const MutableTerm &key) const {
675
- if (auto *props = getPropertiesIfPresent (key))
676
- return props;
677
-
678
- auto begin = key.begin () + 1 ;
679
- auto end = key.end ();
680
-
681
- while (begin != end) {
682
- MutableTerm suffix (begin, end);
683
-
684
- if (auto *suffixClass = getPropertiesIfPresent (suffix))
685
- return suffixClass;
686
-
687
- ++begin;
688
- }
664
+ if (auto result = Trie.find (key.rbegin (), key.rend ()))
665
+ return *result;
689
666
690
667
return nullptr ;
691
668
}
@@ -698,13 +675,10 @@ PropertyBag *
698
675
PropertyMap::getOrCreateProperties (const MutableTerm &key) {
699
676
assert (!key.empty ());
700
677
701
- if (!Map.empty ()) {
702
- const auto &lastEquivClass = Map.back ();
703
- int compare = lastEquivClass->getKey ().compare (key, Protos);
704
- if (compare == 0 )
705
- return lastEquivClass.get ();
706
-
707
- assert (compare < 0 && " Must record property bags in sorted order" );
678
+ if (!Entries.empty ()) {
679
+ const auto &lastEntry = Entries.back ();
680
+ if (lastEntry->getKey () == key)
681
+ return lastEntry;
708
682
}
709
683
710
684
auto *props = new PropertyBag (key);
@@ -733,13 +707,31 @@ PropertyMap::getOrCreateProperties(const MutableTerm &key) {
733
707
if (auto *next = lookUpProperties (key))
734
708
props->copyPropertiesFrom (next, Context);
735
709
736
- Map.emplace_back (props);
710
+ // Here is where we make the assumption that if the new key is not equal to
711
+ // the key of the last entry, then it is larger than any key already in the
712
+ // map.
713
+ Entries.push_back (props);
714
+ auto oldProps = Trie.insert (key.rbegin (), key.rend (), props);
715
+ if (oldProps) {
716
+ llvm::errs () << " Duplicate property map entry for " << key << " \n " ;
717
+ llvm::errs () << " Old:\n " ;
718
+ (*oldProps)->dump (llvm::errs ());
719
+ llvm::errs () << " \n " ;
720
+ llvm::errs () << " New:\n " ;
721
+ props->dump (llvm::errs ());
722
+ llvm::errs () << " \n " ;
723
+ abort ();
724
+ }
737
725
738
726
return props;
739
727
}
740
728
741
729
void PropertyMap::clear () {
742
- Map.clear ();
730
+ for (auto *props : Entries)
731
+ delete props;
732
+
733
+ Trie.clear ();
734
+ Entries.clear ();
743
735
ConcreteTypeInDomainMap.clear ();
744
736
}
745
737
@@ -757,7 +749,7 @@ void PropertyMap::addProperty(
757
749
// / For each fully-concrete type, find the shortest term having that concrete type.
758
750
// / This is later used by computeConstraintTermForTypeWitness().
759
751
void PropertyMap::computeConcreteTypeInDomainMap () {
760
- for (const auto &props : Map ) {
752
+ for (const auto &props : Entries ) {
761
753
if (!props->isConcreteType ())
762
754
continue ;
763
755
@@ -787,7 +779,7 @@ void PropertyMap::computeConcreteTypeInDomainMap() {
787
779
788
780
void PropertyMap::concretizeNestedTypesFromConcreteParents (
789
781
SmallVectorImpl<std::pair<MutableTerm, MutableTerm>> &inducedRules) const {
790
- for (const auto &props : Map ) {
782
+ for (const auto &props : Entries ) {
791
783
if (props->getConformsTo ().empty ())
792
784
continue ;
793
785
@@ -1030,7 +1022,7 @@ MutableTerm PropertyMap::computeConstraintTermForTypeWitness(
1030
1022
1031
1023
void PropertyMap::dump (llvm::raw_ostream &out) const {
1032
1024
out << " Property map: {\n " ;
1033
- for (const auto &props : Map ) {
1025
+ for (const auto &props : Entries ) {
1034
1026
out << " " ;
1035
1027
props->dump (out);
1036
1028
out << " \n " ;
0 commit comments