Skip to content

Commit 380dba1

Browse files
committed
RequirementMachine: Fold PropertyBag::addProperty() into PropertyMap::addProperty()
1 parent 7386444 commit 380dba1

File tree

3 files changed

+39
-54
lines changed

3 files changed

+39
-54
lines changed

lib/AST/RequirementMachine/PropertyMap.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -307,22 +307,6 @@ void PropertyMap::clear() {
307307
ConcreteTypeInDomainMap.clear();
308308
}
309309

310-
/// Record a protocol conformance, layout or superclass constraint on the given
311-
/// key. Must be called in monotonically non-decreasing key order.
312-
///
313-
/// If there was a conflict, returns the conflicting rule ID; otherwise
314-
/// returns None.
315-
Optional<unsigned> PropertyMap::addProperty(
316-
Term key, Symbol property, unsigned ruleID,
317-
SmallVectorImpl<InducedRule> &inducedRules) {
318-
assert(property.isProperty());
319-
assert(*System.getRule(ruleID).isPropertyRule() == property);
320-
auto *props = getOrCreateProperties(key);
321-
bool debug = Debug.contains(DebugFlags::ConcreteUnification);
322-
return props->addProperty(property, ruleID, System,
323-
inducedRules, debug);
324-
}
325-
326310
/// Build the property map from all rules of the form T.[p] => T, where
327311
/// [p] is a property symbol.
328312
///

lib/AST/RequirementMachine/PropertyMap.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,6 @@ class PropertyBag {
101101

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

104-
Optional<unsigned> addProperty(Symbol property,
105-
unsigned ruleID,
106-
RewriteSystem &system,
107-
SmallVectorImpl<InducedRule> &inducedRules,
108-
bool debug);
109104
void copyPropertiesFrom(const PropertyBag *next,
110105
RewriteContext &ctx);
111106

lib/AST/RequirementMachine/PropertyUnification.cpp

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -383,45 +383,51 @@ static std::pair<Symbol, bool> unifySuperclasses(
383383
return std::make_pair(rhs, false);
384384
}
385385

386-
/// Returns the old conflicting rule ID if there was a conflict,
387-
/// otherwise returns None.
388-
Optional<unsigned> PropertyBag::addProperty(
389-
Symbol property, unsigned ruleID, RewriteSystem &system,
390-
SmallVectorImpl<InducedRule> &inducedRules,
391-
bool debug) {
386+
/// Record a protocol conformance, layout or superclass constraint on the given
387+
/// key. Must be called in monotonically non-decreasing key order.
388+
///
389+
/// If there was a conflict, returns the conflicting rule ID; otherwise
390+
/// returns None.
391+
Optional<unsigned> PropertyMap::addProperty(
392+
Term key, Symbol property, unsigned ruleID,
393+
SmallVectorImpl<InducedRule> &inducedRules) {
394+
assert(property.isProperty());
395+
assert(*System.getRule(ruleID).isPropertyRule() == property);
396+
auto *props = getOrCreateProperties(key);
397+
bool debug = Debug.contains(DebugFlags::ConcreteUnification);
392398

393399
switch (property.getKind()) {
394400
case Symbol::Kind::Protocol:
395-
ConformsTo.push_back(property.getProtocol());
396-
ConformsToRules.push_back(ruleID);
401+
props->ConformsTo.push_back(property.getProtocol());
402+
props->ConformsToRules.push_back(ruleID);
397403
return None;
398404

399405
case Symbol::Kind::Layout: {
400406
auto newLayout = property.getLayoutConstraint();
401407

402-
if (!Layout) {
408+
if (!props->Layout) {
403409
// If we haven't seen a layout requirement before, just record it.
404-
Layout = newLayout;
405-
LayoutRule = ruleID;
410+
props->Layout = newLayout;
411+
props->LayoutRule = ruleID;
406412
} else {
407413
// Otherwise, compute the intersection.
408-
assert(LayoutRule.hasValue());
409-
auto mergedLayout = Layout.merge(property.getLayoutConstraint());
414+
assert(props->LayoutRule.hasValue());
415+
auto mergedLayout = props->Layout.merge(property.getLayoutConstraint());
410416

411417
// If the intersection is invalid, we have a conflict.
412418
if (!mergedLayout->isKnownLayout())
413-
return LayoutRule;
419+
return props->LayoutRule;
414420

415421
// If the intersection is equal to the existing layout requirement,
416422
// the new layout requirement is redundant.
417-
if (mergedLayout == Layout) {
418-
recordRelation(*LayoutRule, ruleID, system, inducedRules, debug);
423+
if (mergedLayout == props->Layout) {
424+
recordRelation(*props->LayoutRule, ruleID, System, inducedRules, debug);
419425

420426
// If the intersection is equal to the new layout requirement, the
421427
// existing layout requirement is redundant.
422428
} else if (mergedLayout == newLayout) {
423-
recordRelation(ruleID, *LayoutRule, system, inducedRules, debug);
424-
LayoutRule = ruleID;
429+
recordRelation(ruleID, *props->LayoutRule, System, inducedRules, debug);
430+
props->LayoutRule = ruleID;
425431
} else {
426432
llvm::errs() << "Arbitrary intersection of layout requirements is "
427433
<< "supported yet\n";
@@ -435,34 +441,34 @@ Optional<unsigned> PropertyBag::addProperty(
435441
case Symbol::Kind::Superclass: {
436442
// FIXME: Also handle superclass vs concrete
437443

438-
if (!Superclass) {
439-
Superclass = property;
440-
SuperclassRule = ruleID;
444+
if (!props->Superclass) {
445+
props->Superclass = property;
446+
props->SuperclassRule = ruleID;
441447
} else {
442-
assert(SuperclassRule.hasValue());
443-
auto pair = unifySuperclasses(*Superclass, property,
444-
system.getRewriteContext(),
448+
assert(props->SuperclassRule.hasValue());
449+
auto pair = unifySuperclasses(*props->Superclass, property,
450+
System.getRewriteContext(),
445451
inducedRules, debug);
446-
Superclass = pair.first;
452+
props->Superclass = pair.first;
447453
bool conflict = pair.second;
448454
if (conflict)
449-
return SuperclassRule;
455+
return props->SuperclassRule;
450456
}
451457

452458
return None;
453459
}
454460

455461
case Symbol::Kind::ConcreteType: {
456-
if (!ConcreteType) {
457-
ConcreteType = property;
458-
ConcreteTypeRule = ruleID;
462+
if (!props->ConcreteType) {
463+
props->ConcreteType = property;
464+
props->ConcreteTypeRule = ruleID;
459465
} else {
460-
assert(ConcreteTypeRule.hasValue());
461-
bool conflict = unifyConcreteTypes(*ConcreteType, property,
462-
system.getRewriteContext(),
466+
assert(props->ConcreteTypeRule.hasValue());
467+
bool conflict = unifyConcreteTypes(*props->ConcreteType, property,
468+
System.getRewriteContext(),
463469
inducedRules, debug);
464470
if (conflict)
465-
return ConcreteTypeRule;
471+
return props->ConcreteTypeRule;
466472
}
467473

468474
return None;

0 commit comments

Comments
 (0)