@@ -44,6 +44,16 @@ namespace rewriting {
4444class MutableTerm ;
4545class Term ;
4646
47+ // / Records a superclass constraint at a given level in the class hierarchy.
48+ struct SuperclassRequirement {
49+ // / The most specific superclass constraint (in type difference order) for
50+ // / this level in the class hierarchy.
51+ Optional<Symbol> SuperclassType;
52+
53+ // / The corresponding superclass rule for the above.
54+ Optional<unsigned > SuperclassRule;
55+ };
56+
4757// / Stores a convenient representation of all "property-like" rewrite rules of
4858// / the form T.[p] => T, where [p] is a property symbol, for some term 'T'.
4959class PropertyBag {
@@ -64,11 +74,14 @@ class PropertyBag {
6474 // / The corresponding layout rule for the above.
6575 Optional<unsigned > LayoutRule;
6676
67- // / The most specific superclass constraint this type satisfies.
68- Optional<Symbol> Superclass;
77+ // / The most specific superclass declaration for which this type has a
78+ // / superclass constraint.
79+ const ClassDecl *SuperclassDecl = nullptr ;
6980
70- // / The corresponding superclass rule for the above.
71- Optional<unsigned > SuperclassRule;
81+ // / Used for unifying superclass rules at different levels in the class
82+ // / hierarchy. For each class declaration, stores a symbol and rule pair
83+ // / for the most specific substituted type.
84+ llvm::SmallDenseMap<const ClassDecl *, SuperclassRequirement, 2 > Superclasses;
7285
7386 // / All concrete conformances of Superclass to the protocols in the
7487 // / ConformsTo list.
@@ -97,16 +110,22 @@ class PropertyBag {
97110 PropertyBag &operator =(const PropertyBag &) = delete ;
98111 PropertyBag &operator =(PropertyBag &&) = delete ;
99112
113+ const SuperclassRequirement &getSuperclassRequirement () const {
114+ assert (SuperclassDecl != nullptr );
115+ auto found = Superclasses.find (SuperclassDecl);
116+ return found->second ;
117+ }
118+
100119public:
101120 Term getKey () const { return Key; }
102121 void dump (llvm::raw_ostream &out) const ;
103122
104123 bool hasSuperclassBound () const {
105- return Superclass. hasValue () ;
124+ return SuperclassDecl != nullptr ;
106125 }
107126
108127 CanType getSuperclassBound () const {
109- return Superclass ->getConcreteType ();
128+ return getSuperclassRequirement (). SuperclassType ->getConcreteType ();
110129 }
111130
112131 Type getSuperclassBound (
@@ -250,6 +269,18 @@ class PropertyMap {
250269
251270 void addConformanceProperty (Term key, Symbol property, unsigned ruleID);
252271 void addLayoutProperty (Term key, Symbol property, unsigned ruleID);
272+
273+ void unifyConcreteTypes (Term key,
274+ Optional<Symbol> &existingProperty,
275+ Optional<unsigned > &existingRuleID,
276+ Symbol property,
277+ unsigned ruleID);
278+
279+ void recordSuperclassRelation (Term key,
280+ Symbol superclassType,
281+ unsigned superclassRuleID,
282+ const ClassDecl *otherClass);
283+
253284 void addSuperclassProperty (Term key, Symbol property, unsigned ruleID);
254285 void addConcreteTypeProperty (Term key, Symbol property, unsigned ruleID);
255286
0 commit comments