Skip to content

Commit 088c540

Browse files
authored
Merge pull request #40536 from slavapestov/rqm-refactor-nested-type-concretization
RequirementMachine: Refactor nested type concretization
2 parents f09a7e7 + 56fb3cc commit 088c540

14 files changed

+381
-239
lines changed

lib/AST/RequirementMachine/HomotopyReduction.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -523,16 +523,19 @@ void RewriteSystem::minimizeRewriteSystem() {
523523

524524
/// In a conformance-valid rewrite system, any rule with unresolved symbols on
525525
/// the left or right hand side should have been simplified by another rule.
526-
bool RewriteSystem::hasNonRedundantUnresolvedRules() const {
526+
bool RewriteSystem::hadError() const {
527527
assert(Complete);
528528
assert(Minimized);
529529

530530
for (const auto &rule : Rules) {
531-
if (!rule.isRedundant() &&
532-
!rule.isPermanent() &&
533-
rule.containsUnresolvedSymbols()) {
531+
if (rule.isPermanent())
532+
continue;
533+
534+
if (rule.isConflicting())
535+
return true;
536+
537+
if (!rule.isRedundant() && rule.containsUnresolvedSymbols())
534538
return true;
535-
}
536539
}
537540

538541
return false;
@@ -555,6 +558,7 @@ RewriteSystem::getMinimizedProtocolRules(
555558

556559
if (rule.isPermanent() ||
557560
rule.isRedundant() ||
561+
rule.isConflicting() ||
558562
rule.containsUnresolvedSymbols()) {
559563
continue;
560564
}
@@ -584,6 +588,7 @@ RewriteSystem::getMinimizedGenericSignatureRules() const {
584588

585589
if (rule.isPermanent() ||
586590
rule.isRedundant() ||
591+
rule.isConflicting() ||
587592
rule.containsUnresolvedSymbols()) {
588593
continue;
589594
}

lib/AST/RequirementMachine/KnuthBendix.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ RewriteSystem::computeConfluentCompletion(unsigned maxIterations,
596596
}
597597
}
598598

599-
simplifyRewriteSystem();
599+
simplifyLeftHandSides();
600600

601601
assert(resolvedCriticalPairs.size() == resolvedPaths.size());
602602

@@ -629,6 +629,8 @@ RewriteSystem::computeConfluentCompletion(unsigned maxIterations,
629629
resolvedPaths.clear();
630630
resolvedLoops.clear();
631631

632+
simplifyRightHandSidesAndSubstitutions();
633+
632634
// If the added rules merged any associated types, process the merges now
633635
// before we continue with the completion procedure. This is important
634636
// to perform incrementally since merging is required to repair confluence

lib/AST/RequirementMachine/PropertyMap.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -309,14 +309,15 @@ void PropertyMap::clear() {
309309

310310
/// Record a protocol conformance, layout or superclass constraint on the given
311311
/// key. Must be called in monotonically non-decreasing key order.
312-
void PropertyMap::addProperty(
312+
bool PropertyMap::addProperty(
313313
Term key, Symbol property, unsigned ruleID,
314314
SmallVectorImpl<InducedRule> &inducedRules) {
315315
assert(property.isProperty());
316316
assert(*System.getRule(ruleID).isPropertyRule() == property);
317317
auto *props = getOrCreateProperties(key);
318-
props->addProperty(property, ruleID, Context,
319-
inducedRules, Debug.contains(DebugFlags::ConcreteUnification));
318+
bool debug = Debug.contains(DebugFlags::ConcreteUnification);
319+
return props->addProperty(property, ruleID, Context,
320+
inducedRules, debug);
320321
}
321322

322323
/// Build the property map from all rules of the form T.[p] => T, where
@@ -375,7 +376,10 @@ PropertyMap::buildPropertyMap(unsigned maxIterations,
375376

376377
for (const auto &bucket : properties) {
377378
for (auto property : bucket) {
378-
addProperty(property.key, property.symbol, property.ruleID, inducedRules);
379+
bool conflict = addProperty(property.key, property.symbol,
380+
property.ruleID, inducedRules);
381+
if (conflict)
382+
System.getRule(property.ruleID).markConflicting();
379383
}
380384
}
381385

@@ -388,10 +392,6 @@ PropertyMap::buildPropertyMap(unsigned maxIterations,
388392
// the concrete type witnesses in the concrete type's conformance.
389393
concretizeNestedTypesFromConcreteParents(inducedRules);
390394

391-
// Finally, introduce concrete conformance rules, relating conformance rules
392-
// to concrete type and superclass rules.
393-
recordConcreteConformanceRules(inducedRules);
394-
395395
// Some of the induced rules might be trivial; only count the induced rules
396396
// where the left hand side is not already equivalent to the right hand side.
397397
unsigned addedNewRules = 0;

lib/AST/RequirementMachine/PropertyMap.h

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class PropertyBag {
100100

101101
explicit PropertyBag(Term key) : Key(key) {}
102102

103-
void addProperty(Symbol property,
103+
bool addProperty(Symbol property,
104104
unsigned ruleID,
105105
RewriteContext &ctx,
106106
SmallVectorImpl<InducedRule> &inducedRules,
@@ -202,32 +202,40 @@ class PropertyMap {
202202

203203
private:
204204
void clear();
205-
void addProperty(Term key, Symbol property, unsigned ruleID,
205+
bool addProperty(Term key, Symbol property, unsigned ruleID,
206206
SmallVectorImpl<InducedRule> &inducedRules);
207207

208208
void computeConcreteTypeInDomainMap();
209209
void concretizeNestedTypesFromConcreteParents(
210-
SmallVectorImpl<InducedRule> &inducedRules) const;
210+
SmallVectorImpl<InducedRule> &inducedRules);
211211

212212
void concretizeNestedTypesFromConcreteParent(
213213
Term key, RequirementKind requirementKind,
214-
CanType concreteType, ArrayRef<Term> substitutions,
214+
unsigned concreteRuleID,
215+
CanType concreteType,
216+
ArrayRef<Term> substitutions,
217+
ArrayRef<unsigned> conformsToRules,
215218
ArrayRef<const ProtocolDecl *> conformsTo,
216219
llvm::TinyPtrVector<ProtocolConformance *> &conformances,
220+
SmallVectorImpl<InducedRule> &inducedRules);
221+
222+
void concretizeTypeWitnessInConformance(
223+
Term key, RequirementKind requirementKind,
224+
Symbol concreteConformanceSymbol,
225+
ProtocolConformance *concrete,
226+
AssociatedTypeDecl *assocType,
217227
SmallVectorImpl<InducedRule> &inducedRules) const;
218228

219229
MutableTerm computeConstraintTermForTypeWitness(
220230
Term key, CanType concreteType, CanType typeWitness,
221231
const MutableTerm &subjectType, ArrayRef<Term> substitutions) const;
222232

223-
void recordConcreteConformanceRules(
224-
SmallVectorImpl<InducedRule> &inducedRules);
225-
226233
void recordConcreteConformanceRule(
227234
unsigned concreteRuleID,
228235
unsigned conformanceRuleID,
229-
const ProtocolDecl *proto,
230-
SmallVectorImpl<InducedRule> &inducedRules);
236+
RequirementKind requirementKind,
237+
Symbol concreteConformanceSymbol,
238+
SmallVectorImpl<InducedRule> &inducedRules) const;
231239

232240
void verify() const;
233241
};

0 commit comments

Comments
 (0)