Skip to content

Commit 2b2bcdd

Browse files
author
David Ungar
committed
Fix arg-order bug and add assertions. (Windows manifested.)
1 parent 126932f commit 2b2bcdd

File tree

2 files changed

+39
-27
lines changed

2 files changed

+39
-27
lines changed

include/swift/AST/FineGrainedDependencies.h

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -390,17 +390,6 @@ template <typename NodeT> class InterfaceAndImplementationPair {
390390

391391
InterfaceAndImplementationPair(NodeT *interface, NodeT *implementation)
392392
: interface(interface), implementation(implementation) {
393-
394-
if (!interface->getKey().isInterface()) {
395-
llvm::errs() << "interface key is wrong: \n";
396-
interface->dump();
397-
}
398-
if (!implementation->getKey().isImplementation()) {
399-
llvm::errs() << "implementation key is wrong: \n";
400-
implementation->dump();
401-
}
402-
403-
404393
assert(
405394
interface->getKey().isInterface() &&
406395
implementation->getKey().isImplementation() &&
@@ -725,8 +714,29 @@ class SourceFileDepGraphNode : public DepGraphNode {
725714
bool verify() const {
726715
DepGraphNode::verify();
727716
assert(getIsProvides() || isDepends());
717+
assert(verifySequenceNumber());
728718
return true;
729719
}
720+
721+
bool verifySequenceNumber() const {
722+
const auto &k = getKey();
723+
if (k.getKind() != NodeKind::sourceFileProvide)
724+
return true;
725+
switch (k.getAspect()) {
726+
case DeclAspect::interface:
727+
assert(getSequenceNumber() == sourceFileProvidesInterfaceSequenceNumber);
728+
return true;
729+
case DeclAspect::implementation:
730+
assert(getSequenceNumber() ==
731+
sourceFileProvidesImplementationSequenceNumber);
732+
return true;
733+
default:
734+
llvm_unreachable("neither interface nor implementation");
735+
}
736+
}
737+
static constexpr const size_t sourceFileProvidesInterfaceSequenceNumber = 0;
738+
static constexpr const size_t sourceFileProvidesImplementationSequenceNumber =
739+
1;
730740
};
731741

732742
//==============================================================================
@@ -849,14 +859,14 @@ class SourceFileDepGraph {
849859
/// Ensure that when read, the graph is the same as what was written.
850860
bool verifyReadsWhatIsWritten(StringRef path) const;
851861

862+
bool verifySequenceNumber() const;
863+
852864
private:
853865
void addNode(SourceFileDepGraphNode *n) {
854866
n->setSequenceNumber(allNodes.size());
855-
assert(allNodes.size() < 2 ==
856-
(n->getKey().getKind() == NodeKind::sourceFileProvide) &&
857-
"First two and only first two nodes should be sourceFileProvide "
858-
"nodes.");
859867
allNodes.push_back(n);
868+
assert(n->verifySequenceNumber() &&
869+
"Certain nodes must be in certain places");
860870
}
861871
};
862872

lib/AST/FineGrainedDependencies.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,11 @@ SourceFileDepGraph::getNode(size_t sequenceNumber) const {
4949

5050
InterfaceAndImplementationPair<SourceFileDepGraphNode>
5151
SourceFileDepGraph::getSourceFileNodePair() const {
52-
assert(getNode(0)->getKey().getKind() == NodeKind::sourceFileProvide &&
53-
"First node must be sourceFileProvide.");
54-
assert(getNode(1)->getKey().getKind() == NodeKind::sourceFileProvide &&
55-
"Second node must be sourceFileProvide.");
56-
return InterfaceAndImplementationPair<SourceFileDepGraphNode>(getNode(0),
57-
getNode(1));
52+
return InterfaceAndImplementationPair<SourceFileDepGraphNode>(
53+
getNode(
54+
SourceFileDepGraphNode::sourceFileProvidesInterfaceSequenceNumber),
55+
getNode(SourceFileDepGraphNode::
56+
sourceFileProvidesImplementationSequenceNumber));
5857
}
5958

6059
StringRef SourceFileDepGraph::getSwiftDepsOfJobThatProducedThisGraph() const {
@@ -82,13 +81,16 @@ SourceFileDepGraph::findExistingNodePairOrCreateAndAddIfNew(
8281
const std::string &name = std::get<1>(contextNameFingerprint);
8382
const Optional<std::string> &fingerprint =
8483
std::get<2>(contextNameFingerprint);
84+
auto *interfaceNode = findExistingNodeOrCreateIfNew(
85+
DependencyKey(k, DeclAspect::interface, context, name), fingerprint,
86+
true /* = isProvides */);
87+
auto *implementationNode = findExistingNodeOrCreateIfNew(
88+
DependencyKey(k, DeclAspect::implementation, context, name), fingerprint,
89+
true /* = isProvides */);
90+
8591
InterfaceAndImplementationPair<SourceFileDepGraphNode> nodePair{
86-
findExistingNodeOrCreateIfNew(
87-
DependencyKey(k, DeclAspect::interface, context, name), fingerprint,
88-
true /* = isProvides */),
89-
findExistingNodeOrCreateIfNew(
90-
DependencyKey(k, DeclAspect::implementation, context, name),
91-
fingerprint, true /* = isProvides */)};
92+
interfaceNode, implementationNode};
93+
9294
// if interface changes, have to rebuild implementation.
9395
// This dependency used to be represented by
9496
// addArc(nodePair.getInterface(), nodePair.getImplementation());

0 commit comments

Comments
 (0)