Skip to content

Commit 49ec947

Browse files
committed
Serialize External Dependencies
Also fix a bug where the some fidelity of external dependency nodes was lost because the base name of the path was used instead of the full file path.
1 parent 41aec37 commit 49ec947

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

Sources/SwiftDriver/IncrementalCompilation/ModuleDependencyGraph.swift

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ extension ModuleDependencyGraph {
280280
case metadata = 1
281281
case moduleDepGraphNode = 2
282282
case identifierNode = 3
283+
case externalDepNode = 5
283284

284285
/// The human-readable name of this record.
285286
///
@@ -292,6 +293,8 @@ extension ModuleDependencyGraph {
292293
return "METADATA"
293294
case .moduleDepGraphNode:
294295
return "MODULE_DEP_GRAPH_NODE"
296+
case .externalDepNode:
297+
return "EXTERNAL_DEP_NODE"
295298
case .identifierNode:
296299
return "IDENTIFIER_NODE"
297300
}
@@ -306,6 +309,7 @@ extension ModuleDependencyGraph {
306309
case malformedFingerprintRecord
307310
case malformedIdentifierRecord
308311
case malformedModuleDepGraphNodeRecord
312+
case malformedExternalDepNodeRecord
309313
case unknownRecord
310314
case unexpectedSubblock
311315
case bogusNameOrContext
@@ -421,6 +425,14 @@ extension ModuleDependencyGraph {
421425
fingerprint: fingerprint,
422426
swiftDeps: swiftDeps)
423427
sequenceNumber += 1
428+
case .externalDepNode:
429+
guard record.fields.count == 1,
430+
record.fields[0] < identifiers.count
431+
else {
432+
throw ReadError.malformedExternalDepNodeRecord
433+
}
434+
let path = identifiers[Int(record.fields[0])]
435+
self.graph.externalDependencies.insert(ExternalDependency(path))
424436
case .identifierNode:
425437
guard record.fields.count == 0,
426438
case .blob(let identifierBlob) = record.payload,
@@ -575,13 +587,22 @@ extension ModuleDependencyGraph {
575587
}
576588
}
577589

590+
for path in graph.externalDependencies {
591+
self.addIdentifier(path.fileName)
592+
}
593+
578594
for str in self.identifiersToWrite {
579595
self.stream.writeRecord(self.abbreviations[.identifierNode]!, {
580596
$0.append(RecordID.identifierNode)
581597
}, blob: str)
582598
}
583599
}
584600

601+
self.abbreviate(.externalDepNode, [
602+
.literal(RecordID.externalDepNode.rawValue),
603+
// path ID
604+
.vbr(chunkBitWidth: 13),
605+
])
585606
private func abbreviate(
586607
_ record: RecordID,
587608
_ operands: [Bitstream.Abbreviation.Operand]
@@ -652,6 +673,13 @@ extension ModuleDependencyGraph {
652673
$0.append((node.fingerprint != nil) ? UInt32(1) : UInt32(0))
653674
}, blob: node.fingerprint ?? "")
654675
}
676+
677+
for dep in graph.externalDependencies {
678+
serializer.stream.writeRecord(serializer.abbreviations[.externalDepNode]!) {
679+
$0.append(RecordID.externalDepNode)
680+
$0.append(serializer.lookupIdentifierCode(for: dep.fileName))
681+
}
682+
}
655683
}
656684
return ByteString(serializer.stream.data)
657685
}
@@ -765,11 +793,11 @@ fileprivate extension DependencyKey.Designator {
765793
case .dynamicLookup(name: let name):
766794
return name
767795
case .externalDepend(let path):
768-
return path.file?.basename
796+
return path.fileName
769797
case .sourceFileProvide(name: let name):
770798
return name
771799
case .incrementalExternalDependency(let path):
772-
return path.file?.basename
800+
return path.fileName
773801
case .member(context: _, name: let name):
774802
return name
775803
case .nominal(context: _):

0 commit comments

Comments
 (0)