@@ -244,36 +244,25 @@ void RewriteSystem::propagateRedundantRequirementIDs() {
244244 }
245245}
246246
247- // / After propagating the 'explicit' bit on rules, process pairs of
248- // / conflicting rules, marking one or both of the rules as conflicting,
249- // / which instructs minimization to drop them.
247+ // / Process pairs of conflicting rules, marking the more specific rule as
248+ // / conflicting, which instructs minimization to drop this rule.
250249void RewriteSystem::processConflicts () {
251250 for (auto pair : ConflictingRules) {
252- auto existingRuleID = pair.first ;
253- auto newRuleID = pair.second ;
254-
255- auto *existingRule = &getRule (existingRuleID);
256- auto *newRule = &getRule (newRuleID);
257-
258- auto existingKind = existingRule->isPropertyRule ()->getKind ();
259- auto newKind = newRule->isPropertyRule ()->getKind ();
260-
261- // The GSB preferred to drop an explicit rule in a conflict, but
262- // only if the kinds were the same.
263- if (existingRule->isExplicit () && !newRule->isExplicit () &&
264- existingKind == newKind) {
265- std::swap (existingRule, newRule);
266- }
267-
268- if (newRule->getRHS ().size () >= existingRule->getRHS ().size ()) {
251+ auto *existingRule = &getRule (pair.first );
252+ auto *newRule = &getRule (pair.second );
253+
254+ // The identity conformance rule ([P].[P] => [P]) will conflict with
255+ // a concrete type requirement in an invalid protocol declaration
256+ // where 'Self' is constrained to a type that does not conform to
257+ // the protocol. This rule is permanent, so don't mark it as
258+ // conflicting in this case.
259+
260+ if (!existingRule->isIdentityConformanceRule () &&
261+ existingRule->getRHS ().size () >= newRule->getRHS ().size ())
262+ existingRule->markConflicting ();
263+ if (!newRule->isIdentityConformanceRule () &&
264+ newRule->getRHS ().size () >= existingRule->getRHS ().size ())
269265 newRule->markConflicting ();
270- } else if (existingKind != Symbol::Kind::Superclass &&
271- existingKind == newKind) {
272- // The GSB only dropped the new rule in the case of a conflicting
273- // superclass requirement, so maintain that behavior here.
274- if (existingRule->getRHS ().size () >= newRule->getRHS ().size ())
275- existingRule->markConflicting ();
276- }
277266
278267 // FIXME: Diagnose the conflict later.
279268 }
0 commit comments