Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -348,15 +348,15 @@ extension DependencyKey.Designator: Comparable {}
// MARK: - InvalidationReason
extension ExternalDependency {
/// When explaining incremental decisions, it helps to know why a particular external dependency
/// was investigated.
/// caused invalidation.
public enum InvalidationReason: String, CustomStringConvertible {
/// An `import` of this file was added to the source code.
case added

/// The imported file has changed.
case changed

/// Used when testing invalidation
/// Used when testing
case testing

public var description: String { rawValue }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,13 @@ extension IncrementalCompilationState.FirstWaveComputer {
}
}

let inputsHavingMalformedDependencySources =
sourceFiles.currentInOrder.filter { sourceFile in
!moduleDependencyGraph.containsNodes(forSourceFile: sourceFile)
}
let inputsMissingFromGraph = sourceFiles.currentInOrder.filter { sourceFile in
!moduleDependencyGraph.containsNodes(forSourceFile: sourceFile)
}

if let reporter = reporter {
for input in inputsHavingMalformedDependencySources {
if let reporter = reporter,
moduleDependencyGraph.phase == .buildingFromSwiftDeps {
for input in inputsMissingFromGraph {
reporter.report("Has malformed dependency source; will queue", input)
}
}
Expand All @@ -156,7 +156,7 @@ extension IncrementalCompilationState.FirstWaveComputer {
let definitelyRequiredInputs =
Set(changedInputs.map({ $0.filePath }) +
inputsInvalidatedByExternals +
inputsHavingMalformedDependencySources +
inputsMissingFromGraph +
inputsMissingOutputs)
if let reporter = reporter {
for scheduledInput in sortByCommandLineOrder(definitelyRequiredInputs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ extension IncrementalCompilationState.IncrementalDependencyAndInputSetup {
return readPriorGraphAndCollectInputsInvalidatedByChangedOrAddedExternals()
}
// Every external is added, but don't want to compile an unchanged input that has an import
// so just changed, not changedOrAdded
// so just changed, not changedOrAdded.
return buildInitialGraphFromSwiftDepsAndCollectInputsInvalidatedByChangedExternals()
}

Expand All @@ -230,7 +230,13 @@ extension IncrementalCompilationState.IncrementalDependencyAndInputSetup {
}
guard let graph = graphIfPresent
else {
return buildInitialGraphFromSwiftDepsAndCollectInputsInvalidatedByChangedExternals()
// Do not fall back to `buildInitialGraphFromSwiftDepsAndCollectInputsInvalidatedByChangedExternals`
// because it would be unsound to read a `swiftmodule` file with only a partial set of integrated `swiftdeps`.
// A fingerprint change in such a `swiftmodule` would not be able to propagate and invalidate a use
// in a as-yet-unread swiftdeps file.
//
// Instead, just compile everything. It's OK to be unsound then because every file will be compiled anyway.
return bulidEmptyGraphAndCompileEverything()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more typo.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed!

}
graph.dotFileWriter?.write(graph)

Expand All @@ -257,10 +263,7 @@ extension IncrementalCompilationState.IncrementalDependencyAndInputSetup {
private func buildInitialGraphFromSwiftDepsAndCollectInputsInvalidatedByChangedExternals()
-> (ModuleDependencyGraph, TransitivelyInvalidatedInputSet)?
{
guard let graph = ModuleDependencyGraph(self, .buildingWithoutAPrior)
else {
return nil
}
let graph = ModuleDependencyGraph(self, .buildingFromSwiftDeps)
var inputsInvalidatedByChangedExternals = TransitivelyInvalidatedInputSet()
for input in sourceFiles.currentInOrder {
guard let invalidatedInputs =
Expand All @@ -273,4 +276,10 @@ extension IncrementalCompilationState.IncrementalDependencyAndInputSetup {
reporter?.report("Created dependency graph from swiftdeps files")
return (graph, inputsInvalidatedByChangedExternals)
}

private func bulidEmptyGraphAndCompileEverything()
-> (ModuleDependencyGraph, TransitivelyInvalidatedInputSet) {
let graph = ModuleDependencyGraph(self, .buildingAfterEachCompilation)
return (graph, TransitivelyInvalidatedInputSet())
}
}
Loading