Skip to content

Commit 41e3292

Browse files
committed
RequirementMachine: Remove 'induced rules' mechanism from the property map
1 parent 0b3d6ea commit 41e3292

File tree

3 files changed

+28
-77
lines changed

3 files changed

+28
-77
lines changed

lib/AST/RequirementMachine/PropertyMap.cpp

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -372,30 +372,21 @@ PropertyMap::buildPropertyMap(unsigned maxIterations,
372372
// Merging multiple superclass or concrete type rules can induce new rules
373373
// to unify concrete type constructor arguments.
374374
unsigned ruleCount = System.getRules().size();
375-
SmallVector<InducedRule, 3> inducedRules;
376375

377376
for (const auto &bucket : properties) {
378377
for (auto property : bucket) {
379378
addProperty(property.key, property.symbol,
380-
property.ruleID, inducedRules);
379+
property.ruleID);
381380
}
382381
}
383382

384383
// Now, check for conflicts between superclass and concrete type rules.
385-
checkConcreteTypeRequirements(inducedRules);
384+
checkConcreteTypeRequirements();
386385

387386
// Now, we merge concrete type rules with conformance rules, by adding
388387
// relations between associated type members of type parameters with
389388
// the concrete type witnesses in the concrete type's conformance.
390-
concretizeNestedTypesFromConcreteParents(inducedRules);
391-
392-
// Some of the induced rules might be trivial; only count the induced rules
393-
// where the left hand side is not already equivalent to the right hand side.
394-
for (auto pair : inducedRules) {
395-
// FIXME: Eventually, all induced rules will have a rewrite path.
396-
(void) System.addRule(pair.LHS, pair.RHS,
397-
pair.Path.empty() ? nullptr : &pair.Path);
398-
}
389+
concretizeNestedTypesFromConcreteParents();
399390

