Skip to content

Commit f63f70b

Browse files
author
David Ungar
committed
Batch and test batching of 1st wave
1 parent d575017 commit f63f70b

File tree

3 files changed

+47
-12
lines changed

3 files changed

+47
-12
lines changed

Sources/SwiftDriver/Incremental Compilation/IncrementalCompilationState.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -369,28 +369,28 @@ extension IncrementalCompilationState {
369369
func addPreOrCompileJobGroups(_ groups: [[Job]],
370370
formBatchedJobs: ([Job]) throws -> [Job]
371371
) throws {
372-
for group in groups {
372+
let mandatoryPreOrCompileJobs = groups.flatMap { group -> [Job] in
373373
if let firstJob = group.first, isSkipped(firstJob) {
374374
recordSkippedGroup(group)
375+
return []
375376
}
376-
else {
377-
try scheduleMandatoryPreOrCompile(group: group)
378-
}
377+
return group
379378
}
379+
let batchedMandatoryPreOrCompileJobs = try formBatchedJobs(mandatoryPreOrCompileJobs)
380+
scheduleMandatoryPreOrCompile(jobs: batchedMandatoryPreOrCompileJobs)
380381
}
381382

382383
/// Remember that `group` (a compilation and possibly bitcode generation)
383384
/// must definitely be executed.
384-
private func scheduleMandatoryPreOrCompile(
385-
group: [Job]) {
385+
private func scheduleMandatoryPreOrCompile(jobs: [Job]) {
386386
if let report = reportIncrementalDecision {
387-
for job in group {
387+
for job in jobs {
388388
report("Queuing \(job.descriptionForLifecycle)", nil)
389389
}
390390
}
391-
mandatoryPreOrCompileJobsInOrder.append(contentsOf: group)
392-
unfinishedMandatoryJobs.formUnion(group)
393-
let mandatoryCompilationInputs = group
391+
mandatoryPreOrCompileJobsInOrder.append(contentsOf: jobs)
392+
unfinishedMandatoryJobs.formUnion(jobs)
393+
let mandatoryCompilationInputs = jobs
394394
.flatMap {$0.kind == .compile ? $0.primaryInputs : []}
395395
pendingInputs.formUnion(mandatoryCompilationInputs)
396396
}

Sources/SwiftDriver/Jobs/Planning.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -599,14 +599,14 @@ extension Driver {
599599
diagnosticEngine
600600
.emit(
601601
.remark(
602-
"Adding {compile: \($0.file.basename)} to batch \(idx)\n"))
602+
"Adding {compile: \($0.file.basename)} to batch \(idx)"))
603603
}
604604

605605
let constituents = primaryInputs.map {$0.file.basename}.joined(separator: ", ")
606606
diagnosticEngine
607607
.emit(
608608
.remark(
609-
"Forming batch job from \(primaryInputs.count) constituents: \(constituents)\n"))
609+
"Forming batch job from \(primaryInputs.count) constituents: \(constituents)"))
610610
}
611611
let constituentsEmittedModuleTrace = !inputsRequiringModuleTrace.intersection(primaryInputs).isEmpty
612612
// no need to add job outputs again

Tests/SwiftDriverTests/IncrementalCompilationTests.swift

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ final class IncrementalCompilationTests: XCTestCase {
368368
#if true // sometimes want to skip for debugging
369369
tryNoChange(checkDiagnostics)
370370
tryTouchingOther(checkDiagnostics)
371+
tryTouchingBoth(checkDiagnostics)
371372
#endif
372373
tryReplacingMain(checkDiagnostics)
373374
}
@@ -417,6 +418,10 @@ final class IncrementalCompilationTests: XCTestCase {
417418
"Incremental compilation: Queuing (initial): {compile: other.o <= other.swift}",
418419
"Incremental compilation: not scheduling dependents of other.swift; unknown changes",
419420
"Incremental compilation: Skipping input: {compile: main.o <= main.swift}",
421+
"Found 1 batchable job",
422+
"Forming into 1 batch",
423+
"Adding {compile: other.swift} to batch 0",
424+
"Forming batch job from 1 constituents: other.swift",
420425
"Incremental compilation: Queuing Compiling other.swift",
421426
"Starting Compiling other.swift",
422427
"Finished Compiling other.swift",
@@ -425,6 +430,32 @@ final class IncrementalCompilationTests: XCTestCase {
425430
],
426431
whenAutolinking: autolinkLifecycleExpectations)
427432
}
433+
func tryTouchingBoth(_ checkDiagnostics: Bool) {
434+
touch("main")
435+
touch("other")
436+
try! doABuild(
437+
"non-propagating, both touched",
438+
checkDiagnostics: checkDiagnostics,
439+
expectingRemarks: [
440+
"Incremental compilation: Scheduing changed input {compile: main.o <= main.swift}",
441+
"Incremental compilation: Scheduing changed input {compile: other.o <= other.swift}",
442+
"Incremental compilation: Queuing (initial): {compile: main.o <= main.swift}",
443+
"Incremental compilation: Queuing (initial): {compile: other.o <= other.swift}",
444+
"Incremental compilation: not scheduling dependents of main.swift; unknown changes",
445+
"Incremental compilation: not scheduling dependents of other.swift; unknown changes",
446+
"Found 2 batchable jobs",
447+
"Forming into 1 batch",
448+
"Adding {compile: main.swift} to batch 0",
449+
"Adding {compile: other.swift} to batch 0",
450+
"Forming batch job from 2 constituents: main.swift, other.swift",
451+
"Incremental compilation: Queuing Compiling main.swift, other.swift",
452+
"Starting Compiling main.swift, other.swift",
453+
"Finished Compiling main.swift, other.swift",
454+
"Starting Linking theModule",
455+
"Finished Linking theModule",
456+
],
457+
whenAutolinking: autolinkLifecycleExpectations)
458+
}
428459

429460
func tryReplacingMain(_ checkDiagnostics: Bool) {
430461
replace(contentsOf: "main", with: "let foo = \"hello\"")
@@ -437,6 +468,10 @@ final class IncrementalCompilationTests: XCTestCase {
437468
"Incremental compilation: Queuing (initial): {compile: main.o <= main.swift}",
438469
"Incremental compilation: not scheduling dependents of main.swift; unknown changes",
439470
"Incremental compilation: Skipping input: {compile: other.o <= other.swift}",
471+
"Found 1 batchable job",
472+
"Forming into 1 batch",
473+
"Adding {compile: main.swift} to batch 0",
474+
"Forming batch job from 1 constituents: main.swift",
440475
"Incremental compilation: Queuing Compiling main.swift",
441476
"Starting Compiling main.swift",
442477
"Incremental compilation: Traced: interface of main.swiftdeps -> interface of top-level name foo -> implementation of other.swiftdeps",

0 commit comments

Comments
 (0)