Skip to content

Commit 332faac

Browse files
committed
Expose a new public property on the driver to retrieve an InterModuleDependencyGraph
1 parent 6715b84 commit 332faac

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,9 @@ public struct Driver {
314314
/// Code & data for incremental compilation. Nil if not running in incremental mode.
315315
/// Set during planning because needs the jobs to look at outputs.
316316
@_spi(Testing) public private(set) var incrementalCompilationState: IncrementalCompilationState? = nil
317+
318+
/// The graph of explicit module dependencies of this module, if the driver has planned an explicit module build.
319+
public private(set) var intermoduleDependencyGraph: InterModuleDependencyGraph? = nil
317320

318321
/// The path of the SDK.
319322
public var absoluteSDKPath: AbsolutePath? {
@@ -1354,8 +1357,9 @@ public struct Driver {
13541357
}
13551358

13561359
public mutating func planBuild() throws -> [Job] {
1357-
let (jobs, incrementalCompilationState) = try planPossiblyIncrementalBuild()
1360+
let (jobs, incrementalCompilationState, intermoduleDependencyGraph) = try planPossiblyIncrementalBuild()
13581361
self.incrementalCompilationState = incrementalCompilationState
1362+
self.intermoduleDependencyGraph = intermoduleDependencyGraph
13591363
return jobs
13601364
}
13611365
}

Sources/SwiftDriver/Jobs/Planning.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ extension Driver {
6161
/// Plan a standard compilation, which produces jobs for compiling separate
6262
/// primary files.
6363
private mutating func planStandardCompile() throws
64-
-> ([Job], IncrementalCompilationState?) {
64+
-> ([Job], IncrementalCompilationState?, InterModuleDependencyGraph?) {
6565
precondition(compilerMode.isStandardCompilationForPlanning,
6666
"compiler mode \(compilerMode) is handled elsewhere")
6767
// Determine the initial state for incremental compilation that is required during
@@ -101,7 +101,7 @@ extension Driver {
101101
jobCreatingPch: jobsInPhases.allJobs.first(where: {$0.kind == .generatePCH}))
102102
}
103103

104-
return (batchedJobs, incrementalCompilationState)
104+
return (batchedJobs, incrementalCompilationState, interModuleDependencyGraph)
105105
}
106106

107107
/// If performing an explicit module build, compute an inter-module dependency graph.
@@ -750,17 +750,17 @@ extension Driver {
750750
/// Plan a build by producing a set of jobs to complete the build.
751751
/// Should be private, but compiler bug
752752
/*private*/ mutating func planPossiblyIncrementalBuild() throws
753-
-> ([Job], IncrementalCompilationState?) {
753+
-> ([Job], IncrementalCompilationState?, InterModuleDependencyGraph?) {
754754

755755
if let job = try immediateForwardingJob() {
756-
return ([job], nil)
756+
return ([job], nil, nil)
757757
}
758758

759759
// The REPL doesn't require input files, but all other modes do.
760760
guard !inputFiles.isEmpty || compilerMode == .repl || compilerMode == .intro else {
761761
if parsedOptions.hasArgument(.v) {
762762
// `swiftc -v` is allowed and prints version information.
763-
return ([], nil)
763+
return ([], nil, nil)
764764
}
765765
throw Error.noInputFiles
766766
}
@@ -771,7 +771,7 @@ extension Driver {
771771
if !inputFiles.isEmpty {
772772
throw PlanningError.replReceivedInput
773773
}
774-
return ([try replJob()], nil)
774+
return ([try replJob()], nil, nil)
775775

776776
case .immediate:
777777
var jobs: [Job] = []
@@ -783,7 +783,7 @@ extension Driver {
783783
initialIncrementalState: nil,
784784
addJob: { jobs.append($0) })
785785
jobs.append(try interpretJob(inputs: inputFiles))
786-
return (jobs, nil)
786+
return (jobs, nil, nil)
787787

788788
case .standardCompile, .batchCompile, .singleCompile:
789789
return try planStandardCompile()
@@ -792,15 +792,15 @@ extension Driver {
792792
if inputFiles.count != 1 {
793793
throw PlanningError.emitPCMWrongInputFiles
794794
}
795-
return ([try generateEmitPCMJob(input: inputFiles.first!)], nil)
795+
return ([try generateEmitPCMJob(input: inputFiles.first!)], nil, nil)
796796

797797
case .dumpPCM:
798798
if inputFiles.count != 1 {
799799
throw PlanningError.dumpPCMWrongInputFiles
800800
}
801-
return ([try generateDumpPCMJob(input: inputFiles.first!)], nil)
801+
return ([try generateDumpPCMJob(input: inputFiles.first!)], nil, nil)
802802
case .intro:
803-
return (try helpIntroJobs(), nil)
803+
return (try helpIntroJobs(), nil, nil)
804804
}
805805
}
806806
}

0 commit comments

Comments
 (0)