Skip to content

Commit d164fb8

Browse files
committed
RequirementMachine: Rename RewriteSystemBuilder to RuleBuilder
1 parent cc87566 commit d164fb8

File tree

1 file changed

+25
-24
lines changed

1 file changed

+25
-24
lines changed

lib/AST/RequirementMachine/RequirementMachine.cpp

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ using namespace rewriting;
2525

2626
namespace {
2727

28-
/// A utility class for bulding a rewrite system from the top-level requirements
29-
/// of a generic signature, and all protocol requirement signatures from all
30-
/// transitively-referenced protocols.
31-
struct RewriteSystemBuilder {
28+
/// A utility class for bulding rewrite rules from the top-level requirements
29+
/// of a generic signature.
30+
///
31+
/// This also collects requirements from the transitive closure of all protocols
32+
/// appearing on the right hand side of conformance requirements.
33+
struct RuleBuilder {
3234
RewriteContext &Context;
3335
bool Dump;
3436

@@ -64,8 +66,7 @@ struct RewriteSystemBuilder {
6466
const ProtocolDecl *proto,
6567
SmallVectorImpl<Term> &result);
6668

67-
RewriteSystemBuilder(RewriteContext &ctx, bool dump)
68-
: Context(ctx), Dump(dump) {}
69+
RuleBuilder(RewriteContext &ctx, bool dump) : Context(ctx), Dump(dump) {}
6970
void addRequirements(ArrayRef<Requirement> requirements);
7071
void addProtocols(ArrayRef<const ProtocolDecl *> proto);
7172
void addProtocol(const ProtocolDecl *proto,
@@ -74,7 +75,7 @@ struct RewriteSystemBuilder {
7475
const ProtocolDecl *proto);
7576
void addRequirement(const Requirement &req,
7677
const ProtocolDecl *proto);
77-
void processProtocolDependencies();
78+
void collectRulesFromReferencedProtocols();
7879
};
7980

8081
} // end namespace
@@ -87,9 +88,9 @@ struct RewriteSystemBuilder {
8788
/// For example, given the concrete type Foo<X.Y, Array<Z>>, this produces the
8889
/// result type Foo<τ_0_0, Array<τ_0_1>>, with result array {X.Y, Z}.
8990
CanType
90-
RewriteSystemBuilder::getConcreteSubstitutionSchema(CanType concreteType,
91-
const ProtocolDecl *proto,
92-
SmallVectorImpl<Term> &result) {
91+
RuleBuilder::getConcreteSubstitutionSchema(CanType concreteType,
92+
const ProtocolDecl *proto,
93+
SmallVectorImpl<Term> &result) {
9394
assert(!concreteType->isTypeParameter() && "Must have a concrete type here");
9495

9596
if (!concreteType->hasTypeParameter())
@@ -108,29 +109,29 @@ RewriteSystemBuilder::getConcreteSubstitutionSchema(CanType concreteType,
108109
}));
109110
}
110111

111-
void RewriteSystemBuilder::addRequirements(ArrayRef<Requirement> requirements) {
112+
void RuleBuilder::addRequirements(ArrayRef<Requirement> requirements) {
112113
// Collect all protocols transitively referenced from these requirements.
113114
for (auto req : requirements) {
114115
if (req.getKind() == RequirementKind::Conformance) {
115116
addProtocol(req.getProtocolDecl(), /*initialComponent=*/false);
116117
}
117118
}
118119

119-
processProtocolDependencies();
120+
collectRulesFromReferencedProtocols();
120121

121122
// Add rewrite rules for all top-level requirements.
122123
for (const auto &req : requirements)
123124
addRequirement(req, /*proto=*/nullptr);
124125
}
125126

126-
void RewriteSystemBuilder::addProtocols(ArrayRef<const ProtocolDecl *> protos) {
127+
void RuleBuilder::addProtocols(ArrayRef<const ProtocolDecl *> protos) {
127128
// Collect all protocols transitively referenced from this connected component
128129
// of the protocol dependency graph.
129130
for (auto proto : protos) {
130131
addProtocol(proto, /*initialComponent=*/true);
131132
}
132133

133-
processProtocolDependencies();
134+
collectRulesFromReferencedProtocols();
134135
}
135136

136137
/// For an associated type T in a protocol P, we add a rewrite rule:
@@ -139,8 +140,8 @@ void RewriteSystemBuilder::addProtocols(ArrayRef<const ProtocolDecl *> protos) {
139140
///
140141
/// Intuitively, this means "if a type conforms to P, it has a nested type
141142
/// named T".
142-
void RewriteSystemBuilder::addAssociatedType(const AssociatedTypeDecl *type,
143-
const ProtocolDecl *proto) {
143+
void RuleBuilder::addAssociatedType(const AssociatedTypeDecl *type,
144+
const ProtocolDecl *proto) {
144145
MutableTerm lhs;
145146
lhs.add(Symbol::forProtocol(proto, Context));
146147
lhs.add(Symbol::forName(type->getName(), Context));
@@ -160,8 +161,8 @@ void RewriteSystemBuilder::addAssociatedType(const AssociatedTypeDecl *type,
160161
/// If \p proto is non-null, this is a generic requirement in the protocol's
161162
/// requirement signature. The added rewrite rule will be rooted in a
162163
/// protocol symbol.
163-
void RewriteSystemBuilder::addRequirement(const Requirement &req,
164-
const ProtocolDecl *proto) {
164+
void RuleBuilder::addRequirement(const Requirement &req,
165+
const ProtocolDecl *proto) {
165166
if (Dump) {
166167
llvm::dbgs() << "+ ";
167168
req.dump(llvm::dbgs());
@@ -281,16 +282,16 @@ void RewriteSystemBuilder::addRequirement(const Requirement &req,
281282
}
282283

283284
/// Record information about a protocol if we have no seen it yet.
284-
void RewriteSystemBuilder::addProtocol(const ProtocolDecl *proto,
285-
bool initialComponent) {
285+
void RuleBuilder::addProtocol(const ProtocolDecl *proto,
286+
bool initialComponent) {
286287
if (ProtocolMap.count(proto) > 0)
287288
return;
288289

289290
ProtocolMap[proto] = initialComponent;
290291
Protocols.push_back(proto);
291292
}
292293

293-
void RewriteSystemBuilder::processProtocolDependencies() {
294+
void RuleBuilder::collectRulesFromReferencedProtocols() {
294295
unsigned i = 0;
295296
while (i < Protocols.size()) {
296297
auto *proto = Protocols[i++];
@@ -490,7 +491,7 @@ void RequirementMachine::initWithGenericSignature(CanGenericSignature sig) {
490491

491492
// Collect the top-level requirements, and all transtively-referenced
492493
// protocol requirement signatures.
493-
RewriteSystemBuilder builder(Context, Dump);
494+
RuleBuilder builder(Context, Dump);
494495
builder.addRequirements(sig.getRequirements());
495496

496497
// Add the initial set of rewrite rules to the rewrite system.
@@ -530,7 +531,7 @@ void RequirementMachine::initWithProtocols(ArrayRef<const ProtocolDecl *> protos
530531
llvm::dbgs() << " {\n";
531532
}
532533

533-
RewriteSystemBuilder builder(Context, Dump);
534+
RuleBuilder builder(Context, Dump);
534535
builder.addProtocols(protos);
535536

536537
// Add the initial set of rewrite rules to the rewrite system.
@@ -570,7 +571,7 @@ void RequirementMachine::initWithAbstractRequirements(
570571

571572
// Collect the top-level requirements, and all transtively-referenced
572573
// protocol requirement signatures.
573-
RewriteSystemBuilder builder(Context, Dump);
574+
RuleBuilder builder(Context, Dump);
574575
builder.addRequirements(requirements);
575576

576577
// Add the initial set of rewrite rules to the rewrite system.

0 commit comments

Comments
 (0)