@@ -39,7 +39,7 @@ import SwiftOptions
3939 var skippedCompileGroups = [ TypedVirtualPath: [ Job] ] ( )
4040
4141 /// Accumulates jobs to be run through compilation
42- public var preOrCompileJobs = SynchronizedQueue < Job > ( )
42+ public var preOrCompileJobs = SynchronizedQueue < [ Job ] ? > ( )
4343
4444 /// Jobs to run after the last compile
4545 /// Nonnil means planning has informed me
@@ -116,8 +116,6 @@ import SwiftOptions
116116 self . pendingInputs = Set ( immediatelyCompiledInputs)
117117 self . moduleDependencyGraph = moduleDependencyGraph
118118 self . reportIncrementalDecision = reportIncrementalDecision
119-
120- maybeFinishedWithCompilations ( )
121119 }
122120
123121 /// Check various arguments to rule out incremental compilation if need be.
@@ -370,14 +368,19 @@ extension IncrementalCompilationState {
370368extension IncrementalCompilationState {
371369 /// Decide if a job can be skipped, and register accordingly
372370 func addPreOrCompileJobGroups( _ groups: [ [ Job ] ] ) {
371+ var wereAnyJobsScheduled = false
373372 for group in groups {
374373 if let firstJob = group. first, isSkipped ( firstJob) {
375374 recordSkippedGroup ( group)
376375 }
377376 else {
378377 schedule ( group: group)
378+ wereAnyJobsScheduled = true
379379 }
380380 }
381+ if !wereAnyJobsScheduled {
382+ finishedWithCompilations ( )
383+ }
381384 }
382385
383386 func isSkipped( _ job: Job ) -> Bool {
@@ -409,12 +412,16 @@ extension IncrementalCompilationState {
409412 }
410413
411414 func schedule( group: [ Job ] ) {
412- group . forEach { schedule ( preOrCompileJob : $0 ) }
415+ schedule ( preOrCompileJobs : group )
413416 }
414417 /// Put job in queue for execution
415- func schedule( preOrCompileJob job: Job ) {
416- reportIncrementalDecision ? ( " Queuing \( job. descriptionForLifecycle) " , nil )
417- preOrCompileJobs. append ( job)
418+ func schedule( preOrCompileJobs jobs: [ Job ] ) {
419+ if let report = reportIncrementalDecision {
420+ for job in jobs {
421+ report ( " Queuing \( job. descriptionForLifecycle) " , nil )
422+ }
423+ }
424+ preOrCompileJobs. enqueue ( jobs)
418425 }
419426
420427 /// Remember a job that runs after all compile jobs
@@ -447,7 +454,9 @@ extension IncrementalCompilationState {
447454 }
448455 schedule ( compilationInputs: discoveredInputs)
449456 finishedJob. primaryInputs. forEach { pendingInputs. remove ( $0) }
450- maybeFinishedWithCompilations ( )
457+ if pendingInputs. isEmpty {
458+ finishedWithCompilations ( )
459+ }
451460 }
452461
453462 private func collectInputsDiscovered(
@@ -465,24 +474,22 @@ extension IncrementalCompilationState {
465474 }
466475
467476 private func schedule( compilationInputs inputs: [ TypedVirtualPath ] ) {
468- for input in inputs {
477+ let jobs = inputs. flatMap { input -> [ Job ] in
469478 if let group = skippedCompileGroups. removeValue ( forKey: input) {
470479 skippedCompilationInputs. subtract ( group. first!. primaryInputs)
471480 reportIncrementalDecision ? ( " Scheduling discovered " , input)
472- group . forEach { schedule ( preOrCompileJob : $0 ) }
481+ return group
473482 }
474483 else {
475484 reportIncrementalDecision ? ( " Tried to schedule discovered input again " , input)
485+ return [ ]
476486 }
477487 }
488+ schedule ( preOrCompileJobs: jobs)
478489 }
479490
480- func maybeFinishedWithCompilations( ) {
481- guard pendingInputs. isEmpty
482- else {
483- return
484- }
485- preOrCompileJobs. close ( )
491+ func finishedWithCompilations( ) {
492+ preOrCompileJobs. enqueue ( nil )
486493 }
487494}
488495
0 commit comments