Skip to content

Commit d59a76c

Browse files
committed
Dependencies: New binary format for fine-grained dependency graph
1 parent 6730270 commit d59a76c

8 files changed

+621
-9
lines changed

include/swift/AST/FileSystem.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include "swift/Basic/FileSystem.h"
1717
#include "swift/AST/DiagnosticEngine.h"
18+
#include "swift/AST/DiagnosticsCommon.h"
1819

1920
namespace swift {
2021

include/swift/AST/FineGrainedDependencies.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,11 @@ class DepGraphNode {
632632

633633
const DependencyKey &getKey() const { return key; }
634634

635+
/// Only used when the driver is reading a SourceFileDepGraphNode.
636+
void setKey(const DependencyKey &key) {
637+
this->key = key;
638+
}
639+
635640
const Optional<StringRef> getFingerprint() const {
636641
if (fingerprint) {
637642
return StringRef(fingerprint.getValue());
@@ -872,7 +877,6 @@ class SourceFileDepGraph {
872877

873878
void emitDotFile(StringRef outputPath, DiagnosticEngine &diags);
874879

875-
private:
876880
void addNode(SourceFileDepGraphNode *n) {
877881
n->setSequenceNumber(allNodes.size());
878882
allNodes.push_back(n);
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
//===---- FineGrainedDependencyFormat.h - swiftdeps format ---*- C++ -*-======//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2020 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_FINEGRAINEDDEPENDENCYFORMAT_H
14+
#define SWIFT_AST_FINEGRAINEDDEPENDENCYFORMAT_H
15+
16+
#include "llvm/Bitcode/RecordLayout.h"
17+
#include "llvm/Bitstream/BitCodes.h"
18+
19+
namespace llvm {
20+
class MemoryBuffer;
21+
}
22+
23+
namespace swift {
24+
25+
class DiagnosticEngine;
26+
27+
namespace fine_grained_dependencies {
28+
29+
class SourceFileDepGraph;
30+
31+
using llvm::BCFixed;
32+
using llvm::BCVBR;
33+
using llvm::BCBlob;
34+
using llvm::BCRecordLayout;
35+
36+
const unsigned char FINE_GRAINED_DEPDENENCY_FORMAT_SIGNATURE[] = {'D', 'E', 'P', 'S'};
37+
38+
const unsigned FINE_GRAINED_DEPENDENCY_FORMAT_VERSION_MAJOR = 1;
39+
40+
/// Increment this on every change.
41+
const unsigned FINE_GRAINED_DEPENDENCY_FORMAT_VERSION_MINOR = 0;
42+
43+
using IdentifierIDField = BCVBR<13>;
44+
45+
using NodeKindField = BCFixed<3>;
46+
using DeclAspectField = BCFixed<1>;
47+
48+
const unsigned RECORD_BLOCK_ID = llvm::bitc::FIRST_APPLICATION_BLOCKID;
49+
50+
namespace record_block {
51+
enum {
52+
METADATA = 1,
53+
SOURCE_FILE_DEP_GRAPH_NODE,
54+
FINGERPRINT_NODE,
55+
DEPENDS_ON_DEFINITION_NODE,
56+
IDENTIFIER_NODE,
57+
};
58+
59+
using MetadataLayout = BCRecordLayout<
60+
METADATA, // ID
61+
BCFixed<16>, // Dependency graph format major version
62+
BCFixed<16>, // Dependency graph format minor version
63+
BCBlob // Compiler version string
64+
>;
65+
66+
using SourceFileDepGraphNodeLayout = BCRecordLayout<
67+
SOURCE_FILE_DEP_GRAPH_NODE, // ID
68+
NodeKindField, // Dependency key node kind
69+
DeclAspectField, // Dependency key declaration aspect
70+
IdentifierIDField, // Dependency key mangled context type name
71+
IdentifierIDField, // Dependency key basic name
72+
BCFixed<1> // Is this a "provides" node?
73+
>;
74+
75+
// Optionally follows DEPENDS_ON_DEFINITION_NODE.
76+
using FingerprintNodeLayout = BCRecordLayout<
77+
FINGERPRINT_NODE,
78+
BCBlob
79+
>;
80+
81+
// Optionally follows SOURCE_FILE_DEP_GRAPH_NODE and FINGERPRINT_NODE.
82+
using DependsOnDefNodeLayout = BCRecordLayout<
83+
DEPENDS_ON_DEFINITION_NODE,
84+
BCVBR<16>
85+
>;
86+
87+
// Optionally follows all other nodes.
88+
using IdentifierNodeLayout = BCRecordLayout<
89+
IDENTIFIER_NODE,
90+
BCBlob
91+
>;
92+
}
93+
94+
bool readFineGrainedDependencyGraph(llvm::MemoryBuffer &buffer,
95+
SourceFileDepGraph &g);
96+
97+
bool readFineGrainedDependencyGraph(llvm::StringRef path,
98+
SourceFileDepGraph &g);
99+
100+
bool writeFineGrainedDependencyGraph(DiagnosticEngine &diags, llvm::StringRef path,
101+
const SourceFileDepGraph &g);
102+
103+
} // namespace fine_grained_dependencies
104+
} // namespace swift
105+
106+
#endif

lib/AST/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ add_swift_host_library(swiftAST STATIC
4545
Evaluator.cpp
4646
Expr.cpp
4747
FineGrainedDependencies.cpp
48+
FineGrainedDependencyFormat.cpp
4849
FrontendSourceFileDepGraphFactory.cpp
4950
GenericEnvironment.cpp
5051
GenericSignature.cpp

lib/AST/FineGrainedDependencies.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "swift/AST/DiagnosticsCommon.h"
1818
#include "swift/AST/DiagnosticsFrontend.h"
1919
#include "swift/AST/FileSystem.h"
20+
#include "swift/AST/FineGrainedDependencyFormat.h"
2021
#include "swift/Basic/FileSystem.h"
2122
#include "swift/Basic/LLVM.h"
2223
#include "swift/Demangling/Demangle.h"
@@ -29,6 +30,7 @@
2930
#include "llvm/Support/Path.h"
3031
#include "llvm/Support/YAMLParser.h"
3132

33+
3234
// This file holds the definitions for the fine-grained dependency system
3335
// that are likely to be stable as it moves away from the status quo.
3436
// These include the graph structures common to both programs and also
@@ -50,13 +52,21 @@ Optional<SourceFileDepGraph> SourceFileDepGraph::loadFromPath(StringRef path) {
5052

5153
Optional<SourceFileDepGraph>
5254
SourceFileDepGraph::loadFromBuffer(llvm::MemoryBuffer &buffer) {
53-
SourceFileDepGraph fg;
54-
llvm::yaml::Input yamlReader(llvm::MemoryBufferRef(buffer), nullptr);
55-
yamlReader >> fg;
56-
if (yamlReader.error())
57-
return None;
58-
// return fg; compiles for Mac but not Linux, because it cannot be copied.
59-
return Optional<SourceFileDepGraph>(std::move(fg));
55+
if (false) {
56+
SourceFileDepGraph fg;
57+
llvm::yaml::Input yamlReader(llvm::MemoryBufferRef(buffer), nullptr);
58+
yamlReader >> fg;
59+
if (yamlReader.error())
60+
return None;
61+
// return fg; compiles for Mac but not Linux, because it cannot be copied.
62+
return Optional<SourceFileDepGraph>(std::move(fg));
63+
} else {
64+
SourceFileDepGraph fg;
65+
if (swift::fine_grained_dependencies::readFineGrainedDependencyGraph(
66+
buffer, fg))
67+
return None;
68+
return Optional<SourceFileDepGraph>(std::move(fg));
69+
}
6070
}
6171

6272
//==============================================================================

0 commit comments

Comments
 (0)