@@ -617,7 +617,7 @@ constructDetailedTaskDescription(const CompilerInvocation &Invocation,
617617 Outputs};
618618}
619619
620- static void emitReferenceDependenciesForAllPrimaryInputsIfNeeded (
620+ static void emitSwiftdepsForAllPrimaryInputsIfNeeded (
621621 CompilerInstance &Instance) {
622622 const auto &Invocation = Instance.getInvocation ();
623623 if (Invocation.getFrontendOptions ()
@@ -627,6 +627,22 @@ static void emitReferenceDependenciesForAllPrimaryInputsIfNeeded(
627627 SourceLoc (), diag::emit_reference_dependencies_without_primary_file);
628628 return ;
629629 }
630+
631+ // Do not write out swiftdeps for any primaries if we've encountered an
632+ // error. Without this, the driver will attempt to integrate swiftdeps
633+ // from broken swift files. One way this could go wrong is if a primary that
634+ // fails to build in an early wave has dependents in a later wave. The
635+ // driver will not schedule those later dependents after this batch exits,
636+ // so they will have no opportunity to bring their swiftdeps files up to
637+ // date. With this early exit, the driver sees the same priors in the
638+ // swiftdeps files from before errors were introduced into the batch, and
639+ // integration therefore always hops from "known good" to "known good" states.
640+ //
641+ // FIXME: It seems more appropriate for the driver to notice the early-exit
642+ // and react by always enqueuing the jobs it dropped in the other waves.
643+ if (Instance.getDiags ().hadAnyError ())
644+ return ;
645+
630646 for (auto *SF : Instance.getPrimarySourceFiles ()) {
631647 const std::string &referenceDependenciesFilePath =
632648 Invocation.getReferenceDependenciesFilePathForPrimary (
@@ -1035,8 +1051,10 @@ static void performEndOfPipelineActions(CompilerInstance &Instance) {
10351051 emitIndexData (Instance);
10361052 }
10371053
1038- // Emit dependencies.
1039- emitReferenceDependenciesForAllPrimaryInputsIfNeeded (Instance);
1054+ // Emit Swiftdeps for every file in the batch.
1055+ emitSwiftdepsForAllPrimaryInputsIfNeeded (Instance);
1056+
1057+ // Emit Make-style dependencies.
10401058 emitMakeDependenciesIfNeeded (Instance.getDiags (),
10411059 Instance.getDependencyTracker (), opts);
10421060
0 commit comments