Skip to content

Commit 62de909

Browse files
committed
RequirementMachine: Some comments
1 parent 03dfa60 commit 62de909

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

lib/AST/RequirementMachine/GeneratingConformances.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ using namespace rewriting;
5252
/// Finds all protocol conformance rules appearing in a 3-cell, both without
5353
/// context, and with a non-empty left context. Applications of rules with a
5454
/// non-empty right context are ignored.
55+
///
56+
/// The rules are organized by protocol. For each protocol, the first element
57+
/// of the pair stores conformance rules that appear without context. The
58+
/// second element of the pair stores rules that appear with non-empty left
59+
/// context. For each such rule, the left prefix is also stored alongside.
5560
void HomotopyGenerator::findProtocolConformanceRules(
5661
llvm::SmallDenseMap<const ProtocolDecl *,
5762
std::pair<SmallVector<unsigned, 2>,

lib/AST/RequirementMachine/RequirementMachine.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,10 @@ RequirementMachine::RequirementMachine(RewriteContext &ctx)
369369

370370
RequirementMachine::~RequirementMachine() {}
371371

372+
/// Build a requirement machine for the requirements of a generic signature.
373+
///
374+
/// This must only be called exactly once, before any other operations are
375+
/// performed on this requirement machine.
372376
void RequirementMachine::initWithGenericSignature(CanGenericSignature sig) {
373377
Sig = sig;
374378

@@ -404,6 +408,12 @@ void RequirementMachine::initWithGenericSignature(CanGenericSignature sig) {
404408
}
405409
}
406410

411+
/// Build a requirement machine for the structural requirements of a set
412+
/// of protocols, which are understood to form a strongly-connected component
413+
/// (SCC) of the protocol dependency graph.
414+
///
415+
/// This must only be called exactly once, before any other operations are
416+
/// performed on this requirement machine.
407417
void RequirementMachine::initWithProtocols(ArrayRef<const ProtocolDecl *> protos) {
408418
Protos = protos;
409419

lib/AST/RequirementMachine/RewriteContext.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,8 @@ bool RewriteContext::isRecursivelyConstructingRequirementMachine(
382382
return !found->second->isComplete();
383383
}
384384

385+
/// Implement Tarjan's algorithm to compute strongly-connected components in
386+
/// the protocol dependency graph.
385387
void RewriteContext::getRequirementMachineRec(
386388
const ProtocolDecl *proto,
387389
SmallVectorImpl<const ProtocolDecl *> &stack) {
@@ -453,6 +455,8 @@ void RewriteContext::getRequirementMachineRec(
453455
}
454456
}
455457

458+
/// Lazily construct a requirement machine for the given protocol's strongly
459+
/// connected component (SCC) in the protocol dependency graph.
456460
RequirementMachine *RewriteContext::getRequirementMachine(
457461
const ProtocolDecl *proto) {
458462
auto found = Protos.find(proto);
@@ -471,6 +475,8 @@ RequirementMachine *RewriteContext::getRequirementMachine(
471475
auto *&machine = component.Machine;
472476

473477
if (machine) {
478+
// If this component has a machine already, make sure it is ready
479+
// for use.
474480
if (!machine->isComplete()) {
475481
llvm::errs() << "Re-entrant construction of requirement "
476482
<< "machine for:";
@@ -479,6 +485,8 @@ RequirementMachine *RewriteContext::getRequirementMachine(
479485
abort();
480486
}
481487
} else {
488+
// Construct a requirement machine from the structural requirements of
489+
// the given set of protocols.
482490
machine = new RequirementMachine(*this);
483491
machine->initWithProtocols(component.Protos);
484492
}

0 commit comments

Comments
 (0)