400391
unsigned addedNewRules = System.getRules().size() - ruleCount;
401392
for (unsigned i = ruleCount, e = System.getRules().size(); i < e; ++i) {

lib/AST/RequirementMachine/PropertyMap.h

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,6 @@ namespace rewriting {
4444
class MutableTerm;
4545
class Term;
4646

47-
/// A new rule introduced during property map construction, as a result of
48-
/// unifying two property symbols that apply to the same common suffix term.
49-
struct InducedRule {
50-
MutableTerm LHS;
51-
MutableTerm RHS;
52-
RewritePath Path;
53-
54-
InducedRule(MutableTerm LHS, MutableTerm RHS, RewritePath Path)
55-
: LHS(LHS), RHS(RHS), Path(Path) {}
56-
57-
// FIXME: Eventually all induced rules will have a rewrite path.
58-
InducedRule(MutableTerm LHS, MutableTerm RHS)
59-
: LHS(LHS), RHS(RHS) {}
60-
};
61-
6247
/// Stores a convenient representation of all "property-like" rewrite rules of
6348
/// the form T.[p] => T, where [p] is a property symbol, for some term 'T'.
6449
class PropertyBag {
@@ -258,14 +243,11 @@ class PropertyMap {
258243
bool checkRuleOnce(unsigned ruleID);
259244
bool checkRulePairOnce(unsigned firstRuleID, unsigned secondRuleID);
260245

261-
void addProperty(Term key, Symbol property, unsigned ruleID,
262-
SmallVectorImpl<InducedRule> &inducedRules);
246+
void addProperty(Term key, Symbol property, unsigned ruleID);
263247

264-
void checkConcreteTypeRequirements(
265-
SmallVectorImpl<InducedRule> &inducedRules);
248+
void checkConcreteTypeRequirements();
266249

267-
void concretizeNestedTypesFromConcreteParents(
268-
SmallVectorImpl<InducedRule> &inducedRules);
250+
void concretizeNestedTypesFromConcreteParents();
269251

270252
void concretizeNestedTypesFromConcreteParent(
271253
Term key, RequirementKind requirementKind,
@@ -274,15 +256,13 @@ class PropertyMap {
274256
ArrayRef<Term> substitutions,
275257
ArrayRef<unsigned> conformsToRules,
276258
ArrayRef<const ProtocolDecl *> conformsTo,
277-
llvm::TinyPtrVector<ProtocolConformance *> &conformances,
278-
SmallVectorImpl<InducedRule> &inducedRules);
259+
llvm::TinyPtrVector<ProtocolConformance *> &conformances);
279260

280261
void concretizeTypeWitnessInConformance(
281262
Term key, RequirementKind requirementKind,
282263
Symbol concreteConformanceSymbol,
283264
ProtocolConformance *concrete,
284-
AssociatedTypeDecl *assocType,
285-
SmallVectorImpl<InducedRule> &inducedRules) const;
265+
AssociatedTypeDecl *assocType) const;
286266

287267
MutableTerm computeConstraintTermForTypeWitness(
288268
Term key, RequirementKind requirementKind,
@@ -295,8 +275,7 @@ class PropertyMap {
295275
unsigned concreteRuleID,
296276
unsigned conformanceRuleID,
297277
RequirementKind requirementKind,
298-
Symbol concreteConformanceSymbol,
299-
SmallVectorImpl<InducedRule> &inducedRules) const;
278+
Symbol concreteConformanceSymbol) const;
300279

301280
void verify() const;
302281
};

lib/AST/RequirementMachine/PropertyUnification.cpp

Lines changed: 19 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ static void recordRelation(Term key,
5656
unsigned lhsRuleID,
5757
Symbol rhsProperty,
5858
RewriteSystem &system,
59-
SmallVectorImpl<InducedRule> &inducedRules,
6059
bool debug) {
6160
const auto &lhsRule = system.getRule(lhsRuleID);
6261
auto lhsProperty = lhsRule.getLHS().back();
@@ -141,19 +140,17 @@ namespace {
141140
ArrayRef<Term> rhsSubstitutions;
142141
RewriteContext &ctx;
143142
RewriteSystem &system;
144-
SmallVectorImpl<InducedRule> &inducedRules;
145143
bool debug;
146144

147145
public:
148146
ConcreteTypeMatcher(ArrayRef<Term> lhsSubstitutions,
149147
ArrayRef<Term> rhsSubstitutions,
150148
RewriteSystem &system,
151-
SmallVectorImpl<InducedRule> &inducedRules,
152149
bool debug)
153150
: lhsSubstitutions(lhsSubstitutions),
154151
rhsSubstitutions(rhsSubstitutions),
155152
ctx(system.getRewriteContext()), system(system),
156-
inducedRules(inducedRules), debug(debug) {}
153+
debug(debug) {}
157154

158155
bool alwaysMismatchTypeParameters() const { return true; }
159156

@@ -260,7 +257,6 @@ namespace {
260257
/// Returns true if a conflict was detected.
261258
static bool unifyConcreteTypes(
262259
Symbol lhs, Symbol rhs, RewriteSystem &system,
263-
SmallVectorImpl<InducedRule> &inducedRules,
264260
bool debug) {
265261
auto lhsType = lhs.getConcreteType();
266262
auto rhsType = rhs.getConcreteType();
@@ -271,7 +267,7 @@ static bool unifyConcreteTypes(
271267

272268
ConcreteTypeMatcher matcher(lhs.getSubstitutions(),
273269
rhs.getSubstitutions(),
274-
system, inducedRules, debug);
270+
system, debug);
275271
if (!matcher.match(lhsType, rhsType)) {
276272
// FIXME: Diagnose the conflict
277273
if (debug) {
@@ -308,7 +304,6 @@ static bool unifyConcreteTypes(
308304
/// that gets recorded in the property map.
309305
static std::pair<Symbol, bool> unifySuperclasses(
310306
Symbol lhs, Symbol rhs, RewriteSystem &system,
311-
SmallVectorImpl<InducedRule> &inducedRules,
312307
bool debug) {
313308
if (debug) {
314309
llvm::dbgs() << "% Unifying " << lhs << " with " << rhs << "\n";
@@ -351,7 +346,7 @@ static std::pair<Symbol, bool> unifySuperclasses(
351346
// Unify type contructor arguments.
352347
ConcreteTypeMatcher matcher(lhs.getSubstitutions(),
353348
rhs.getSubstitutions(),
354-
system, inducedRules, debug);
349+
system, debug);
355350
if (!matcher.match(lhsType, rhsType)) {
356351
if (debug) {
357352
llvm::dbgs() << "%% Superclass conflict\n";
@@ -366,8 +361,7 @@ static std::pair<Symbol, bool> unifySuperclasses(
366361
/// Record a protocol conformance, layout or superclass constraint on the given
367362
/// key. Must be called in monotonically non-decreasing key order.
368363
void PropertyMap::addProperty(
369-
Term key, Symbol property, unsigned ruleID,
370-
SmallVectorImpl<InducedRule> &inducedRules) {
364+
Term key, Symbol property, unsigned ruleID) {
371365
assert(property.isProperty());
372366
assert(*System.getRule(ruleID).isPropertyRule() == property);
373367
auto *props = getOrCreateProperties(key);
@@ -401,17 +395,15 @@ void PropertyMap::addProperty(
401395
// the new layout requirement is redundant.
402396
if (mergedLayout == props->Layout) {
403397
if (checkRulePairOnce(*props->LayoutRule, ruleID)) {
404-
recordRelation(key, *props->LayoutRule, property, System,
405-
inducedRules, debug);
398+
recordRelation(key, *props->LayoutRule, property, System, debug);
406399
}
407400

408401
// If the intersection is equal to the new layout requirement, the
409402
// existing layout requirement is redundant.
410403
} else if (mergedLayout == newLayout) {
411404
if (checkRulePairOnce(ruleID, *props->LayoutRule)) {
412405
auto oldProperty = System.getRule(*props->LayoutRule).getLHS().back();
413-
recordRelation(key, ruleID, oldProperty, System,
414-
inducedRules, debug);
406+
recordRelation(key, ruleID, oldProperty, System, debug);
415407
}
416408

417409
props->LayoutRule = ruleID;
@@ -437,8 +429,7 @@ void PropertyMap::addProperty(
437429
Context.getASTContext());
438430
auto layoutSymbol = Symbol::forLayout(layout, Context);
439431

440-
recordRelation(key, ruleID, layoutSymbol, System,
441-
inducedRules, debug);
432+
recordRelation(key, ruleID, layoutSymbol, System, debug);
442433
}
443434

444435
if (!props->Superclass) {
@@ -447,7 +438,7 @@ void PropertyMap::addProperty(
447438
} else {
448439
assert(props->SuperclassRule.hasValue());
449440
auto pair = unifySuperclasses(*props->Superclass, property,
450-
System, inducedRules, debug);
441+
System, debug);
451442
props->Superclass = pair.first;
452443
bool conflict = pair.second;
453444
if (conflict) {
@@ -466,7 +457,7 @@ void PropertyMap::addProperty(
466457
} else {
467458
assert(props->ConcreteTypeRule.hasValue());
468459
bool conflict = unifyConcreteTypes(*props->ConcreteType, property,
469-
System, inducedRules, debug);
460+
System, debug);
470461
if (conflict) {
471462
recordConflict(key, *props->ConcreteTypeRule, ruleID, System);
472463
return;
@@ -489,8 +480,7 @@ void PropertyMap::addProperty(
489480
llvm_unreachable("Bad symbol kind");
490481
}
491482

492-
void PropertyMap::checkConcreteTypeRequirements(
493-
SmallVectorImpl<InducedRule> &inducedRules) {
483+
void PropertyMap::checkConcreteTypeRequirements() {
494484
bool debug = Debug.contains(DebugFlags::ConcreteUnification);
495485

496486
for (auto *props : Entries) {
@@ -505,8 +495,7 @@ void PropertyMap::checkConcreteTypeRequirements(
505495
Context);
506496

507497
recordRelation(props->getKey(), *props->ConcreteTypeRule,
508-
superclassSymbol, System,
509-
inducedRules, debug);
498+
superclassSymbol, System, debug);
510499

511500
// Otherwise, we have a concrete vs superclass conflict.
512501
} else {
@@ -518,8 +507,7 @@ void PropertyMap::checkConcreteTypeRequirements(
518507
}
519508
}
520509

521-
void PropertyMap::concretizeNestedTypesFromConcreteParents(
522-
SmallVectorImpl<InducedRule> &inducedRules) {
510+
void PropertyMap::concretizeNestedTypesFromConcreteParents() {
523511
for (auto *props : Entries) {
524512
if (props->getConformsTo().empty())
525513
continue;
@@ -546,8 +534,7 @@ void PropertyMap::concretizeNestedTypesFromConcreteParents(
546534
props->ConcreteType->getSubstitutions(),
547535
props->ConformsToRules,
548536
props->ConformsTo,
549-
props->ConcreteConformances,
550-
inducedRules);
537+
props->ConcreteConformances);
551538
}
552539

553540
if (props->hasSuperclassBound()) {
@@ -563,8 +550,7 @@ void PropertyMap::concretizeNestedTypesFromConcreteParents(
563550
props->Superclass->getSubstitutions(),
564551
props->ConformsToRules,
565552
props->ConformsTo,
566-
props->SuperclassConformances,
567-
inducedRules);
553+
props->SuperclassConformances);
568554
}
569555
}
570556
}
@@ -608,8 +594,7 @@ void PropertyMap::concretizeNestedTypesFromConcreteParent(
608594
ArrayRef<Term> substitutions,
609595
ArrayRef<unsigned> conformsToRules,
610596
ArrayRef<const ProtocolDecl *> conformsTo,
611-
llvm::TinyPtrVector<ProtocolConformance *> &conformances,
612-
SmallVectorImpl<InducedRule> &inducedRules) {
597+
llvm::TinyPtrVector<ProtocolConformance *> &conformances) {
613598
assert(requirementKind == RequirementKind::SameType ||
614599
requirementKind == RequirementKind::Superclass);
615600
assert(conformsTo.size() == conformsToRules.size());
@@ -684,8 +669,7 @@ void PropertyMap::concretizeNestedTypesFromConcreteParent(
684669
concreteType, substitutions, proto, Context);
685670

686671
recordConcreteConformanceRule(concreteRuleID, conformanceRuleID,
687-
requirementKind, concreteConformanceSymbol,
688-
inducedRules);
672+
requirementKind, concreteConformanceSymbol);
689673

690674
auto assocTypes = proto->getAssociatedTypeMembers();
691675
if (assocTypes.empty())
@@ -694,8 +678,7 @@ void PropertyMap::concretizeNestedTypesFromConcreteParent(
694678
for (auto *assocType : assocTypes) {
695679
concretizeTypeWitnessInConformance(key, requirementKind,
696680
concreteConformanceSymbol,
697-
concrete, assocType,
698-
inducedRules);
681+
concrete, assocType);
699682
}
700683
}
701684
}
@@ -704,8 +687,7 @@ void PropertyMap::concretizeTypeWitnessInConformance(
704687
Term key, RequirementKind requirementKind,
705688
Symbol concreteConformanceSymbol,
706689
ProtocolConformance *concrete,
707-
AssociatedTypeDecl *assocType,
708-
SmallVectorImpl<InducedRule> &inducedRules) const {
690+
AssociatedTypeDecl *assocType) const {
709691
auto concreteType = concreteConformanceSymbol.getConcreteType();
710692
auto substitutions = concreteConformanceSymbol.getSubstitutions();
711693
auto *proto = concreteConformanceSymbol.getProtocol();
@@ -926,8 +908,7 @@ void PropertyMap::recordConcreteConformanceRule(
926908
unsigned concreteRuleID,
927909
unsigned conformanceRuleID,
928910
RequirementKind requirementKind,
929-
Symbol concreteConformanceSymbol,
930-
SmallVectorImpl<InducedRule> &inducedRules) const {
911+
Symbol concreteConformanceSymbol) const {
931912
const auto &concreteRule = System.getRule(concreteRuleID);
932913
const auto &conformanceRule = System.getRule(conformanceRuleID);
933914

0 commit comments

Comments
 (0)