Skip to content

Commit 582b778

Browse files
author
David Ungar
authored
Merge pull request #345 from davidungar/from-main-10-1
Use the standard SynchronizedQueue instead of my custom one.
2 parents df4b912 + 7b50ef0 commit 582b778

File tree

4 files changed

+24
-82
lines changed

4 files changed

+24
-82
lines changed

Sources/SwiftDriver/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ add_library(SwiftDriver
4444
"Incremental Compilation/ModuleDependencyGraph.swift"
4545
"Incremental Compilation/Multidictionary.swift"
4646
"Incremental Compilation/SourceFileDependencyGraph.swift"
47-
"Incremental Compilation/SynchronizedQueue.swift"
4847
"Incremental Compilation/TwoDMap.swift"
4948

5049
Jobs/AutolinkExtractJob.swift

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ extension Driver {
889889
try execute(jobs: allJobs)
890890
return
891891
}
892-
while let jobs = incrementalCompilationState.preOrCompileJobs.removeAll() {
892+
while let jobs = incrementalCompilationState.preOrCompileJobs.dequeue() {
893893
try execute(jobs: formBatchedJobs(jobs, forIncremental: true))
894894
}
895895
guard let postCompileJobs = incrementalCompilationState.postCompileJobs

Sources/SwiftDriver/Incremental Compilation/IncrementalCompilationState.swift

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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 {
370368
extension 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

Sources/SwiftDriver/Incremental Compilation/SynchronizedQueue.swift

Lines changed: 0 additions & 64 deletions
This file was deleted.

0 commit comments

Comments
 (0)