@@ -446,7 +446,7 @@ namespace driver {
446446
447447 std::vector<const Job*>
448448 reloadAndRemarkDeps (const Job *FinishedCmd, int ReturnCode,
449- const bool forRanges) {
449+ const bool forRanges) {
450450 const CommandOutput &Output = FinishedCmd->getOutput ();
451451 StringRef DependenciesFile =
452452 Output.getAdditionalOutputForType (file_types::TY_SwiftDeps);
@@ -458,7 +458,8 @@ namespace driver {
458458 // coarse dependencies that always affect downstream nodes), but we're
459459 // not using either of those right now, and this logic should probably
460460 // be revisited when we are.
461- assert (FinishedCmd->getCondition () == Job::Condition::Always);
461+ assert (isa<MergeModuleJobAction>(FinishedCmd->getSource ()) ||
462+ FinishedCmd->getCondition () == Job::Condition::Always);
462463 return {};
463464 }
464465 const bool compileExitedNormally =
@@ -907,6 +908,7 @@ namespace driver {
907908 return everyIncrementalJob;
908909 };
909910
911+ const Job *mergeModulesJob = nullptr ;
910912 CommandSet jobsToSchedule;
911913 CommandSet initialCascadingCommands;
912914 for (const Job *cmd : Comp.getJobs ()) {
@@ -915,6 +917,11 @@ namespace driver {
915917 continue ;
916918 }
917919
920+ if (isa<MergeModuleJobAction>(cmd->getSource ())) {
921+ assert (!mergeModulesJob && " multiple scheduled merge-modules jobs?" );
922+ mergeModulesJob = cmd;
923+ }
924+
918925 const Optional<std::pair<bool , bool >> shouldSchedAndIsCascading =
919926 computeShouldInitiallyScheduleJobAndDependendents (cmd, forRanges);
920927 if (!shouldSchedAndIsCascading)
@@ -936,6 +943,15 @@ namespace driver {
936943 collectIncrementalExternallyDependentJobsFromDependencyGraph (
937944 forRanges))
938945 jobsToSchedule.insert (cmd);
946+
947+ // The merge-modules job is special: it *must* be scheduled if any other
948+ // job has been scheduled because any other job can influence the
949+ // structure of the resulting module. Additionally, the initial scheduling
950+ // predicate above is only aware of intra-module changes. External
951+ // dependencies changing *must* cause merge-modules to be scheduled.
952+ if (!jobsToSchedule.empty () && mergeModulesJob) {
953+ jobsToSchedule.insert (mergeModulesJob);
954+ }
939955 return jobsToSchedule;
940956 }
941957
@@ -1031,6 +1047,13 @@ namespace driver {
10311047 // / But returns None if there was a dependency read error.
10321048 Optional<std::pair<Job::Condition, bool >>
10331049 loadDependenciesAndComputeCondition (const Job *const Cmd, bool forRanges) {
1050+ // merge-modules Jobs do not have .swiftdeps files associated with them,
1051+ // however, their compilation condition is computed as a function of their
1052+ // inputs, so their condition can be used as normal.
1053+ if (isa<MergeModuleJobAction>(Cmd->getSource ())) {
1054+ return std::make_pair (Cmd->getCondition (), true );
1055+ }
1056+
10341057 // Try to load the dependencies file for this job. If there isn't one, we
10351058 // always have to run the job, but it doesn't affect any other jobs. If
10361059 // there should be one but it's not present or can't be loaded, we have to
@@ -1163,7 +1186,12 @@ namespace driver {
11631186 continue ;
11641187 }
11651188
1166- // Can we run a cross-module incremental build at all? If not, fallback.
1189+ // Is this module out of date? If not, just keep searching.
1190+ if (Comp.getLastBuildTime () >= depStatus.getLastModificationTime ())
1191+ continue ;
1192+
1193+ // Can we run a cross-module incremental build at all?
1194+ // If not, fall back.
11671195 if (!Comp.getEnableCrossModuleIncrementalBuild ()) {
11681196 fallbackToExternalBehavior (external);
11691197 continue ;
@@ -1609,8 +1637,8 @@ namespace driver {
16091637 CompileJobAction::InputInfo info;
16101638 info.previousModTime = entry.first ->getInputModTime ();
16111639 info.status = entry.second ?
1612- CompileJobAction::InputInfo::NeedsCascadingBuild :
1613- CompileJobAction::InputInfo::NeedsNonCascadingBuild;
1640+ CompileJobAction::InputInfo::Status:: NeedsCascadingBuild :
1641+ CompileJobAction::InputInfo::Status:: NeedsNonCascadingBuild;
16141642 inputs[&inputFile->getInputArg ()] = info;
16151643 }
16161644 }
@@ -1627,7 +1655,7 @@ namespace driver {
16271655
16281656 CompileJobAction::InputInfo info;
16291657 info.previousModTime = entry->getInputModTime ();
1630- info.status = CompileJobAction::InputInfo::UpToDate;
1658+ info.status = CompileJobAction::InputInfo::Status:: UpToDate;
16311659 inputs[&inputFile->getInputArg ()] = info;
16321660 }
16331661 }
0 commit comments