Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Explicit Module Builds][Target Variant] Refactor build planning to allow for a second, separate emit-module task for the target variant #1856

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Sources/SwiftDriver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ add_library(SwiftDriver
Jobs/InterpretJob.swift
Jobs/Job.swift
Jobs/LinkJob.swift
Jobs/MergeModuleJob.swift
Jobs/ModuleWrapJob.swift
Jobs/Planning.swift
Jobs/PrintTargetInfoJob.swift
Expand Down
57 changes: 7 additions & 50 deletions Sources/SwiftDriver/Driver/Driver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -341,38 +341,15 @@ public struct Driver {
/// Original ObjC Header passed from command-line
let originalObjCHeaderFile: VirtualPath.Handle?


/// Enable bridging header chaining.
let bridgingHeaderChaining: Bool

/// The path to the imported Objective-C header.
lazy var importedObjCHeader: VirtualPath.Handle? = {
assert(explicitDependencyBuildPlanner != nil ||
!parsedOptions.hasArgument(.driverExplicitModuleBuild) ||
!inputFiles.contains { $0.type == .swift },
"should not be queried before scanning")
let chainedBridgingHeader = try? explicitDependencyBuildPlanner?.getChainedBridgingHeaderFile()
return try? computeImportedObjCHeader(&parsedOptions, compilerMode: compilerMode,
chainedBridgingHeader: chainedBridgingHeader) ?? originalObjCHeaderFile
}()

/// The directory to emit PCH file.
lazy var bridgingPrecompiledHeaderOutputDir: VirtualPath? = {
return try? computePrecompiledBridgingHeaderDir(&parsedOptions,
compilerMode: compilerMode)
}()

/// The path to the pch for the imported Objective-C header.
lazy var bridgingPrecompiledHeader: VirtualPath.Handle? = {
let contextHash = try? explicitDependencyBuildPlanner?.getMainModuleContextHash()
return computeBridgingPrecompiledHeader(&parsedOptions,
compilerMode: compilerMode,
importedObjCHeader: importedObjCHeader,
outputFileMap: outputFileMap,
outputDirectory: bridgingPrecompiledHeaderOutputDir,
contextHash: contextHash)
}()

/// Path to the dependencies file.
let dependenciesFilePath: VirtualPath.Handle?

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

// FIXME: We should soon be able to remove this from being in the Driver's state.
// Its only remaining use outside of actual dependency build planning is in
// command-line input option generation for the explicit main module compile job.
/// Planner for constructing module build jobs using Explicit Module Builds.
/// Constructed during the planning phase only when all module dependencies will be prebuilt and treated
/// as explicit inputs by the various compilation jobs.
@_spi(Testing) public var explicitDependencyBuildPlanner: ExplicitDependencyBuildPlanner? = nil

/// A reference to the instance of libSwiftScan which is shared with the driver's
/// `InterModuleDependencyOracle`, but also used for non-scanning tasks, such as target info
/// and supported compiler feature queries
Expand Down Expand Up @@ -1357,9 +1326,9 @@ public struct Driver {
}

public mutating func planBuild() throws -> [Job] {
let (jobs, incrementalCompilationState, intermoduleDependencyGraph) = try planPossiblyIncrementalBuild()
let (jobs, incrementalCompilationState, explicitModulePlanner) = try planPossiblyIncrementalBuild()
self.incrementalCompilationState = incrementalCompilationState
self.intermoduleDependencyGraph = intermoduleDependencyGraph
self.intermoduleDependencyGraph = explicitModulePlanner?.dependencyGraph
return jobs
}
}
Expand Down Expand Up @@ -1748,11 +1717,9 @@ extension Diagnostic.Message {
}

extension Driver {
func explainModuleDependency(_ explainModuleName: String, allPaths: Bool) throws {
guard let dependencyPlanner = explicitDependencyBuildPlanner else {
fatalError("Cannot explain dependency without Explicit Build Planner")
}
guard let dependencyPaths = try dependencyPlanner.explainDependency(explainModuleName, allPaths: allPaths) else {
func explainModuleDependency(_ explainModuleName: String, allPaths: Bool,
moduleDependencyGraph: InterModuleDependencyGraph) throws {
guard let dependencyPaths = try moduleDependencyGraph.explainDependency(explainModuleName, allPaths: allPaths) else {
diagnosticEngine.emit(.remark("No such module dependency found: '\(explainModuleName)'"))
return
}
Expand Down Expand Up @@ -1824,13 +1791,6 @@ extension Driver {
return
}

// If we're only supposed to explain a dependency on a given module, do so now.
if let explainModuleName = parsedOptions.getLastArgument(.explainModuleDependencyDetailed) {
try explainModuleDependency(explainModuleName.asSingle, allPaths: true)
} else if let explainModuleNameDetailed = parsedOptions.getLastArgument(.explainModuleDependency) {
try explainModuleDependency(explainModuleNameDetailed.asSingle, allPaths: false)
}

if parsedOptions.contains(.driverPrintOutputFileMap) {
if let outputFileMap = self.outputFileMap {
stderrStream.send(outputFileMap.description)
Expand Down Expand Up @@ -2023,7 +1983,7 @@ extension Driver {

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

var jobInputs = job.primaryInputs.isEmpty ? job.inputs : job.primaryInputs
if let pchPath = bridgingPrecompiledHeader, job.kind == .compile {
jobInputs.append(TypedVirtualPath(file: pchPath, type: .pch))
}
let jobInputs = job.primaryInputs.isEmpty ? job.inputs : job.primaryInputs
// Collect input job IDs.
for input in jobInputs {
if let id = inputIdMap[input] {
Expand Down
Loading