Skip to content

Commit 7b01ff6

Browse files
committed
RequirementMachine: Simplify RewriteSystem::processConflicts()
Remove the logic which incorrectly attempted to simulate the GenericSignatureBuilder's minimization behavior in the presence of conflicts, since it doesn't matter anymore.
1 parent 13c6611 commit 7b01ff6

File tree

4 files changed

+21
-30
lines changed

4 files changed

+21
-30
lines changed

lib/AST/RequirementMachine/HomotopyReduction.cpp

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
250249
void 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
}

test/Generics/concrete_conflict.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class Class<T> {}
3636

3737
extension Class where T == Bool {
3838
// CHECK-LABEL: .badRequirement()@
39-
// CHECK-NEXT: <T where T == Bool>
39+
// CHECK-NEXT: <T>
4040
func badRequirement() where T == Int { }
4141
// expected-error@-1 {{generic parameter 'T' cannot be equal to both 'Int' and 'Bool'}}
4242
}

test/Generics/superclass_and_concrete_requirement.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ protocol P1 {
1414
}
1515

1616
// CHECK-LABEL: .P2@
17-
// CHECK-NEXT: Requirement signature: <Self where Self.[P2]T == S>
17+
// CHECK-NEXT: Requirement signature: <Self>
1818
protocol P2 {
1919
associatedtype T where T : C, T == S
2020
// expected-error@-1 {{'Self.T' requires that 'S' inherit from 'C'}}
@@ -23,7 +23,7 @@ protocol P2 {
2323
}
2424

2525
// CHECK-LABEL: .P3@
26-
// CHECK-NEXT: Requirement signature: <Self where Self.[P3]T == S>
26+
// CHECK-NEXT: Requirement signature: <Self>
2727
protocol P3 {
2828
associatedtype T where T == S, T : C
2929
// expected-error@-1 {{'Self.T' requires that 'S' inherit from 'C'}}

test/attr/attr_specialize.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ func funcWithForbiddenSpecializeRequirement<T>(_ t: T) {
177177
// expected-warning@-3{{redundant constraint 'T' : '_Trivial'}}
178178
// expected-note@-4 {{constraint 'T' : '_Trivial' implied here}}
179179
// expected-note@-5 2{{constraint conflicts with 'T' : '_Trivial(32)'}}
180+
// expected-error@-6 {{too few generic parameters are specified in '_specialize' attribute (got 0, but expected 1)}}
181+
// expected-note@-7 {{missing constraint for 'T' in '_specialize' attribute}}
180182
@_specialize(where T: _Trivial, T: _Trivial(64))
181183
// expected-warning@-1{{redundant constraint 'T' : '_Trivial'}}
182184
// expected-note@-2 1{{constraint 'T' : '_Trivial' implied here}}

0 commit comments

Comments
 (0)