Skip to content

Commit 86a76cb

Browse files
author
David Ungar
authored
Merge pull request #28566 from davidungar/renaming-dependencies-2
Rename older dependency graph to "CoarseGrainedDependencyGraph"
2 parents 9072cce + bc068ae commit 86a76cb

9 files changed

+182
-169
lines changed

include/swift/Driver/DependencyGraph.h renamed to include/swift/Driver/CoarseGrainedDependencyGraph.h

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===--- DependencyGraph.h - Track intra-module dependencies ----*- C++ -*-===//
1+
//===- CoarseGrainedDependencyGraph.h - Track intra-module dependencies -*- C++ -*-===//
22
//
33
// This source file is part of the Swift.org open source project
44
//
@@ -10,8 +10,8 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#ifndef SWIFT_DRIVER_DEPENDENCYGRAPH_H
14-
#define SWIFT_DRIVER_DEPENDENCYGRAPH_H
13+
#ifndef SWIFT_DRIVER_COARSEGRAINEDDEPENDENCYGRAPH_H
14+
#define SWIFT_DRIVER_COARSEGRAINEDDEPENDENCYGRAPH_H
1515

1616
#include "swift/AST/DiagnosticEngine.h"
1717
#include "swift/Basic/LLVM.h"
@@ -36,15 +36,15 @@ namespace swift {
3636

3737
class UnifiedStatsReporter;
3838

39-
/// The non-templated implementation of DependencyGraph.
39+
/// The non-templated implementation of CoarseGrainedDependencyGraph.
4040
///
41-
/// \see DependencyGraph
42-
class DependencyGraphImpl {
41+
/// \see CoarseGrainedDependencyGraph
42+
class CoarseGrainedDependencyGraphImpl {
4343
public:
4444
/// Possible dependency kinds.
4545
///
46-
/// Clients of DependencyGraph should have no reason to use this type.
47-
/// It is only used in the implementation.
46+
/// Clients of CoarseGrainedDependencyGraph should have no reason to use this
47+
/// type. It is only used in the implementation.
4848
enum class DependencyKind : uint8_t;
4949

5050
/// Describes the result of loading a dependency file for a particular node.
@@ -62,15 +62,17 @@ class DependencyGraphImpl {
6262
AffectsDownstream
6363
};
6464

65-
/// The non-templated implementation of DependencyGraph::MarkTracer.
65+
/// The non-templated implementation of
66+
/// CoarseGrainedDependencyGraph::MarkTracer.
6667
///
67-
/// \see DependencyGraph::MarkTracer
68+
/// \see CoarseGrainedDependencyGraph::MarkTracer
6869
class MarkTracerImpl {
6970
class Entry;
7071
llvm::DenseMap<const void *, SmallVector<Entry, 4>> Table;
7172
UnifiedStatsReporter *Stats;
7273

73-
friend class DependencyGraphImpl;
74+
friend class CoarseGrainedDependencyGraphImpl;
75+
7476
protected:
7577
explicit MarkTracerImpl(UnifiedStatsReporter *Stats);
7678
~MarkTracerImpl();
@@ -154,7 +156,7 @@ class DependencyGraphImpl {
154156
(void)newlyInserted;
155157
}
156158

157-
/// See DependencyGraph::markTransitive.
159+
/// See CoarseGrainedDependencyGraph::markTransitive.
158160

159161
void markTransitive(SmallVectorImpl<const void *> &visited,
160162
const void *node, MarkTracerImpl *tracer = nullptr);
@@ -196,7 +198,7 @@ class DependencyGraphImpl {
196198
/// The graph also supports a "mark" operation, which is intended to track
197199
/// nodes that have been not just visited but transitively marked through.
198200
template <typename T>
199-
class DependencyGraph : public DependencyGraphImpl {
201+
class CoarseGrainedDependencyGraph : public CoarseGrainedDependencyGraphImpl {
200202
using Traits = llvm::PointerLikeTypeTraits<T>;
201203
static_assert(Traits::NumLowBitsAvailable >= 0, "not a pointer-like type");
202204

@@ -210,7 +212,8 @@ class DependencyGraph : public DependencyGraphImpl {
210212
}
211213

212214
public:
213-
/// Traces the graph traversal performed in DependencyGraph::markTransitive.
215+
/// Traces the graph traversal performed in
216+
/// CoarseGrainedDependencyGraph::markTransitive.
214217
///
215218
/// This is intended to be a debugging aid.
216219
class MarkTracer : public MarkTracerImpl {
@@ -240,8 +243,8 @@ class DependencyGraph : public DependencyGraphImpl {
240243
/// call site can polymorphically call \ref
241244
/// fine_grained_dependencies::ModuleDepGraph::loadFromPath
242245
LoadResult loadFromPath(T node, StringRef path, DiagnosticEngine &) {
243-
return DependencyGraphImpl::loadFromPath(Traits::getAsVoidPointer(node),
244-
path);
246+
return CoarseGrainedDependencyGraphImpl::loadFromPath(
247+
Traits::getAsVoidPointer(node), path);
245248
}
246249

247250
/// Load "depends" and "provides" data for \p node from a plain string.
@@ -250,16 +253,16 @@ class DependencyGraph : public DependencyGraphImpl {
250253
///
251254
/// \sa loadFromPath
252255
LoadResult loadFromString(T node, StringRef data) {
253-
return DependencyGraphImpl::loadFromString(Traits::getAsVoidPointer(node),
254-
data);
256+
return CoarseGrainedDependencyGraphImpl::loadFromString(
257+
Traits::getAsVoidPointer(node), data);
255258
}
256259

257260
/// Adds \p node to the dependency graph without any connections.
258261
///
259262
/// This can be used for new nodes that may be updated later.
260263
void addIndependentNode(T node) {
261-
return
262-
DependencyGraphImpl::addIndependentNode(Traits::getAsVoidPointer(node));
264+
return CoarseGrainedDependencyGraphImpl::addIndependentNode(
265+
Traits::getAsVoidPointer(node));
263266
}
264267

265268
/// Marks \p node and all nodes that depend on \p node, and places any nodes
@@ -287,17 +290,17 @@ class DependencyGraph : public DependencyGraphImpl {
287290
void markTransitive(SmallVector<T, N> &visited, T node,
288291
MarkTracer *tracer = nullptr) {
289292
SmallVector<const void *, N> rawMarked;
290-
DependencyGraphImpl::markTransitive(rawMarked,
291-
Traits::getAsVoidPointer(node),
292-
tracer);
293+
CoarseGrainedDependencyGraphImpl::markTransitive(
294+
rawMarked, Traits::getAsVoidPointer(node), tracer);
293295
// FIXME: How can we avoid this copy?
294296
copyBack(visited, rawMarked);
295297
}
296298

297299
template <unsigned N>
298300
void markExternal(SmallVector<T, N> &visited, StringRef externalDependency) {
299301
SmallVector<const void *, N> rawMarked;
300-
DependencyGraphImpl::markExternal(rawMarked, externalDependency);
302+
CoarseGrainedDependencyGraphImpl::markExternal(rawMarked,
303+
externalDependency);
301304
// FIXME: How can we avoid this copy?
302305
copyBack(visited, rawMarked);
303306
}
@@ -308,13 +311,14 @@ class DependencyGraph : public DependencyGraphImpl {
308311
///
309312
/// \sa #markTransitive
310313
bool markIntransitive(T node) {
311-
return
312-
DependencyGraphImpl::markIntransitive(Traits::getAsVoidPointer(node));
314+
return CoarseGrainedDependencyGraphImpl::markIntransitive(
315+
Traits::getAsVoidPointer(node));
313316
}
314317

315318
/// Returns true if \p node has been marked (directly or transitively).
316319
bool isMarked(T node) const {
317-
return DependencyGraphImpl::isMarked(Traits::getAsVoidPointer(node));
320+
return CoarseGrainedDependencyGraphImpl::isMarked(
321+
Traits::getAsVoidPointer(node));
318322
}
319323
};
320324

include/swift/Driver/FineGrainedDependencyDriverGraph.h

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include "swift/Basic/Debug.h"
1818
#include "swift/Basic/LLVM.h"
1919
#include "swift/Basic/OptionSet.h"
20-
#include "swift/Driver/DependencyGraph.h"
20+
#include "swift/Driver/CoarseGrainedDependencyGraph.h"
2121
#include "swift/Driver/Job.h"
2222
#include "llvm/ADT/ArrayRef.h"
2323
#include "llvm/ADT/DenseMap.h"
@@ -107,10 +107,11 @@ class ModuleDepGraphNode : public DepGraphNode {
107107

108108
/// A placeholder allowing the experimental system to fit into the driver
109109
/// without changing as much code.
110-
class DependencyGraphImpl {
110+
class CoarseGrainedDependencyGraphImpl {
111111
public:
112112
/// Use the status quo LoadResult for now.
113-
using LoadResult = typename swift::DependencyGraphImpl::LoadResult;
113+
using LoadResult =
114+
typename swift::CoarseGrainedDependencyGraphImpl::LoadResult;
114115
};
115116

116117
//==============================================================================
@@ -267,11 +268,12 @@ class ModuleDepGraph {
267268
assert(verify() && "ModuleDepGraph should be fine when created");
268269
}
269270

270-
/// Unlike the standard \c DependencyGraph, returns \c
271-
/// DependencyGraphImpl::LoadResult::AffectsDownstream when loading a new
272-
/// file, i.e. when determining the initial set. Caller compensates.
273-
DependencyGraphImpl::LoadResult loadFromPath(const driver::Job *, StringRef,
274-
DiagnosticEngine &);
271+
/// Unlike the standard \c CoarseGrainedDependencyGraph, returns \c
272+
/// CoarseGrainedDependencyGraphImpl::LoadResult::AffectsDownstream when
273+
/// loading a new file, i.e. when determining the initial set. Caller
274+
/// compensates.
275+
CoarseGrainedDependencyGraphImpl::LoadResult
276+
loadFromPath(const driver::Job *, StringRef, DiagnosticEngine &);
275277

276278
/// For the dot file.
277279
std::string getGraphID() const { return "driver"; }
@@ -372,12 +374,13 @@ class ModuleDepGraph {
372374
/// and integrate it into the ModuleDepGraph.
373375
/// Used both the first time, and to reload the SourceFileDepGraph.
374376
/// If any changes were observed, indicate same in the return vale.
375-
DependencyGraphImpl::LoadResult loadFromBuffer(const driver::Job *,
376-
llvm::MemoryBuffer &);
377+
CoarseGrainedDependencyGraphImpl::LoadResult
378+
loadFromBuffer(const driver::Job *, llvm::MemoryBuffer &);
377379

378380
/// Integrate a SourceFileDepGraph into the receiver.
379381
/// Integration happens when the driver needs to read SourceFileDepGraph.
380-
DependencyGraphImpl::LoadResult integrate(const SourceFileDepGraph &);
382+
CoarseGrainedDependencyGraphImpl::LoadResult
383+
integrate(const SourceFileDepGraph &);
381384

382385
enum class LocationOfPreexistingNode { nowhere, here, elsewhere };
383386

lib/Basic/Statistic.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "swift/AST/Decl.h"
1919
#include "swift/AST/Expr.h"
2020
#include "swift/SIL/SILFunction.h"
21-
#include "swift/Driver/DependencyGraph.h"
21+
#include "swift/Driver/CoarseGrainedDependencyGraph.h"
2222
#include "llvm/ADT/DenseMap.h"
2323
#include "llvm/Config/config.h"
2424
#include "llvm/Support/FileSystem.h"

lib/Driver/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
set(swiftDriver_sources
22
Action.cpp
3+
CoarseGrainedDependencyGraph.cpp
34
Compilation.cpp
45
DarwinToolChains.cpp
5-
DependencyGraph.cpp
66
SourceComparator.cpp
77
Driver.cpp
88
DriverIncrementalRanges.cpp

lib/Driver/DependencyGraph.cpp renamed to lib/Driver/CoarseGrainedDependencyGraph.cpp

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===--- DependencyGraph.cpp - Track intra-module dependencies ------------===//
1+
//===- CoarseGrainedDependencyGraph.cpp - Track intra-module dependencies -===//
22
//
33
// This source file is part of the Swift.org open source project
44
//
@@ -10,9 +10,9 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#include "swift/Driver/CoarseGrainedDependencyGraph.h"
1314
#include "swift/Basic/ReferenceDependencyKeys.h"
1415
#include "swift/Basic/Statistic.h"
15-
#include "swift/Driver/DependencyGraph.h"
1616
#include "swift/Demangling/Demangle.h"
1717
#include "llvm/ADT/SmallString.h"
1818
#include "llvm/ADT/SmallVector.h"
@@ -25,30 +25,31 @@
2525

2626
using namespace swift;
2727

28-
enum class DependencyGraphImpl::DependencyKind : uint8_t {
28+
enum class CoarseGrainedDependencyGraphImpl::DependencyKind : uint8_t {
2929
TopLevelName = 1 << 0,
3030
DynamicLookupName = 1 << 1,
3131
NominalType = 1 << 2,
3232
NominalTypeMember = 1 << 3,
3333
ExternalFile = 1 << 4,
3434
};
35-
enum class DependencyGraphImpl::DependencyFlags : uint8_t {
35+
enum class CoarseGrainedDependencyGraphImpl::DependencyFlags : uint8_t {
3636
IsCascading = 1 << 0
3737
};
3838

39-
class DependencyGraphImpl::MarkTracerImpl::Entry {
39+
class CoarseGrainedDependencyGraphImpl::MarkTracerImpl::Entry {
4040
public:
4141
const void *Node;
4242
StringRef Name;
4343
DependencyMaskTy KindMask;
4444
};
4545

46-
DependencyGraphImpl::MarkTracerImpl::MarkTracerImpl(UnifiedStatsReporter *Stats)
47-
: Stats(Stats) {}
48-
DependencyGraphImpl::MarkTracerImpl::~MarkTracerImpl() = default;
46+
CoarseGrainedDependencyGraphImpl::MarkTracerImpl::MarkTracerImpl(
47+
UnifiedStatsReporter *Stats)
48+
: Stats(Stats) {}
49+
CoarseGrainedDependencyGraphImpl::MarkTracerImpl::~MarkTracerImpl() = default;
4950

50-
using LoadResult = DependencyGraphImpl::LoadResult;
51-
using DependencyKind = DependencyGraphImpl::DependencyKind;
51+
using LoadResult = CoarseGrainedDependencyGraphImpl::LoadResult;
52+
using DependencyKind = CoarseGrainedDependencyGraphImpl::DependencyKind;
5253
using DependencyCallbackTy = LoadResult(StringRef, DependencyKind, bool);
5354
using InterfaceHashCallbackTy = LoadResult(StringRef);
5455

@@ -211,21 +212,23 @@ parseDependencyFile(llvm::MemoryBuffer &buffer,
211212
return result;
212213
}
213214

214-
LoadResult DependencyGraphImpl::loadFromPath(const void *node, StringRef path) {
215+
LoadResult CoarseGrainedDependencyGraphImpl::loadFromPath(const void *node,
216+
StringRef path) {
215217
auto buffer = llvm::MemoryBuffer::getFile(path);
216218
if (!buffer)
217219
return LoadResult::HadError;
218220
return loadFromBuffer(node, *buffer.get());
219221
}
220222

221-
LoadResult
222-
DependencyGraphImpl::loadFromString(const void *node, StringRef data) {
223+
LoadResult CoarseGrainedDependencyGraphImpl::loadFromString(const void *node,
224+
StringRef data) {
223225
auto buffer = llvm::MemoryBuffer::getMemBuffer(data);
224226
return loadFromBuffer(node, *buffer);
225227
}
226228

227-
LoadResult DependencyGraphImpl::loadFromBuffer(const void *node,
228-
llvm::MemoryBuffer &buffer) {
229+
LoadResult
230+
CoarseGrainedDependencyGraphImpl::loadFromBuffer(const void *node,
231+
llvm::MemoryBuffer &buffer) {
229232
auto &provides = Provides[node];
230233

231234
auto dependsCallback = [this, node](StringRef name, DependencyKind kind,
@@ -294,16 +297,16 @@ LoadResult DependencyGraphImpl::loadFromBuffer(const void *node,
294297
interfaceHashCallback);
295298
}
296299

297-
void DependencyGraphImpl::markExternal(SmallVectorImpl<const void *> &visited,
298-
StringRef externalDependency) {
300+
void CoarseGrainedDependencyGraphImpl::markExternal(
301+
SmallVectorImpl<const void *> &visited, StringRef externalDependency) {
299302
forEachUnmarkedJobDirectlyDependentOnExternalSwiftdeps(
300303
externalDependency, [&](const void *node) {
301304
visited.push_back(node);
302305
markTransitive(visited, node);
303306
});
304307
}
305308

306-
void DependencyGraphImpl::
309+
void CoarseGrainedDependencyGraphImpl::
307310
forEachUnmarkedJobDirectlyDependentOnExternalSwiftdeps(
308311
StringRef externalSwiftDeps, function_ref<void(const void *node)> fn) {
309312
auto allDependents = Dependencies.find(externalSwiftDeps);
@@ -319,9 +322,9 @@ void DependencyGraphImpl::
319322
}
320323
}
321324

322-
void
323-
DependencyGraphImpl::markTransitive(SmallVectorImpl<const void *> &visited,
324-
const void *node, MarkTracerImpl *tracer) {
325+
void CoarseGrainedDependencyGraphImpl::markTransitive(
326+
SmallVectorImpl<const void *> &visited, const void *node,
327+
MarkTracerImpl *tracer) {
325328
assert(Provides.count(node) && "node is not in the graph");
326329
llvm::SpecificBumpPtrAllocator<MarkTracerImpl::Entry> scratchAlloc;
327330

@@ -407,7 +410,7 @@ DependencyGraphImpl::markTransitive(SmallVectorImpl<const void *> &visited,
407410
}
408411
}
409412

410-
void DependencyGraphImpl::MarkTracerImpl::countStatsForNodeMarking(
413+
void CoarseGrainedDependencyGraphImpl::MarkTracerImpl::countStatsForNodeMarking(
411414
const OptionSet<DependencyKind> &Kind, bool IsCascading) const {
412415

413416
if (!Stats)
@@ -439,7 +442,7 @@ void DependencyGraphImpl::MarkTracerImpl::countStatsForNodeMarking(
439442
}
440443
}
441444

442-
void DependencyGraphImpl::MarkTracerImpl::printPath(
445+
void CoarseGrainedDependencyGraphImpl::MarkTracerImpl::printPath(
443446
raw_ostream &out,
444447
const void *item,
445448
llvm::function_ref<void (const void *)> printItem) const {

0 commit comments

Comments
 (0)