Skip to content

Commit 80fc8e1

Browse files
authored
Merge pull request #749 from artemcm/GardenCleanup
[Gardening] Delete deprecated API for tracking external target information.
2 parents 63d6636 + 93d2732 commit 80fc8e1

File tree

9 files changed

+71
-498
lines changed

9 files changed

+71
-498
lines changed

Sources/SwiftDriver/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ add_library(SwiftDriver
1010
"ExplicitModuleBuilds/ClangVersionedDependencyResolution.swift"
1111
"ExplicitModuleBuilds/ExplicitDependencyBuildPlanner.swift"
1212
"ExplicitModuleBuilds/ModuleDependencyScanning.swift"
13-
"ExplicitModuleBuilds/PlaceholderDependencyResolution.swift"
1413
"ExplicitModuleBuilds/SerializableModuleArtifacts.swift"
1514
"ExplicitModuleBuilds/InterModuleDependencies/CommonDependencyOperations.swift"
1615
"ExplicitModuleBuilds/InterModuleDependencies/InterModuleDependencyGraph.swift"

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -317,12 +317,9 @@ public struct Driver {
317317
/// is shared across many targets; otherwise, a new instance is created by the driver itself.
318318
@_spi(Testing) public let interModuleDependencyOracle: InterModuleDependencyOracle
319319

320-
// TODO: Once the clients have transitioned to using the InterModuleDependencyOracle API,
321-
// this must convey information about the externally-prebuilt targets only
322-
/// All external artifacts a build system (e.g. SwiftPM) may pass in as input to the explicit
323-
/// build of the current module. Consists of a map of externally-built targets, and a map of all previously
324-
/// discovered/scanned modules and their infos.
325-
@_spi(Testing) public var externalBuildArtifacts: ExternalBuildArtifacts? = nil
320+
/// A dictionary of external targets that are a part of the same build, mapping to filesystem paths
321+
/// of their module files
322+
@_spi(Testing) public var externalTargetModulePathMap: ExternalTargetModulePathMap? = nil
326323

327324
/// A collection of all the flags the selected toolchain's `swift-frontend` supports
328325
public let supportedFrontendFlags: Set<String>
@@ -399,9 +396,14 @@ public struct Driver {
399396
/// expand response files, etc. By default this is the local filesystem.
400397
/// - Parameter executor: Used by the driver to execute jobs. The default argument
401398
/// is present to streamline testing, it shouldn't be used in production.
402-
/// - Parameter externalBuildArtifacts: All external artifacts a build system may pass in as input to the explicit
403-
/// build of the current module. Consists of a map of externally-built targets, and a map of all previously
404-
/// discovered/scanned modules.
399+
/// - Parameter integratedDriver: Used to distinguish whether the driver is being used as
400+
/// an executable or as a library.
401+
/// - Parameter compilerExecutableDir: Directory that contains the compiler executable to be used.
402+
/// Used when in `integratedDriver` mode as a substitute for the driver knowing its executable path.
403+
/// - Parameter externalTargetModulePathMap: A dictionary of external targets that are a part of
404+
/// the same build, mapping to filesystem paths of their module files.
405+
/// - Parameter interModuleDependencyOracle: An oracle for querying inter-module dependencies,
406+
/// shared across different module builds by a build system.
405407
public init(
406408
args: [String],
407409
env: [String: String] = ProcessEnv.vars,
@@ -410,9 +412,6 @@ public struct Driver {
410412
executor: DriverExecutor,
411413
integratedDriver: Bool = true,
412414
compilerExecutableDir: AbsolutePath? = nil,
413-
// FIXME: Duplication with externalBuildArtifacts and externalTargetModulePathMap
414-
// is a temporary backwards-compatibility shim to help transition SwiftPM to the new API
415-
externalBuildArtifacts: ExternalBuildArtifacts? = nil,
416415
externalTargetModulePathMap: ExternalTargetModulePathMap? = nil,
417416
interModuleDependencyOracle: InterModuleDependencyOracle? = nil
418417
) throws {
@@ -423,10 +422,8 @@ public struct Driver {
423422
self.diagnosticEngine = diagnosticsEngine
424423
self.executor = executor
425424

426-
if let externalArtifacts = externalBuildArtifacts {
427-
self.externalBuildArtifacts = externalArtifacts
428-
} else if let externalTargetPaths = externalTargetModulePathMap {
429-
self.externalBuildArtifacts = (externalTargetPaths, [:])
425+
if let externalTargetPaths = externalTargetModulePathMap {
426+
self.externalTargetModulePathMap = externalTargetPaths
430427
}
431428

432429
if case .subcommand = try Self.invocationRunMode(forArgs: args).mode {
@@ -519,14 +516,6 @@ public struct Driver {
519516
self.interModuleDependencyOracle = dependencyOracle
520517
} else {
521518
self.interModuleDependencyOracle = InterModuleDependencyOracle()
522-
523-
// This is a shim for backwards-compatibility with ModuleInfoMap-based API
524-
// used by SwiftPM
525-
if let externalArtifacts = externalBuildArtifacts {
526-
if !externalArtifacts.1.isEmpty {
527-
try self.interModuleDependencyOracle.mergeModules(from: externalArtifacts.1)
528-
}
529-
}
530519
}
531520

532521
self.fileListThreshold = try Self.computeFileListThreshold(&self.parsedOptions, diagnosticsEngine: diagnosticsEngine)

Sources/SwiftDriver/ExplicitModuleBuilds/ExplicitDependencyBuildPlanner.swift

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@ import Foundation
1616
/// A map from a module identifier to a path to its .swiftmodule file.
1717
public typealias ExternalTargetModulePathMap = [ModuleDependencyId: AbsolutePath]
1818

19-
// FIXME: ExternalBuildArtifacts is a temporary backwards-compatibility shim
20-
// to help transition SwiftPM to the new API.
21-
/// A tuple all external artifacts a build system may pass in as input to the explicit build of the current module
22-
/// Consists of a map of externally-built targets, and a map of all previously discovered/scanned modules.
23-
public typealias ExternalBuildArtifacts = (ExternalTargetModulePathMap, ModuleInfoMap)
24-
2519
/// In Explicit Module Build mode, this planner is responsible for generating and providing
2620
/// build jobs for all module dependencies and providing compile command options
2721
/// that specify said explicit module dependencies.
@@ -444,7 +438,7 @@ extension ExplicitDependencyBuildPlanner {
444438

445439
/// Encapsulates some of the common queries of the ExplicitDependencyBuildPlanner with error-checking
446440
/// on the dependency graph's structure.
447-
internal extension InterModuleDependencyGraph {
441+
@_spi(Testing) public extension InterModuleDependencyGraph {
448442
func moduleInfo(of moduleId: ModuleDependencyId) throws -> ModuleInfo {
449443
guard let moduleInfo = modules[moduleId] else {
450444
throw Driver.Error.missingModuleDependency(moduleId.moduleName)

Sources/SwiftDriver/ExplicitModuleBuilds/InterModuleDependencies/CommonDependencyOperations.swift

Lines changed: 7 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@ import TSCBasic
1515
/// For targets that are built alongside the driver's current module, the scanning action will report them as
1616
/// textual targets to be built from source. Because we can rely on these targets to have been built prior
1717
/// to the driver's current target, we resolve such external targets as prebuilt binary modules, in the graph.
18-
mutating func resolveExternalDependencies(for externalBuildArtifacts: ExternalBuildArtifacts)
18+
mutating func resolveExternalDependencies(for externalTargetModulePathMap: ExternalTargetModulePathMap)
1919
throws {
20-
let externalTargetModulePathMap = externalBuildArtifacts.0
21-
22-
for (externalModuleId, externalModulePath) in externalTargetModulePathMap {
20+
for (externalModuleId, externalModulePath) in externalTargetModulePathMap {
2321
// Replace the occurence of a Swift module to-be-built from source-file
2422
// to an info that describes a pre-built binary module.
2523
let swiftModuleId: ModuleDependencyId = .swift(externalModuleId.moduleName)
@@ -30,57 +28,22 @@ import TSCBasic
3028
// a dependency on a target that is not actually used.
3129
continue
3230
}
33-
34-
let newModuleId: ModuleDependencyId = .swiftPrebuiltExternal(externalModuleId.moduleName)
31+
32+
let newModuleId: ModuleDependencyId = .swiftPrebuiltExternal(externalModuleId.moduleName)
3533
let newExternalModuleDetails =
36-
try SwiftPrebuiltExternalModuleDetails(compiledModulePath:
37-
TextualVirtualPath(path: VirtualPath.absolute(externalModulePath).intern()))
34+
try SwiftPrebuiltExternalModuleDetails(compiledModulePath:
35+
TextualVirtualPath(path: VirtualPath.absolute(externalModulePath).intern()))
3836
let newInfo = ModuleInfo(modulePath: TextualVirtualPath(path: VirtualPath.absolute(externalModulePath).intern()),
3937
sourceFiles: [],
4038
directDependencies: currentInfo.directDependencies,
4139
details: .swiftPrebuiltExternal(newExternalModuleDetails))
4240

43-
Self.replaceModule(originalId: swiftModuleId, replacementId: newModuleId,
41+
Self.replaceModule(originalId: swiftModuleId, replacementId: newModuleId,
4442
replacementInfo: newInfo, in: &modules)
4543
}
4644
}
4745
}
4846

49-
@_spi(Testing) public extension InterModuleDependencyOracle {
50-
/// An API to allow clients to accumulate InterModuleDependencyGraphs across mutiple main externalModules/targets
51-
/// into a single collection of discovered externalModules.
52-
func mergeModules(from dependencyGraph: InterModuleDependencyGraph) throws {
53-
try queue.sync {
54-
for (moduleId, moduleInfo) in dependencyGraph.modules {
55-
try InterModuleDependencyGraph.mergeModule(moduleId, moduleInfo, into: &externalModules)
56-
}
57-
}
58-
}
59-
60-
// This is a backwards-compatibility shim to handle existing ModuleInfoMap-based API
61-
// used by SwiftPM
62-
func mergeModules(from moduleInfoMap: ModuleInfoMap) throws {
63-
try queue.sync {
64-
for (moduleId, moduleInfo) in moduleInfoMap {
65-
try InterModuleDependencyGraph.mergeModule(moduleId, moduleInfo, into: &externalModules)
66-
}
67-
}
68-
}
69-
}
70-
71-
public extension InterModuleDependencyGraph {
72-
// This is a shim for backwards-compatibility with existing API used by SwiftPM.
73-
// TODO: After SwiftPM switches to using the oracle, this should be deleted.
74-
static func mergeModules(
75-
from dependencyGraph: InterModuleDependencyGraph,
76-
into discoveredModules: inout ModuleInfoMap
77-
) throws {
78-
for (moduleId, moduleInfo) in dependencyGraph.modules {
79-
try mergeModule(moduleId, moduleInfo, into: &discoveredModules)
80-
}
81-
}
82-
}
83-
8447
extension InterModuleDependencyGraph {
8548
/// Compute a set of modules that are "reachable" (form direct or transitive dependency)
8649
/// from each module in the graph.

Sources/SwiftDriver/ExplicitModuleBuilds/InterModuleDependencies/InterModuleDependencyOracle.swift

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -118,44 +118,5 @@ public class InterModuleDependencyOracle {
118118

119119
/// A reference to an instance of the compiler's libSwiftScan shared library
120120
private var swiftScanLibInstance: SwiftScan? = nil
121-
122-
// The below API is a legacy implementation of the oracle that is in-place to allow clients to
123-
// transition to the new API. It is to be removed once that transition is complete.
124-
/// The complete set of modules discovered so far, spanning potentially multiple targets,
125-
/// accumulated across builds of multiple targets.
126-
/// TODO: This is currently only used for placeholder resolution. libSwiftScan should allow us to move away
127-
/// from the concept of a placeholder module so we should be able to get rid of this in the future.
128-
internal var externalModules: ModuleInfoMap = [:]
129-
/// Query the ModuleInfo of a module with a given ID
130-
@_spi(Testing) public func getExternalModuleInfo(of moduleId: ModuleDependencyId) -> ModuleInfo? {
131-
queue.sync {
132-
return externalModules[moduleId]
133-
}
134-
}
135121
}
136122

137-
// This is a shim for backwards-compatibility with existing API used by SwiftPM.
138-
// TODO: After SwiftPM switches to using the oracle, this should be deleted.
139-
extension Driver {
140-
public var interModuleDependencyGraph: InterModuleDependencyGraph? {
141-
let mainModuleId : ModuleDependencyId = .swift(moduleOutputInfo.name)
142-
var mainModuleDependencyGraph =
143-
InterModuleDependencyGraph(mainModuleName: moduleOutputInfo.name)
144-
145-
addModule(moduleId: mainModuleId,
146-
moduleInfo: interModuleDependencyOracle.getExternalModuleInfo(of: mainModuleId)!,
147-
into: &mainModuleDependencyGraph)
148-
return mainModuleDependencyGraph
149-
}
150-
151-
private func addModule(moduleId: ModuleDependencyId,
152-
moduleInfo: ModuleInfo,
153-
into dependencyGraph: inout InterModuleDependencyGraph) {
154-
dependencyGraph.modules[moduleId] = moduleInfo
155-
moduleInfo.directDependencies?.forEach { dependencyId in
156-
addModule(moduleId: dependencyId,
157-
moduleInfo: interModuleDependencyOracle.getExternalModuleInfo(of: dependencyId)!,
158-
into: &dependencyGraph)
159-
}
160-
}
161-
}

Sources/SwiftDriver/ExplicitModuleBuilds/ModuleDependencyScanning.swift

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -52,48 +52,11 @@ public extension Driver {
5252
moduleDependencyGraphUse: .dependencyScan)
5353
// FIXME: MSVC runtime flags
5454

55-
// Pass in external target dependencies to be treated as placeholder dependencies by the scanner
56-
if let externalBuildArtifacts = externalBuildArtifacts {
57-
let dependencyPlaceholderMapFile =
58-
try serializeExternalDependencyArtifacts(externalBuildArtifacts: externalBuildArtifacts)
59-
commandLine.appendFlag("-placeholder-dependency-module-map-file")
60-
commandLine.appendPath(dependencyPlaceholderMapFile)
61-
}
62-
6355
// Pass on the input files
6456
commandLine.append(contentsOf: inputFiles.map { .path($0.file) })
6557
return (inputs, commandLine)
6658
}
6759

68-
/// Serialize a map of placeholder (external) dependencies for the dependency scanner.
69-
private func serializeExternalDependencyArtifacts(externalBuildArtifacts: ExternalBuildArtifacts)
70-
throws -> VirtualPath {
71-
let (externalTargetModulePathMap, externalModuleInfoMap) = externalBuildArtifacts
72-
var placeholderArtifacts: [SwiftModuleArtifactInfo] = []
73-
74-
// Explicit external targets
75-
for (moduleId, binaryModulePath) in externalTargetModulePathMap {
76-
let modPath = TextualVirtualPath(path: VirtualPath.absolute(binaryModulePath).intern())
77-
placeholderArtifacts.append(
78-
SwiftModuleArtifactInfo(name: moduleId.moduleName,
79-
modulePath: modPath))
80-
}
81-
82-
// All other already-scanned Swift modules
83-
for (moduleId, moduleInfo) in externalModuleInfoMap
84-
where !externalTargetModulePathMap.keys.contains(moduleId) {
85-
guard case .swift(_) = moduleId else { continue }
86-
placeholderArtifacts.append(
87-
SwiftModuleArtifactInfo(name: moduleId.moduleName,
88-
modulePath: moduleInfo.modulePath))
89-
}
90-
let encoder = JSONEncoder()
91-
encoder.outputFormatting = [.prettyPrinted]
92-
let contents = try encoder.encode(placeholderArtifacts)
93-
return VirtualPath.createUniqueTemporaryFileWithKnownContents(.init("\(moduleOutputInfo.name)-placeholder-modules.json"),
94-
contents)
95-
}
96-
9760
/// Returns false if the lib is available and ready to use
9861
private func initSwiftScanLib() throws -> Bool {
9962
// If `-nonlib-dependency-scanner` was specified or the libSwiftScan library cannot be found,

0 commit comments

Comments
 (0)