Skip to content

Commit 95c6c6d

Browse files
committed
[Explicit Module Builds][Target Variant] Refactor build planning to allow for a second, separte emit-module task for the target variant
This change allows builds that specify a variant triple and which must emit a target variant module to do so from within a single `swiftc` invocation when using Explicit Module Builds. This is an extensive refactor of the build planning procedure with respect to Explicit Module Builds: - Remove 'ExplicitDependencyBuildPlanner' global state from the 'Driver' instance - Instantiate a 'ExplicitDependencyBuildPlanner' instance at the beginning if build planning and propagate/thread this instance to all the required compilation task creation routines, all the way to 'addCommonFrontendOptions' - For '-target-variant' builds which emit a variant triple module, instantiate a whole separate explicit build planner, including performing a secondary dependency scan using the variant triple. Using this information: - Schedule variant triple module pre-compile dependency tasks - Schedule a variant triple PCH compilation task, if necessary - Schedule the variant emit-module task - Schedule the variant textual module verification task, if necessary
1 parent aa3faa4 commit 95c6c6d

24 files changed

+461
-706
lines changed

Sources/SwiftDriver/Driver/Driver.swift

+7-50
Original file line numberDiff line numberDiff line change
@@ -341,38 +341,15 @@ public struct Driver {
341341
/// Original ObjC Header passed from command-line
342342
let originalObjCHeaderFile: VirtualPath.Handle?
343343

344-
345344
/// Enable bridging header chaining.
346345
let bridgingHeaderChaining: Bool
347346

348-
/// The path to the imported Objective-C header.
349-
lazy var importedObjCHeader: VirtualPath.Handle? = {
350-
assert(explicitDependencyBuildPlanner != nil ||
351-
!parsedOptions.hasArgument(.driverExplicitModuleBuild) ||
352-
!inputFiles.contains { $0.type == .swift },
353-
"should not be queried before scanning")
354-
let chainedBridgingHeader = try? explicitDependencyBuildPlanner?.getChainedBridgingHeaderFile()
355-
return try? computeImportedObjCHeader(&parsedOptions, compilerMode: compilerMode,
356-
chainedBridgingHeader: chainedBridgingHeader) ?? originalObjCHeaderFile
357-
}()
358-
359347
/// The directory to emit PCH file.
360348
lazy var bridgingPrecompiledHeaderOutputDir: VirtualPath? = {
361349
return try? computePrecompiledBridgingHeaderDir(&parsedOptions,
362350
compilerMode: compilerMode)
363351
}()
364352

365-
/// The path to the pch for the imported Objective-C header.
366-
lazy var bridgingPrecompiledHeader: VirtualPath.Handle? = {
367-
let contextHash = try? explicitDependencyBuildPlanner?.getMainModuleContextHash()
368-
return computeBridgingPrecompiledHeader(&parsedOptions,
369-
compilerMode: compilerMode,
370-
importedObjCHeader: importedObjCHeader,
371-
outputFileMap: outputFileMap,
372-
outputDirectory: bridgingPrecompiledHeaderOutputDir,
373-
contextHash: contextHash)
374-
}()
375-
376353
/// Path to the dependencies file.
377354
let dependenciesFilePath: VirtualPath.Handle?
378355

@@ -621,14 +598,6 @@ public struct Driver {
621598
/// The mode the API digester should run in.
622599
let digesterMode: DigesterMode
623600

624-
// FIXME: We should soon be able to remove this from being in the Driver's state.
625-
// Its only remaining use outside of actual dependency build planning is in
626-
// command-line input option generation for the explicit main module compile job.
627-
/// Planner for constructing module build jobs using Explicit Module Builds.
628-
/// Constructed during the planning phase only when all module dependencies will be prebuilt and treated
629-
/// as explicit inputs by the various compilation jobs.
630-
@_spi(Testing) public var explicitDependencyBuildPlanner: ExplicitDependencyBuildPlanner? = nil
631-
632601
/// A reference to the instance of libSwiftScan which is shared with the driver's
633602
/// `InterModuleDependencyOracle`, but also used for non-scanning tasks, such as target info
634603
/// and supported compiler feature queries
@@ -1357,9 +1326,9 @@ public struct Driver {
13571326
}
13581327

13591328
public mutating func planBuild() throws -> [Job] {
1360-
let (jobs, incrementalCompilationState, intermoduleDependencyGraph) = try planPossiblyIncrementalBuild()
1329+
let (jobs, incrementalCompilationState, explicitModulePlanner) = try planPossiblyIncrementalBuild()
13611330
self.incrementalCompilationState = incrementalCompilationState
1362-
self.intermoduleDependencyGraph = intermoduleDependencyGraph
1331+
self.intermoduleDependencyGraph = explicitModulePlanner?.dependencyGraph
13631332
return jobs
13641333
}
13651334
}
@@ -1748,11 +1717,9 @@ extension Diagnostic.Message {
17481717
}
17491718

17501719
extension Driver {
1751-
func explainModuleDependency(_ explainModuleName: String, allPaths: Bool) throws {
1752-
guard let dependencyPlanner = explicitDependencyBuildPlanner else {
1753-
fatalError("Cannot explain dependency without Explicit Build Planner")
1754-
}
1755-
guard let dependencyPaths = try dependencyPlanner.explainDependency(explainModuleName, allPaths: allPaths) else {
1720+
func explainModuleDependency(_ explainModuleName: String, allPaths: Bool,
1721+
moduleDependencyGraph: InterModuleDependencyGraph) throws {
1722+
guard let dependencyPaths = try moduleDependencyGraph.explainDependency(explainModuleName, allPaths: allPaths) else {
17561723
diagnosticEngine.emit(.remark("No such module dependency found: '\(explainModuleName)'"))
17571724
return
17581725
}
@@ -1824,13 +1791,6 @@ extension Driver {
18241791
return
18251792
}
18261793

1827-
// If we're only supposed to explain a dependency on a given module, do so now.
1828-
if let explainModuleName = parsedOptions.getLastArgument(.explainModuleDependencyDetailed) {
1829-
try explainModuleDependency(explainModuleName.asSingle, allPaths: true)
1830-
} else if let explainModuleNameDetailed = parsedOptions.getLastArgument(.explainModuleDependency) {
1831-
try explainModuleDependency(explainModuleNameDetailed.asSingle, allPaths: false)
1832-
}
1833-
18341794
if parsedOptions.contains(.driverPrintOutputFileMap) {
18351795
if let outputFileMap = self.outputFileMap {
18361796
stderrStream.send(outputFileMap.description)
@@ -2023,7 +1983,7 @@ extension Driver {
20231983

20241984
// Put bridging header as first input if we have it
20251985
let allInputs: [TypedVirtualPath]
2026-
if let objcHeader = importedObjCHeader, bridgingPrecompiledHeader != nil {
1986+
if let objcHeader = originalObjCHeaderFile {
20271987
allInputs = [TypedVirtualPath(file: objcHeader, type: .objcHeader)] + inputFiles
20281988
} else {
20291989
allInputs = inputFiles
@@ -2048,10 +2008,7 @@ extension Driver {
20482008
// All input action IDs for this action.
20492009
var inputIds = [UInt]()
20502010

2051-
var jobInputs = job.primaryInputs.isEmpty ? job.inputs : job.primaryInputs
2052-
if let pchPath = bridgingPrecompiledHeader, job.kind == .compile {
2053-
jobInputs.append(TypedVirtualPath(file: pchPath, type: .pch))
2054-
}
2011+
let jobInputs = job.primaryInputs.isEmpty ? job.inputs : job.primaryInputs
20552012
// Collect input job IDs.
20562013
for input in jobInputs {
20572014
if let id = inputIdMap[input] {

0 commit comments

Comments
 (0)