Skip to content

Commit e6bbb8d

Browse files
author
David Ungar
authored
Merge pull request swiftlang#29948 from davidungar/unit-test-users-v5a
[Incremental, NFC] Rearrange code creating `SourceFileDepGraph`
2 parents f5b40d6 + 0515e00 commit e6bbb8d

13 files changed

+534
-427
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
//===----- AbstractSourceFileDepGraphFactory.h ----------------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef SWIFT_AST_SOURCE_FILE_DEP_GRAPH_CONSTRUCTOR_H
14+
#define SWIFT_AST_SOURCE_FILE_DEP_GRAPH_CONSTRUCTOR_H
15+
16+
#include "swift/AST/DeclContext.h"
17+
#include "swift/AST/FineGrainedDependencies.h"
18+
19+
namespace swift {
20+
class DiagnosticEngine;
21+
namespace fine_grained_dependencies {
22+
23+
/// Abstract class for building a \c SourceFileDepGraph from either a real
24+
/// \c SourceFile or a unit test
25+
class AbstractSourceFileDepGraphFactory {
26+
protected:
27+
/// To match the existing system, set this to false.
28+
/// To include even private entities and get intra-file info, set to true.
29+
const bool includePrivateDeps;
30+
31+
/// If there was an error, cannot get accurate info.
32+
const bool hadCompilationError;
33+
34+
/// The name of the swiftDeps file.
35+
const std::string swiftDeps;
36+
37+
/// The fingerprint of the whole file
38+
const std::string fileFingerprint;
39+
40+
/// For debugging
41+
const bool emitDotFileAfterConstruction;
42+
43+
DiagnosticEngine &diags;
44+
45+
/// Graph under construction
46+
SourceFileDepGraph g;
47+
48+
public:
49+
/// Expose this layer to enable faking up a constructor for testing.
50+
/// See the instance variable comments for explanation.
51+
AbstractSourceFileDepGraphFactory(bool includePrivateDeps,
52+
bool hadCompilationError,
53+
StringRef swiftDeps,
54+
StringRef fileFingerprint,
55+
bool emitDotFileAfterConstruction,
56+
DiagnosticEngine &diags);
57+
58+
virtual ~AbstractSourceFileDepGraphFactory() = default;
59+
60+
/// Create a SourceFileDepGraph.
61+
SourceFileDepGraph construct();
62+
63+
private:
64+
void addSourceFileNodesToGraph();
65+
66+
/// Add the "provides" nodes when mocking up a graph
67+
virtual void addAllDefinedDecls() = 0;
68+
69+
/// Add the "depends" nodes and arcs when mocking a graph
70+
virtual void addAllUsedDecls() = 0;
71+
72+
protected:
73+
/// Add an pair of interface, implementation nodes to the graph, which
74+
/// represent some \c Decl defined in this source file. \param key the
75+
/// interface key of the pair
76+
void addADefinedDecl(const DependencyKey &key,
77+
Optional<StringRef> fingerprint);
78+
79+
void addAUsedDecl(const DependencyKey &def, const DependencyKey &use);
80+
};
81+
82+
} // namespace fine_grained_dependencies
83+
} // namespace swift
84+
85+
#endif // SWIFT_AST_SOURCE_FILE_DEP_GRAPH_CONSTRUCTOR_H

include/swift/AST/FineGrainedDependencies.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,6 @@ const std::string NodeKindNames[]{
378378
"topLevel", "nominal", "potentialMember", "member",
379379
"dynamicLookup", "externalDepend", "sourceFileProvide"};
380380

381-
382381
/// Instead of the status quo scheme of two kinds of "Depends", cascading and
383382
/// non-cascading this code represents each entity ("Provides" in the status
384383
/// quo), by a pair of nodes. One node represents the "implementation." If the
@@ -398,7 +397,6 @@ template <typename FnT> void forEachAspect(FnT fn) {
398397
fn(DeclAspect(i));
399398
}
400399

401-
402400
/// A pair of nodes that represent the two aspects of a given entity.
403401
/// Templated in order to serve for either SourceFileDepGraphNodes or
404402
/// ModuleDepGraphNodes.
@@ -585,7 +583,6 @@ struct std::hash<typename swift::fine_grained_dependencies::NodeKind> {
585583
}
586584
};
587585

588-
589586
namespace swift {
590587
namespace fine_grained_dependencies {
591588
using ContextNameFingerprint =
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
//===----- FrontendSourceFileDepGraphFactory.h -------------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef FrontendSourceFileDepGraphFactory_h
14+
#define FrontendSourceFileDepGraphFactory_h
15+
16+
#include "swift/AST/AbstractSourceFileDepGraphFactory.h"
17+
namespace swift {
18+
namespace fine_grained_dependencies {
19+
20+
/// Constructs a SourceFileDepGraph from a *real* \c SourceFile
21+
/// Reads the information provided by the frontend and builds the
22+
/// SourceFileDepGraph
23+
24+
class FrontendSourceFileDepGraphFactory
25+
: public AbstractSourceFileDepGraphFactory {
26+
SourceFile *const SF;
27+
const DependencyTracker &depTracker;
28+
29+
public:
30+
FrontendSourceFileDepGraphFactory(SourceFile *SF, StringRef outputPath,
31+
const DependencyTracker &depTracker,
32+
bool alsoEmitDotFile);
33+
34+
~FrontendSourceFileDepGraphFactory() override = default;
35+
36+
private:
37+
static std::string getFingerprint(SourceFile *SF);
38+
39+
static bool computeIncludePrivateDeps(SourceFile *SF);
40+
static std::string getInterfaceHash(SourceFile *SF);
41+
42+
void addAllDefinedDecls() override;
43+
void addAllUsedDecls() override;
44+
45+
/// Given an array of Decls or pairs of them in \p declsOrPairs
46+
/// create node pairs for context and name
47+
template <NodeKind kind, typename ContentsT>
48+
void addAllDefinedDeclsOfAGivenType(std::vector<ContentsT> &contentsVec);
49+
50+
/// At present, only nominals, protocols, and extensions have (body)
51+
/// fingerprints
52+
static Optional<std::string>
53+
getFingerprintIfAny(std::pair<const NominalTypeDecl *, const ValueDecl *>);
54+
static Optional<std::string> getFingerprintIfAny(const Decl *d);
55+
};
56+
57+
} // namespace fine_grained_dependencies
58+
} // namespace swift
59+
60+
#endif /* FrontendSourceFileDepGraphFactory_h */

include/swift/AST/SourceFileDepGraphConstructor.h

Lines changed: 0 additions & 172 deletions
This file was deleted.

0 commit comments

Comments
 (0)