Skip to content

Commit ae44028

Browse files
committed
RequirementMachine: Allow the property map to record induced rules directly
It doesn't actually do this yet, but the idea is to look at the total rule count before and after, instead of just looking at the induced rules array (which I will delete in the next commit).
1 parent 10e4ffd commit ae44028

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

lib/AST/RequirementMachine/PropertyMap.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ PropertyMap::buildPropertyMap(unsigned maxIterations,
371371

372372
// Merging multiple superclass or concrete type rules can induce new rules
373373
// to unify concrete type constructor arguments.
374+
unsigned ruleCount = System.getRules().size();
374375
SmallVector<InducedRule, 3> inducedRules;
375376

376377
for (const auto &bucket : properties) {
@@ -390,17 +391,17 @@ PropertyMap::buildPropertyMap(unsigned maxIterations,
390391

391392
// Some of the induced rules might be trivial; only count the induced rules
392393
// where the left hand side is not already equivalent to the right hand side.
393-
unsigned addedNewRules = 0;
394394
for (auto pair : inducedRules) {
395395
// FIXME: Eventually, all induced rules will have a rewrite path.
396-
if (System.addRule(pair.LHS, pair.RHS,
397-
pair.Path.empty() ? nullptr : &pair.Path)) {
398-
++addedNewRules;
396+
(void) System.addRule(pair.LHS, pair.RHS,
397+
pair.Path.empty() ? nullptr : &pair.Path);
398+
}
399399

400-
const auto &newRule = System.getRules().back();
401-
if (newRule.getDepth() > maxDepth)
402-
return std::make_pair(CompletionResult::MaxDepth, addedNewRules);
403-
}
400+
unsigned addedNewRules = System.getRules().size() - ruleCount;
401+
for (unsigned i = ruleCount, e = System.getRules().size(); i < e; ++i) {
402+
const auto &newRule = System.getRule(i);
403+
if (newRule.getDepth() > maxDepth)
404+
return std::make_pair(CompletionResult::MaxDepth, addedNewRules);
404405
}
405406

406407
// Check invariants of the constructed property map.

test/Generics/non_confluent.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,15 @@ func foo<T : P1 & P2>(_: T) {}
3333
// expected-error@-1 {{cannot build rewrite system for generic signature; depth limit exceeded}}
3434

3535
extension P1 where Self : P2 {}
36-
// expected-error@-1 {{cannot build rewrite system for generic signature; depth limit exceeded}}
36+
// expected-error@-1 {{cannot build rewrite system for generic signature; depth limit exceeded}}
37+
38+
struct S<U : P1> : P1 {
39+
typealias T = S<S<U>>
40+
}
41+
42+
protocol P3 {
43+
// expected-error@-1 {{cannot build rewrite system for protocol; depth limit exceeded}}
44+
associatedtype T : P1 where T == S<U>
45+
// expected-error@-1 {{type 'Self.U' does not conform to protocol 'P1'}}
46+
associatedtype U : P1
47+
}

0 commit comments

Comments
 (0)