3737using namespace swift ;
3838using namespace rewriting ;
3939
40+ // / Returns true if we have not processed this rule before.
41+ bool PropertyMap::checkRuleOnce (unsigned ruleID) {
42+ return CheckedRules.insert (ruleID).second ;
43+ }
44+
4045// / Returns true if we have not processed this pair of rules before.
4146bool PropertyMap::checkRulePairOnce (unsigned firstRuleID,
4247 unsigned secondRuleID) {
@@ -65,7 +70,7 @@ RewriteSystem::getRelation(unsigned index) const {
6570}
6671
6772// / Given a key T, a rule (V.[p1] => V) where T == U.V, and a property [p2]
68- // / where [p1] < [p2], record a rule (T.[p2] => T) that is implied by
73+ // / where [p1] < [p2], record a rule (T.[p2] => T) that is induced by
6974// / the original rule (V.[p1] => V).
7075static void recordRelation (Term key,
7176 unsigned lhsRuleID,
@@ -80,7 +85,9 @@ static void recordRelation(Term key,
8085
8186 assert (lhsProperty.isProperty ());
8287 assert (rhsProperty.isProperty ());
83- assert (lhsProperty.getKind () == rhsProperty.getKind ());
88+ assert (lhsProperty.getKind () == rhsProperty.getKind () ||
89+ (lhsProperty.getKind () == Symbol::Kind::Superclass &&
90+ rhsProperty.getKind () == Symbol::Kind::Layout));
8491
8592 if (debug) {
8693 llvm::dbgs () << " %% Recording relation: " ;
@@ -474,6 +481,21 @@ void PropertyMap::addProperty(
474481 case Symbol::Kind::Superclass: {
475482 // FIXME: Also handle superclass vs concrete
476483
484+ if (checkRuleOnce (ruleID)) {
485+ // A rule (T.[superclass: C] => T) induces a rule (T.[layout: L] => T),
486+ // where L is either AnyObject or _NativeObject.
487+ auto superclass =
488+ property.getSuperclass ()->getClassOrBoundGenericClass ();
489+ auto layout =
490+ LayoutConstraint::getLayoutConstraint (
491+ superclass->getLayoutConstraintKind (),
492+ Context.getASTContext ());
493+ auto layoutSymbol = Symbol::forLayout (layout, Context);
494+
495+ recordRelation (key, ruleID, layoutSymbol, System,
496+ inducedRules, debug);
497+ }
498+
477499 if (!props->Superclass ) {
478500 props->Superclass = property;
479501 props->SuperclassRule = ruleID;
0 commit comments