From bc068ae68e491a62e31861d420e2b51ac8eb674d Mon Sep 17 00:00:00 2001 From: David Ungar Date: Wed, 4 Dec 2019 10:47:03 -0800 Subject: [PATCH] format --- .../Driver/CoarseGrainedDependencyGraph.h | 38 ++++++++++--------- .../Driver/FineGrainedDependencyDriverGraph.h | 19 ++++++---- lib/Driver/CoarseGrainedDependencyGraph.cpp | 29 +++++++------- lib/Driver/Compilation.cpp | 21 +++++----- .../FineGrainedDependencyDriverGraph.cpp | 3 +- .../CoarseGrainedDependencyGraphTests.cpp | 37 +++++++++--------- 6 files changed, 80 insertions(+), 67 deletions(-) diff --git a/include/swift/Driver/CoarseGrainedDependencyGraph.h b/include/swift/Driver/CoarseGrainedDependencyGraph.h index ffb4f17e0ab..7d5fa9cf189 100644 --- a/include/swift/Driver/CoarseGrainedDependencyGraph.h +++ b/include/swift/Driver/CoarseGrainedDependencyGraph.h @@ -43,8 +43,8 @@ class CoarseGrainedDependencyGraphImpl { public: /// Possible dependency kinds. /// - /// Clients of CoarseGrainedDependencyGraph should have no reason to use this type. - /// It is only used in the implementation. + /// Clients of CoarseGrainedDependencyGraph should have no reason to use this + /// type. It is only used in the implementation. enum class DependencyKind : uint8_t; /// Describes the result of loading a dependency file for a particular node. @@ -62,7 +62,8 @@ public: AffectsDownstream }; - /// The non-templated implementation of CoarseGrainedDependencyGraph::MarkTracer. + /// The non-templated implementation of + /// CoarseGrainedDependencyGraph::MarkTracer. /// /// \see CoarseGrainedDependencyGraph::MarkTracer class MarkTracerImpl { @@ -71,6 +72,7 @@ public: UnifiedStatsReporter *Stats; friend class CoarseGrainedDependencyGraphImpl; + protected: explicit MarkTracerImpl(UnifiedStatsReporter *Stats); ~MarkTracerImpl(); @@ -210,7 +212,8 @@ class CoarseGrainedDependencyGraph : public CoarseGrainedDependencyGraphImpl { } public: - /// Traces the graph traversal performed in CoarseGrainedDependencyGraph::markTransitive. + /// Traces the graph traversal performed in + /// CoarseGrainedDependencyGraph::markTransitive. /// /// This is intended to be a debugging aid. class MarkTracer : public MarkTracerImpl { @@ -240,8 +243,8 @@ public: /// call site can polymorphically call \ref /// fine_grained_dependencies::ModuleDepGraph::loadFromPath LoadResult loadFromPath(T node, StringRef path, DiagnosticEngine &) { - return CoarseGrainedDependencyGraphImpl::loadFromPath(Traits::getAsVoidPointer(node), - path); + return CoarseGrainedDependencyGraphImpl::loadFromPath( + Traits::getAsVoidPointer(node), path); } /// Load "depends" and "provides" data for \p node from a plain string. @@ -250,16 +253,16 @@ public: /// /// \sa loadFromPath LoadResult loadFromString(T node, StringRef data) { - return CoarseGrainedDependencyGraphImpl::loadFromString(Traits::getAsVoidPointer(node), - data); + return CoarseGrainedDependencyGraphImpl::loadFromString( + Traits::getAsVoidPointer(node), data); } /// Adds \p node to the dependency graph without any connections. /// /// This can be used for new nodes that may be updated later. void addIndependentNode(T node) { - return - CoarseGrainedDependencyGraphImpl::addIndependentNode(Traits::getAsVoidPointer(node)); + return CoarseGrainedDependencyGraphImpl::addIndependentNode( + Traits::getAsVoidPointer(node)); } /// Marks \p node and all nodes that depend on \p node, and places any nodes @@ -287,9 +290,8 @@ public: void markTransitive(SmallVector &visited, T node, MarkTracer *tracer = nullptr) { SmallVector rawMarked; - CoarseGrainedDependencyGraphImpl::markTransitive(rawMarked, - Traits::getAsVoidPointer(node), - tracer); + CoarseGrainedDependencyGraphImpl::markTransitive( + rawMarked, Traits::getAsVoidPointer(node), tracer); // FIXME: How can we avoid this copy? copyBack(visited, rawMarked); } @@ -297,7 +299,8 @@ public: template void markExternal(SmallVector &visited, StringRef externalDependency) { SmallVector rawMarked; - CoarseGrainedDependencyGraphImpl::markExternal(rawMarked, externalDependency); + CoarseGrainedDependencyGraphImpl::markExternal(rawMarked, + externalDependency); // FIXME: How can we avoid this copy? copyBack(visited, rawMarked); } @@ -308,13 +311,14 @@ public: /// /// \sa #markTransitive bool markIntransitive(T node) { - return - CoarseGrainedDependencyGraphImpl::markIntransitive(Traits::getAsVoidPointer(node)); + return CoarseGrainedDependencyGraphImpl::markIntransitive( + Traits::getAsVoidPointer(node)); } /// Returns true if \p node has been marked (directly or transitively). bool isMarked(T node) const { - return CoarseGrainedDependencyGraphImpl::isMarked(Traits::getAsVoidPointer(node)); + return CoarseGrainedDependencyGraphImpl::isMarked( + Traits::getAsVoidPointer(node)); } }; diff --git a/include/swift/Driver/FineGrainedDependencyDriverGraph.h b/include/swift/Driver/FineGrainedDependencyDriverGraph.h index 1d54d7ad46c..d685754f349 100644 --- a/include/swift/Driver/FineGrainedDependencyDriverGraph.h +++ b/include/swift/Driver/FineGrainedDependencyDriverGraph.h @@ -110,7 +110,8 @@ public: class CoarseGrainedDependencyGraphImpl { public: /// Use the status quo LoadResult for now. - using LoadResult = typename swift::CoarseGrainedDependencyGraphImpl::LoadResult; + using LoadResult = + typename swift::CoarseGrainedDependencyGraphImpl::LoadResult; }; //============================================================================== @@ -268,10 +269,11 @@ public: } /// Unlike the standard \c CoarseGrainedDependencyGraph, returns \c - /// CoarseGrainedDependencyGraphImpl::LoadResult::AffectsDownstream when loading a new - /// file, i.e. when determining the initial set. Caller compensates. - CoarseGrainedDependencyGraphImpl::LoadResult loadFromPath(const driver::Job *, StringRef, - DiagnosticEngine &); + /// CoarseGrainedDependencyGraphImpl::LoadResult::AffectsDownstream when + /// loading a new file, i.e. when determining the initial set. Caller + /// compensates. + CoarseGrainedDependencyGraphImpl::LoadResult + loadFromPath(const driver::Job *, StringRef, DiagnosticEngine &); /// For the dot file. std::string getGraphID() const { return "driver"; } @@ -372,12 +374,13 @@ private: /// and integrate it into the ModuleDepGraph. /// Used both the first time, and to reload the SourceFileDepGraph. /// If any changes were observed, indicate same in the return vale. - CoarseGrainedDependencyGraphImpl::LoadResult loadFromBuffer(const driver::Job *, - llvm::MemoryBuffer &); + CoarseGrainedDependencyGraphImpl::LoadResult + loadFromBuffer(const driver::Job *, llvm::MemoryBuffer &); /// Integrate a SourceFileDepGraph into the receiver. /// Integration happens when the driver needs to read SourceFileDepGraph. - CoarseGrainedDependencyGraphImpl::LoadResult integrate(const SourceFileDepGraph &); + CoarseGrainedDependencyGraphImpl::LoadResult + integrate(const SourceFileDepGraph &); enum class LocationOfPreexistingNode { nowhere, here, elsewhere }; diff --git a/lib/Driver/CoarseGrainedDependencyGraph.cpp b/lib/Driver/CoarseGrainedDependencyGraph.cpp index fd18f9641eb..0513519d1b5 100644 --- a/lib/Driver/CoarseGrainedDependencyGraph.cpp +++ b/lib/Driver/CoarseGrainedDependencyGraph.cpp @@ -10,9 +10,9 @@ // //===----------------------------------------------------------------------===// +#include "swift/Driver/CoarseGrainedDependencyGraph.h" #include "swift/Basic/ReferenceDependencyKeys.h" #include "swift/Basic/Statistic.h" -#include "swift/Driver/CoarseGrainedDependencyGraph.h" #include "swift/Demangling/Demangle.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallVector.h" @@ -43,8 +43,9 @@ public: DependencyMaskTy KindMask; }; -CoarseGrainedDependencyGraphImpl::MarkTracerImpl::MarkTracerImpl(UnifiedStatsReporter *Stats) - : Stats(Stats) {} +CoarseGrainedDependencyGraphImpl::MarkTracerImpl::MarkTracerImpl( + UnifiedStatsReporter *Stats) + : Stats(Stats) {} CoarseGrainedDependencyGraphImpl::MarkTracerImpl::~MarkTracerImpl() = default; using LoadResult = CoarseGrainedDependencyGraphImpl::LoadResult; @@ -211,21 +212,23 @@ parseDependencyFile(llvm::MemoryBuffer &buffer, return result; } -LoadResult CoarseGrainedDependencyGraphImpl::loadFromPath(const void *node, StringRef path) { +LoadResult CoarseGrainedDependencyGraphImpl::loadFromPath(const void *node, + StringRef path) { auto buffer = llvm::MemoryBuffer::getFile(path); if (!buffer) return LoadResult::HadError; return loadFromBuffer(node, *buffer.get()); } -LoadResult -CoarseGrainedDependencyGraphImpl::loadFromString(const void *node, StringRef data) { +LoadResult CoarseGrainedDependencyGraphImpl::loadFromString(const void *node, + StringRef data) { auto buffer = llvm::MemoryBuffer::getMemBuffer(data); return loadFromBuffer(node, *buffer); } -LoadResult CoarseGrainedDependencyGraphImpl::loadFromBuffer(const void *node, - llvm::MemoryBuffer &buffer) { +LoadResult +CoarseGrainedDependencyGraphImpl::loadFromBuffer(const void *node, + llvm::MemoryBuffer &buffer) { auto &provides = Provides[node]; auto dependsCallback = [this, node](StringRef name, DependencyKind kind, @@ -294,8 +297,8 @@ LoadResult CoarseGrainedDependencyGraphImpl::loadFromBuffer(const void *node, interfaceHashCallback); } -void CoarseGrainedDependencyGraphImpl::markExternal(SmallVectorImpl &visited, - StringRef externalDependency) { +void CoarseGrainedDependencyGraphImpl::markExternal( + SmallVectorImpl &visited, StringRef externalDependency) { forEachUnmarkedJobDirectlyDependentOnExternalSwiftdeps( externalDependency, [&](const void *node) { visited.push_back(node); @@ -319,9 +322,9 @@ void CoarseGrainedDependencyGraphImpl:: } } -void -CoarseGrainedDependencyGraphImpl::markTransitive(SmallVectorImpl &visited, - const void *node, MarkTracerImpl *tracer) { +void CoarseGrainedDependencyGraphImpl::markTransitive( + SmallVectorImpl &visited, const void *node, + MarkTracerImpl *tracer) { assert(Provides.count(node) && "node is not in the graph"); llvm::SpecificBumpPtrAllocator scratchAlloc; diff --git a/lib/Driver/Compilation.cpp b/lib/Driver/Compilation.cpp index ea5e1af3a35..de71bfeafcf 100644 --- a/lib/Driver/Compilation.cpp +++ b/lib/Driver/Compilation.cpp @@ -239,7 +239,8 @@ namespace driver { /// /// Dependency graphs for deciding which jobs are dirty (need running) /// or clean (can be skipped). - using CoarseGrainedDependencyGraph = CoarseGrainedDependencyGraph; + using CoarseGrainedDependencyGraph = + CoarseGrainedDependencyGraph; CoarseGrainedDependencyGraph CoarseGrainedDepGraph; CoarseGrainedDependencyGraph CoarseGrainedDepGraphForRanges; @@ -1586,20 +1587,19 @@ namespace driver { : getDepGraph(forRanges).markIntransitive(Cmd); } - CoarseGrainedDependencyGraph::LoadResult loadDepGraphFromPath(const Job *Cmd, - StringRef path, - DiagnosticEngine &diags, - const bool forRanges) { + CoarseGrainedDependencyGraph::LoadResult + loadDepGraphFromPath(const Job *Cmd, StringRef path, + DiagnosticEngine &diags, const bool forRanges) { return Comp.getEnableFineGrainedDependencies() ? getExpDepGraph(forRanges).loadFromPath(Cmd, path, diags) : getDepGraph(forRanges).loadFromPath(Cmd, path, diags); } template - void - markTransitiveInDepGraph(SmallVector &visited, - const Job *Cmd, const bool forRanges, - CoarseGrainedDependencyGraph::MarkTracer *tracer = nullptr) { + void markTransitiveInDepGraph( + SmallVector &visited, const Job *Cmd, + const bool forRanges, + CoarseGrainedDependencyGraph::MarkTracer *tracer = nullptr) { if (Comp.getEnableFineGrainedDependencies()) getExpDepGraph(forRanges).markTransitive(visited, Cmd, tracer); else @@ -1624,7 +1624,8 @@ namespace driver { getExpDepGraph(const bool forRanges) const { return forRanges ? ExpDepGraphForRanges : ExpDepGraph; } - const CoarseGrainedDependencyGraph &getDepGraph(const bool forRanges) const { + const CoarseGrainedDependencyGraph & + getDepGraph(const bool forRanges) const { return forRanges ? CoarseGrainedDepGraphForRanges : CoarseGrainedDepGraph; } }; diff --git a/lib/Driver/FineGrainedDependencyDriverGraph.cpp b/lib/Driver/FineGrainedDependencyDriverGraph.cpp index e3a23dafc12..0b3b76ca3d5 100644 --- a/lib/Driver/FineGrainedDependencyDriverGraph.cpp +++ b/lib/Driver/FineGrainedDependencyDriverGraph.cpp @@ -41,7 +41,8 @@ using namespace swift::driver; // MARK: Interfacing to Compilation //============================================================================== -using LoadResult = fine_grained_dependencies::CoarseGrainedDependencyGraphImpl::LoadResult; +using LoadResult = + fine_grained_dependencies::CoarseGrainedDependencyGraphImpl::LoadResult; LoadResult ModuleDepGraph::loadFromPath(const Job *Cmd, StringRef path, DiagnosticEngine &diags) { diff --git a/unittests/Driver/CoarseGrainedDependencyGraphTests.cpp b/unittests/Driver/CoarseGrainedDependencyGraphTests.cpp index 0d71dc04a07..641a2360fa6 100644 --- a/unittests/Driver/CoarseGrainedDependencyGraphTests.cpp +++ b/unittests/Driver/CoarseGrainedDependencyGraphTests.cpp @@ -6,29 +6,30 @@ using namespace swift; using LoadResult = CoarseGrainedDependencyGraphImpl::LoadResult; using namespace reference_dependency_keys; -static LoadResult loadFromString(CoarseGrainedDependencyGraph &dg, uintptr_t node, - StringRef key, StringRef data) { +static LoadResult loadFromString(CoarseGrainedDependencyGraph &dg, + uintptr_t node, StringRef key, + StringRef data) { return dg.loadFromString(node, key.str() + ": [" + data.str() + "]"); } -static LoadResult loadFromString(CoarseGrainedDependencyGraph &dg, uintptr_t node, - StringRef key1, StringRef data1, - StringRef key2, StringRef data2) { - return dg.loadFromString(node, - key1.str() + ": [" + data1.str() + "]\n" + - key2.str() + ": [" + data2.str() + "]"); +static LoadResult loadFromString(CoarseGrainedDependencyGraph &dg, + uintptr_t node, StringRef key1, + StringRef data1, StringRef key2, + StringRef data2) { + return dg.loadFromString(node, key1.str() + ": [" + data1.str() + "]\n" + + key2.str() + ": [" + data2.str() + "]"); } -static LoadResult loadFromString(CoarseGrainedDependencyGraph &dg, uintptr_t node, - StringRef key1, StringRef data1, - StringRef key2, StringRef data2, - StringRef key3, StringRef data3, - StringRef key4, StringRef data4) { - return dg.loadFromString(node, - key1.str() + ": [" + data1.str() + "]\n" + - key2.str() + ": [" + data2.str() + "]\n" + - key3.str() + ": [" + data3.str() + "]\n" + - key4.str() + ": [" + data4.str() + "]\n"); +static LoadResult loadFromString(CoarseGrainedDependencyGraph &dg, + uintptr_t node, StringRef key1, + StringRef data1, StringRef key2, + StringRef data2, StringRef key3, + StringRef data3, StringRef key4, + StringRef data4) { + return dg.loadFromString(node, key1.str() + ": [" + data1.str() + "]\n" + + key2.str() + ": [" + data2.str() + "]\n" + + key3.str() + ": [" + data3.str() + "]\n" + + key4.str() + ": [" + data4.str() + "]\n"); } TEST(CoarseGrainedDependencyGraph, BasicLoad) {