@@ -33,6 +33,8 @@ using llvm::BCVBR;
33
33
using llvm::BCBlob;
34
34
using llvm::BCRecordLayout;
35
35
36
+ // / Every .swiftdeps file begins with these 4 bytes, for easy identification when
37
+ // / debugging.
36
38
const unsigned char FINE_GRAINED_DEPDENENCY_FORMAT_SIGNATURE[] = {' D' , ' E' , ' P' , ' S' };
37
39
38
40
const unsigned FINE_GRAINED_DEPENDENCY_FORMAT_VERSION_MAJOR = 1 ;
@@ -47,6 +49,13 @@ using DeclAspectField = BCFixed<1>;
47
49
48
50
const unsigned RECORD_BLOCK_ID = llvm::bitc::FIRST_APPLICATION_BLOCKID;
49
51
52
+ // / The swiftdeps file format consists of a METADATA record, followed by zero or more
53
+ // / IDENTIFIER_NODE records.
54
+ // /
55
+ // / Then, there is one SOURCE_FILE_DEP_GRAPH_NODE for each serialized
56
+ // / SourceFileDepGraphNode. These are followed by FINGERPRINT_NODE and
57
+ // / DEPENDS_ON_DEFINITION_NODE, if the node has a fingerprint and depends-on
58
+ // / definitions, respectively.
50
59
namespace record_block {
51
60
enum {
52
61
METADATA = 1 ,
@@ -56,47 +65,65 @@ namespace record_block {
56
65
IDENTIFIER_NODE,
57
66
};
58
67
68
+ // Always the first record in the file.
59
69
using MetadataLayout = BCRecordLayout<
60
70
METADATA, // ID
61
71
BCFixed<16 >, // Dependency graph format major version
62
72
BCFixed<16 >, // Dependency graph format minor version
63
73
BCBlob // Compiler version string
64
74
>;
65
75
76
+ // After the metadata record, we have zero or more identifier records,
77
+ // for each unique string that is referenced from a SourceFileDepGraphNode.
78
+ //
79
+ // Identifiers are referenced by their sequence number, starting from 1.
80
+ // The identifier value 0 is special; it always represents the empty string.
81
+ // There is no IDENTIFIER_NODE serialized that corresponds to it, instead
82
+ // the first IDENTIFIER_NODE always has a sequence number of 1.
83
+ using IdentifierNodeLayout = BCRecordLayout<
84
+ IDENTIFIER_NODE,
85
+ BCBlob
86
+ >;
87
+
66
88
using SourceFileDepGraphNodeLayout = BCRecordLayout<
67
89
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
90
+ // The next four fields correspond to the fields of the DependencyKey
91
+ // structure.
92
+ NodeKindField, // DependencyKey::kind
93
+ DeclAspectField, // DependencyKey::aspect
94
+ IdentifierIDField, // DependencyKey::context
95
+ IdentifierIDField, // DependencyKey::name
72
96
BCFixed<1 > // Is this a "provides" node?
73
97
>;
74
98
75
- // Optionally follows DEPENDS_ON_DEFINITION_NODE.
99
+ // Follows DEPENDS_ON_DEFINITION_NODE when the SourceFileDepGraphNode has a
100
+ // fingerprint set.
76
101
using FingerprintNodeLayout = BCRecordLayout<
77
102
FINGERPRINT_NODE,
78
103
BCBlob
79
104
>;
80
105
81
- // Optionally follows SOURCE_FILE_DEP_GRAPH_NODE and FINGERPRINT_NODE.
106
+ // Follows SOURCE_FILE_DEP_GRAPH_NODE and FINGERPRINT_NODE when the
107
+ // SourceFileDepGraphNode has one or more depends-on entries.
82
108
using DependsOnDefNodeLayout = BCRecordLayout<
83
109
DEPENDS_ON_DEFINITION_NODE,
84
- BCVBR<16 >
85
- >;
86
-
87
- // Optionally follows all other nodes.
88
- using IdentifierNodeLayout = BCRecordLayout<
89
- IDENTIFIER_NODE,
90
- BCBlob
110
+ BCVBR<16 > // The sequence number (starting from 0) of the referenced
111
+ // SOURCE_FILE_DEP_GRAPH_NODE
91
112
>;
92
113
}
93
114
115
+ // / Tries to read the dependency graph from the given buffer.
116
+ // / Returns true if there was an error.
94
117
bool readFineGrainedDependencyGraph (llvm::MemoryBuffer &buffer,
95
118
SourceFileDepGraph &g);
96
119
120
+ // / Tries to read the dependency graph from the given path name.
121
+ // / Returns true if there was an error.
97
122
bool readFineGrainedDependencyGraph (llvm::StringRef path,
98
123
SourceFileDepGraph &g);
99
124
125
+ // / Tries to write the dependency graph to the given path name.
126
+ // / Returns true if there was an error.
100
127
bool writeFineGrainedDependencyGraph (DiagnosticEngine &diags, llvm::StringRef path,
101
128
const SourceFileDepGraph &g);
102
129
0 commit comments