Skip to content

Commit 2aab4bb

Browse files
committed
RequirementMachine: Stub out logic for property map to record rewrite loops
For homotopy reduction to properly deal with new rules introduced while bulding the property map, rewrite loops must be recorded relating these to existing rules.
1 parent e9b50f0 commit 2aab4bb

File tree

3 files changed

+31
-15
lines changed

3 files changed

+31
-15
lines changed

lib/AST/RequirementMachine/PropertyMap.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ void PropertyMap::clear() {
311311
/// key. Must be called in monotonically non-decreasing key order.
312312
void PropertyMap::addProperty(
313313
Term key, Symbol property, unsigned ruleID,
314-
SmallVectorImpl<std::pair<MutableTerm, MutableTerm>> &inducedRules) {
314+
SmallVectorImpl<InducedRule> &inducedRules) {
315315
assert(property.isProperty());
316316
assert(*System.getRule(ruleID).isPropertyRule() == property);
317317
auto *props = getOrCreateProperties(key);
@@ -371,7 +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-
SmallVector<std::pair<MutableTerm, MutableTerm>, 3> inducedRules;
374+
SmallVector<InducedRule, 3> inducedRules;
375375

376376
for (const auto &bucket : properties) {
377377
for (auto property : bucket) {
@@ -392,7 +392,9 @@ PropertyMap::buildPropertyMap(unsigned maxIterations,
392392
// where the left hand side is not already equivalent to the right hand side.
393393
unsigned addedNewRules = 0;
394394
for (auto pair : inducedRules) {
395-
if (System.addRule(pair.first, pair.second)) {
395+
// 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)) {
396398
++addedNewRules;
397399

398400
const auto &newRule = System.getRules().back();

lib/AST/RequirementMachine/PropertyMap.h

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,21 @@ namespace rewriting {
4343
class MutableTerm;
4444
class Term;
4545

46+
/// A new rule introduced during property map construction, as a result of
47+
/// unifying two property symbols that apply to the same common suffix term.
48+
struct InducedRule {
49+
MutableTerm LHS;
50+
MutableTerm RHS;
51+
RewritePath Path;
52+
53+
InducedRule(MutableTerm LHS, MutableTerm RHS, RewritePath Path)
54+
: LHS(LHS), RHS(RHS), Path(Path) {}
55+
56+
// FIXME: Eventually all induced rules will have a rewrite path.
57+
InducedRule(MutableTerm LHS, MutableTerm RHS)
58+
: LHS(LHS), RHS(RHS) {}
59+
};
60+
4661
/// Stores a convenient representation of all "property-like" rewrite rules of
4762
/// the form T.[p] => T, where [p] is a property symbol, for some term 'T'.
4863
class PropertyBag {
@@ -88,7 +103,7 @@ class PropertyBag {
88103
void addProperty(Symbol property,
89104
unsigned ruleID,
90105
RewriteContext &ctx,
91-
SmallVectorImpl<std::pair<MutableTerm, MutableTerm>> &inducedRules,
106+
SmallVectorImpl<InducedRule> &inducedRules,
92107
bool debug);
93108
void copyPropertiesFrom(const PropertyBag *next,
94109
RewriteContext &ctx);
@@ -186,18 +201,18 @@ class PropertyMap {
186201
private:
187202
void clear();
188203
void addProperty(Term key, Symbol property, unsigned ruleID,
189-
SmallVectorImpl<std::pair<MutableTerm, MutableTerm>> &inducedRules);
204+
SmallVectorImpl<InducedRule> &inducedRules);
190205

191206
void computeConcreteTypeInDomainMap();
192207
void concretizeNestedTypesFromConcreteParents(
193-
SmallVectorImpl<std::pair<MutableTerm, MutableTerm>> &inducedRules) const;
208+
SmallVectorImpl<InducedRule> &inducedRules) const;
194209

195210
void concretizeNestedTypesFromConcreteParent(
196211
Term key, RequirementKind requirementKind,
197212
CanType concreteType, ArrayRef<Term> substitutions,
198213
ArrayRef<const ProtocolDecl *> conformsTo,
199214
llvm::TinyPtrVector<ProtocolConformance *> &conformances,
200-
SmallVectorImpl<std::pair<MutableTerm, MutableTerm>> &inducedRules) const;
215+
SmallVectorImpl<InducedRule> &inducedRules) const;
201216

202217
MutableTerm computeConstraintTermForTypeWitness(
203218
Term key, CanType concreteType, CanType typeWitness,

lib/AST/RequirementMachine/PropertyUnification.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,14 @@ namespace {
9090
ArrayRef<Term> lhsSubstitutions;
9191
ArrayRef<Term> rhsSubstitutions;
9292
RewriteContext &ctx;
93-
SmallVectorImpl<std::pair<MutableTerm, MutableTerm>> &inducedRules;
93+
SmallVectorImpl<InducedRule> &inducedRules;
9494
bool debug;
9595

9696
public:
9797
ConcreteTypeMatcher(ArrayRef<Term> lhsSubstitutions,
9898
ArrayRef<Term> rhsSubstitutions,
9999
RewriteContext &ctx,
100-
SmallVectorImpl<std::pair<MutableTerm,
101-
MutableTerm>> &inducedRules,
100+
SmallVectorImpl<InducedRule> &inducedRules,
102101
bool debug)
103102
: lhsSubstitutions(lhsSubstitutions),
104103
rhsSubstitutions(rhsSubstitutions),
@@ -205,7 +204,7 @@ namespace {
205204
/// Returns true if a conflict was detected.
206205
static bool unifyConcreteTypes(
207206
Symbol lhs, Symbol rhs, RewriteContext &ctx,
208-
SmallVectorImpl<std::pair<MutableTerm, MutableTerm>> &inducedRules,
207+
SmallVectorImpl<InducedRule> &inducedRules,
209208
bool debug) {
210209
auto lhsType = lhs.getConcreteType();
211210
auto rhsType = rhs.getConcreteType();
@@ -253,7 +252,7 @@ static bool unifyConcreteTypes(
253252
/// that gets recorded in the property map.
254253
static Symbol unifySuperclasses(
255254
Symbol lhs, Symbol rhs, RewriteContext &ctx,
256-
SmallVectorImpl<std::pair<MutableTerm, MutableTerm>> &inducedRules,
255+
SmallVectorImpl<InducedRule> &inducedRules,
257256
bool debug) {
258257
if (debug) {
259258
llvm::dbgs() << "% Unifying " << lhs << " with " << rhs << "\n";
@@ -310,7 +309,7 @@ static Symbol unifySuperclasses(
310309

311310
void PropertyBag::addProperty(
312311
Symbol property, unsigned ruleID, RewriteContext &ctx,
313-
SmallVectorImpl<std::pair<MutableTerm, MutableTerm>> &inducedRules,
312+
SmallVectorImpl<InducedRule> &inducedRules,
314313
bool debug) {
315314

316315
switch (property.getKind()) {
@@ -395,7 +394,7 @@ void PropertyMap::computeConcreteTypeInDomainMap() {
395394
}
396395

397396
void PropertyMap::concretizeNestedTypesFromConcreteParents(
398-
SmallVectorImpl<std::pair<MutableTerm, MutableTerm>> &inducedRules) const {
397+
SmallVectorImpl<InducedRule> &inducedRules) const {
399398
for (const auto &props : Entries) {
400399
if (props->getConformsTo().empty())
401400
continue;
@@ -478,7 +477,7 @@ void PropertyMap::concretizeNestedTypesFromConcreteParent(
478477
CanType concreteType, ArrayRef<Term> substitutions,
479478
ArrayRef<const ProtocolDecl *> conformsTo,
480479
llvm::TinyPtrVector<ProtocolConformance *> &conformances,
481-
SmallVectorImpl<std::pair<MutableTerm, MutableTerm>> &inducedRules) const {
480+
SmallVectorImpl<InducedRule> &inducedRules) const {
482481
assert(requirementKind == RequirementKind::SameType ||
483482
requirementKind == RequirementKind::Superclass);
484483

0 commit comments

Comments
 (0)