Skip to content

Commit 8594e08

Browse files
committed
[Dependency Scanning] Remove obsolete placeholder module concept
This was used a long time ago for a design of a scanner which could rely on the client to specify that some modules *will be* present at a given location but are not yet during the scan. We have long ago determined that the scanner must have all modules available to it at the time of scan for soundness. This code has been stale for a couple of years and it is time to simplify things a bit by deleting it.
1 parent 662bb37 commit 8594e08

14 files changed

+41
-338
lines changed

Sources/CSwiftScan/include/swiftscan_header.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ typedef struct {
3535
typedef enum {
3636
SWIFTSCAN_DEPENDENCY_INFO_SWIFT_TEXTUAL = 0,
3737
SWIFTSCAN_DEPENDENCY_INFO_SWIFT_BINARY = 1,
38-
SWIFTSCAN_DEPENDENCY_INFO_SWIFT_PLACEHOLDER = 2,
3938
SWIFTSCAN_DEPENDENCY_INFO_CLANG = 3
4039
} swiftscan_dependency_info_kind_t;
4140

@@ -172,14 +171,6 @@ typedef struct {
172171
swiftscan_string_set_t *
173172
(*swiftscan_swift_binary_detail_get_header_dependencies)(swiftscan_module_details_t);
174173

175-
//=== Swift Placeholder Module Details query APIs -------------------------===//
176-
swiftscan_string_ref_t
177-
(*swiftscan_swift_placeholder_detail_get_compiled_module_path)(swiftscan_module_details_t);
178-
swiftscan_string_ref_t
179-
(*swiftscan_swift_placeholder_detail_get_module_doc_path)(swiftscan_module_details_t);
180-
swiftscan_string_ref_t
181-
(*swiftscan_swift_placeholder_detail_get_module_source_info_path)(swiftscan_module_details_t);
182-
183174
//=== Clang Module Details query APIs -------------------------------------===//
184175
swiftscan_string_ref_t
185176
(*swiftscan_clang_detail_get_module_map_path)(swiftscan_module_details_t);

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -638,10 +638,6 @@ public struct Driver {
638638
/// is shared across many targets; otherwise, a new instance is created by the driver itself.
639639
@_spi(Testing) public let interModuleDependencyOracle: InterModuleDependencyOracle
640640

641-
/// A dictionary of external targets that are a part of the same build, mapping to filesystem paths
642-
/// of their module files
643-
@_spi(Testing) public var externalTargetModuleDetailsMap: ExternalTargetModuleDetailsMap? = nil
644-
645641
/// A collection of all the flags the selected toolchain's `swift-frontend` supports
646642
public let supportedFrontendFlags: Set<String>
647643

@@ -768,6 +764,7 @@ public struct Driver {
768764
}
769765

770766
@available(*, deprecated, renamed: "init(args:env:diagnosticsOutput:fileSystem:executor:integratedDriver:compilerExecutableDir:externalTargetModuleDetailsMap:interModuleDependencyOracle:)")
767+
@_disfavoredOverload
771768
public init(
772769
args: [String],
773770
env: [String: String] = ProcessEnv.vars,
@@ -788,12 +785,12 @@ public struct Driver {
788785
integratedDriver: integratedDriver,
789786
compilerIntegratedTooling: false,
790787
compilerExecutableDir: compilerExecutableDir,
791-
externalTargetModuleDetailsMap: externalTargetModuleDetailsMap,
792788
interModuleDependencyOracle: interModuleDependencyOracle
793789
)
794790
}
795791

796792
@available(*, deprecated, renamed: "init(args:env:diagnosticsOutput:fileSystem:executor:integratedDriver:compilerIntegratedTooling:compilerExecutableDir:externalTargetModuleDetailsMap:interModuleDependencyOracle:)")
793+
@_disfavoredOverload
797794
public init(
798795
args: [String],
799796
env: [String: String] = ProcessEnv.vars,
@@ -814,7 +811,33 @@ public struct Driver {
814811
integratedDriver: integratedDriver,
815812
compilerIntegratedTooling: false,
816813
compilerExecutableDir: compilerExecutableDir,
817-
externalTargetModuleDetailsMap: externalTargetModuleDetailsMap,
814+
interModuleDependencyOracle: interModuleDependencyOracle
815+
)
816+
}
817+
818+
@available(*, deprecated, renamed: "init(args:env:diagnosticsOutput:fileSystem:executor:integratedDriver:compilerExecutableDir:interModuleDependencyOracle:)")
819+
@_disfavoredOverload
820+
public init(
821+
args: [String],
822+
env: [String: String] = ProcessEnv.vars,
823+
diagnosticsOutput: DiagnosticsOutput = .engine(DiagnosticsEngine(handlers: [Driver.stderrDiagnosticsHandler])),
824+
fileSystem: FileSystem = localFileSystem,
825+
executor: DriverExecutor,
826+
integratedDriver: Bool = true,
827+
compilerIntegratedTooling: Bool = false,
828+
compilerExecutableDir: AbsolutePath? = nil,
829+
externalTargetModuleDetailsMap: ExternalTargetModuleDetailsMap? = nil,
830+
interModuleDependencyOracle: InterModuleDependencyOracle? = nil
831+
) throws {
832+
try self.init(
833+
args: args,
834+
env: env,
835+
diagnosticsOutput: diagnosticsOutput,
836+
fileSystem: fileSystem,
837+
executor: executor,
838+
integratedDriver: integratedDriver,
839+
compilerIntegratedTooling: false,
840+
compilerExecutableDir: compilerExecutableDir,
818841
interModuleDependencyOracle: interModuleDependencyOracle
819842
)
820843
}
@@ -837,9 +860,6 @@ public struct Driver {
837860
/// Swift compiler image which contains symbols normally queried from a libSwiftScan instance.
838861
/// - Parameter compilerExecutableDir: Directory that contains the compiler executable to be used.
839862
/// Used when in `integratedDriver` mode as a substitute for the driver knowing its executable path.
840-
/// - Parameter externalTargetModuleDetailsMap: A dictionary of external targets that are a part of
841-
/// the same build, mapping to a details value which includes a filesystem path of their
842-
/// `.swiftmodule` and a flag indicating whether the external target is a framework.
843863
/// - Parameter interModuleDependencyOracle: An oracle for querying inter-module dependencies,
844864
/// shared across different module builds by a build system.
845865
public init(
@@ -851,7 +871,6 @@ public struct Driver {
851871
integratedDriver: Bool = true,
852872
compilerIntegratedTooling: Bool = false,
853873
compilerExecutableDir: AbsolutePath? = nil,
854-
externalTargetModuleDetailsMap: ExternalTargetModuleDetailsMap? = nil,
855874
interModuleDependencyOracle: InterModuleDependencyOracle? = nil
856875
) throws {
857876
self.env = env
@@ -869,7 +888,6 @@ public struct Driver {
869888
self.diagnosticEngine = diagnosticsEngine
870889

871890
self.executor = executor
872-
self.externalTargetModuleDetailsMap = externalTargetModuleDetailsMap
873891

874892
if case .subcommand = try Self.invocationRunMode(forArgs: args).mode {
875893
throw Error.subcommandPassedToDriver
@@ -1775,8 +1793,6 @@ extension Driver {
17751793
pathString = pathString + "[" + moduleName + "]"
17761794
case .clang(let moduleName):
17771795
pathString = pathString + "[" + moduleName + "](ObjC)"
1778-
case .swiftPlaceholder(_):
1779-
fatalError("Unexpected unresolved Placeholder module")
17801796
}
17811797
if index < path.count - 1 {
17821798
pathString = pathString + " -> "

Sources/SwiftDriver/ExplicitModuleBuilds/ExplicitDependencyBuildPlanner.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public struct ChainedBridgingHeaderFile {
3333
let content: String
3434
}
3535

36+
// Deprecated
3637
public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalTargetModuleDetails]
3738

3839
/// In Explicit Module Build mode, this planner is responsible for generating and providing
@@ -363,8 +364,6 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
363364
headerDependencies: prebuiltModuleDetails.headerDependencyPaths,
364365
isFramework: isFramework,
365366
moduleCacheKey: prebuiltModuleDetails.moduleCacheKey))
366-
case .swiftPlaceholder:
367-
fatalError("Unresolved placeholder dependencies at planning stage: \(dependencyId) of \(moduleId)")
368367
}
369368
}
370369

Sources/SwiftDriver/ExplicitModuleBuilds/InterModuleDependencies/CommonDependencyOperations.swift

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -13,49 +13,6 @@
1313
import func TSCBasic.topologicalSort
1414
import protocol TSCBasic.FileSystem
1515

16-
@_spi(Testing) public extension InterModuleDependencyGraph {
17-
/// For targets that are built alongside the driver's current module, the scanning action will report them as
18-
/// textual targets to be built from source. Because we can rely on these targets to have been built prior
19-
/// to the driver's current target, we resolve such external targets as prebuilt binary modules, in the graph.
20-
mutating func resolveExternalDependencies(for externalTargetModuleDetailsMap: ExternalTargetModuleDetailsMap)
21-
throws {
22-
for (externalModuleId, externalModuleDetails) in externalTargetModuleDetailsMap {
23-
let externalModulePath = externalModuleDetails.path
24-
// Replace the occurrence of a Swift module to-be-built from source-file
25-
// to an info that describes a pre-built binary module.
26-
let swiftModuleId: ModuleDependencyId = .swift(externalModuleId.moduleName)
27-
let prebuiltModuleId: ModuleDependencyId = .swiftPrebuiltExternal(externalModuleId.moduleName)
28-
if let currentInfo = modules[swiftModuleId],
29-
externalModuleId.moduleName != mainModuleName {
30-
let newExternalModuleDetails =
31-
SwiftPrebuiltExternalModuleDetails(compiledModulePath:
32-
TextualVirtualPath(path: VirtualPath.absolute(externalModulePath).intern()),
33-
isFramework: externalModuleDetails.isFramework)
34-
let newInfo = ModuleInfo(modulePath: TextualVirtualPath(path: VirtualPath.absolute(externalModulePath).intern()),
35-
sourceFiles: [],
36-
directDependencies: currentInfo.directDependencies,
37-
linkLibraries: currentInfo.linkLibraries,
38-
details: .swiftPrebuiltExternal(newExternalModuleDetails))
39-
Self.replaceModule(originalId: swiftModuleId, replacementId: prebuiltModuleId,
40-
replacementInfo: newInfo, in: &modules)
41-
} else if let currentPrebuiltInfo = modules[prebuiltModuleId] {
42-
// Just update the isFramework bit on this prebuilt module dependency
43-
let newExternalModuleDetails =
44-
SwiftPrebuiltExternalModuleDetails(compiledModulePath:
45-
TextualVirtualPath(path: VirtualPath.absolute(externalModulePath).intern()),
46-
isFramework: externalModuleDetails.isFramework)
47-
let newInfo = ModuleInfo(modulePath: TextualVirtualPath(path: VirtualPath.absolute(externalModulePath).intern()),
48-
sourceFiles: [],
49-
directDependencies: currentPrebuiltInfo.directDependencies,
50-
linkLibraries: currentPrebuiltInfo.linkLibraries,
51-
details: .swiftPrebuiltExternal(newExternalModuleDetails))
52-
Self.replaceModule(originalId: prebuiltModuleId, replacementId: prebuiltModuleId,
53-
replacementInfo: newInfo, in: &modules)
54-
}
55-
}
56-
}
57-
}
58-
5916
extension InterModuleDependencyGraph {
6017
var topologicalSorting: [ModuleDependencyId] {
6118
get throws {
@@ -114,10 +71,6 @@ extension InterModuleDependencyGraph {
11471
in moduleInfoMap: inout ModuleInfoMap) {
11572
for moduleId in moduleInfoMap.keys {
11673
var moduleInfo = moduleInfoMap[moduleId]!
117-
// Skip over placeholders, they do not have dependencies
118-
if case .swiftPlaceholder(_) = moduleId {
119-
continue
120-
}
12174
if let originalModuleIndex = moduleInfo.directDependencies?.firstIndex(of: originalId) {
12275
moduleInfo.directDependencies![originalModuleIndex] = replacementId;
12376
moduleInfoMap[moduleId] = moduleInfo
@@ -246,9 +199,6 @@ internal extension InterModuleDependencyGraph {
246199
return try casOutputMissing(clangDetails.moduleCacheKey)
247200
case .swiftPrebuiltExternal(_):
248201
return false;
249-
case .swiftPlaceholder(_):
250-
// TODO: This should never ever happen. Hard error?
251-
return true;
252202
}
253203
}
254204

@@ -340,9 +290,6 @@ internal extension InterModuleDependencyGraph {
340290
}
341291
case .swiftPrebuiltExternal(_):
342292
return true;
343-
case .swiftPlaceholder(_):
344-
// TODO: This should never ever happen. Hard error?
345-
return false;
346293
}
347294

348295
return true

Sources/SwiftDriver/ExplicitModuleBuilds/InterModuleDependencies/InterModuleDependencyGraph.swift

Lines changed: 9 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,12 @@ public typealias ModuleInfoMap = [ModuleDependencyId: ModuleInfo]
1818

1919
public enum ModuleDependencyId: Hashable {
2020
case swift(String)
21-
case swiftPlaceholder(String)
2221
case swiftPrebuiltExternal(String)
2322
case clang(String)
2423

2524
public var moduleName: String {
2625
switch self {
2726
case .swift(let name): return name
28-
case .swiftPlaceholder(let name): return name
2927
case .swiftPrebuiltExternal(let name): return name
3028
case .clang(let name): return name
3129
}
@@ -34,7 +32,6 @@ public enum ModuleDependencyId: Hashable {
3432
internal var moduleNameForDiagnostic: String {
3533
switch self {
3634
case .swift(let name): return name
37-
case .swiftPlaceholder(let name): return name + "(placeholder)"
3835
case .swiftPrebuiltExternal(let name): return name + "(swiftmodule)"
3936
case .clang(let name): return name + "(pcm)"
4037
}
@@ -44,7 +41,6 @@ public enum ModuleDependencyId: Hashable {
4441
extension ModuleDependencyId: Codable {
4542
enum CodingKeys: CodingKey {
4643
case swift
47-
case swiftPlaceholder
4844
case swiftPrebuiltExternal
4945
case clang
5046
}
@@ -56,16 +52,11 @@ extension ModuleDependencyId: Codable {
5652
self = .swift(moduleName)
5753
} catch {
5854
do {
59-
let moduleName = try container.decode(String.self, forKey: .swiftPlaceholder)
60-
self = .swiftPlaceholder(moduleName)
55+
let moduleName = try container.decode(String.self, forKey: .swiftPrebuiltExternal)
56+
self = .swiftPrebuiltExternal(moduleName)
6157
} catch {
62-
do {
63-
let moduleName = try container.decode(String.self, forKey: .swiftPrebuiltExternal)
64-
self = .swiftPrebuiltExternal(moduleName)
65-
} catch {
66-
let moduleName = try container.decode(String.self, forKey: .clang)
67-
self = .clang(moduleName)
68-
}
58+
let moduleName = try container.decode(String.self, forKey: .clang)
59+
self = .clang(moduleName)
6960
}
7061
}
7162
}
@@ -75,8 +66,6 @@ extension ModuleDependencyId: Codable {
7566
switch self {
7667
case .swift(let moduleName):
7768
try container.encode(moduleName, forKey: .swift)
78-
case .swiftPlaceholder(let moduleName):
79-
try container.encode(moduleName, forKey: .swiftPlaceholder)
8069
case .swiftPrebuiltExternal(let moduleName):
8170
try container.encode(moduleName, forKey: .swiftPrebuiltExternal)
8271
case .clang(let moduleName):
@@ -150,15 +139,6 @@ public struct SwiftModuleDetails: Codable, Hashable {
150139
public var chainedBridgingHeaderContent: String?
151140
}
152141

153-
/// Details specific to Swift placeholder dependencies.
154-
public struct SwiftPlaceholderModuleDetails: Codable, Hashable {
155-
/// The path to the .swiftModuleDoc file.
156-
var moduleDocPath: TextualVirtualPath?
157-
158-
/// The path to the .swiftSourceInfo file.
159-
var moduleSourceInfoPath: TextualVirtualPath?
160-
}
161-
162142
/// Details specific to Swift externally-pre-built modules.
163143
public struct SwiftPrebuiltExternalModuleDetails: Codable, Hashable {
164144
/// The path to the already-compiled module that must be used instead of
@@ -224,10 +204,6 @@ public struct ModuleInfo: Codable, Hashable {
224204
/// a bridging header.
225205
case swift(SwiftModuleDetails)
226206

227-
/// Swift placeholder modules carry additional details that specify their
228-
/// module doc path and source info paths.
229-
case swiftPlaceholder(SwiftPlaceholderModuleDetails)
230-
231207
/// Swift externally-prebuilt modules must communicate the path to pre-built binary artifacts
232208
case swiftPrebuiltExternal(SwiftPrebuiltExternalModuleDetails)
233209

@@ -251,7 +227,6 @@ public struct ModuleInfo: Codable, Hashable {
251227
extension ModuleInfo.Details: Codable {
252228
enum CodingKeys: CodingKey {
253229
case swift
254-
case swiftPlaceholder
255230
case swiftPrebuiltExternal
256231
case clang
257232
}
@@ -263,18 +238,12 @@ extension ModuleInfo.Details: Codable {
263238
self = .swift(details)
264239
} catch {
265240
do {
266-
let details = try container.decode(SwiftPlaceholderModuleDetails.self,
267-
forKey: .swiftPlaceholder)
268-
self = .swiftPlaceholder(details)
241+
let details = try container.decode(SwiftPrebuiltExternalModuleDetails.self,
242+
forKey: .swiftPrebuiltExternal)
243+
self = .swiftPrebuiltExternal(details)
269244
} catch {
270-
do {
271-
let details = try container.decode(SwiftPrebuiltExternalModuleDetails.self,
272-
forKey: .swiftPrebuiltExternal)
273-
self = .swiftPrebuiltExternal(details)
274-
} catch {
275-
let details = try container.decode(ClangModuleDetails.self, forKey: .clang)
276-
self = .clang(details)
277-
}
245+
let details = try container.decode(ClangModuleDetails.self, forKey: .clang)
246+
self = .clang(details)
278247
}
279248
}
280249
}
@@ -284,8 +253,6 @@ extension ModuleInfo.Details: Codable {
284253
switch self {
285254
case .swift(let details):
286255
try container.encode(details, forKey: .swift)
287-
case .swiftPlaceholder(let details):
288-
try container.encode(details, forKey: .swiftPlaceholder)
289256
case .swiftPrebuiltExternal(let details):
290257
try container.encode(details, forKey: .swiftPrebuiltExternal)
291258
case .clang(let details):

Sources/SwiftDriver/ExplicitModuleBuilds/InterModuleDependencies/InterModuleDependencyOracle.swift

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,7 @@ import Dispatch
3232
/// An abstraction of a cache and query-engine of inter-module dependencies
3333
public class InterModuleDependencyOracle {
3434
/// Allow external clients to instantiate the oracle
35-
/// - Parameter scannerRequiresPlaceholderModules: Configures this driver's/oracle's scanner invocations to
36-
/// specify external module dependencies to be treated as placeholders. This is required in contexts
37-
/// where the dependency scanning action is invoked for a module which depends on another module
38-
/// that is part of the same build but has not yet been built. Treating it as a placeholder
39-
/// will allow the scanning action to not fail when it fails to detect this dependency on
40-
/// the filesystem. For example, SwiftPM plans all targets belonging to a package before *any* of them
41-
/// are built. So this setting is meant to be used there. In contexts where planning a module
42-
/// necessarily means all of its dependencies have already been built this is not necessary.
43-
public init(scannerRequiresPlaceholderModules: Bool = false) {
44-
self.scannerRequiresPlaceholderModules = scannerRequiresPlaceholderModules
45-
}
35+
public init() {}
4636

4737
@_spi(Testing) public func getDependencies(workingDirectory: AbsolutePath,
4838
moduleAliases: [String: String]? = nil,
@@ -200,8 +190,6 @@ public class InterModuleDependencyOracle {
200190
/// A reference to an instance of the compiler's libSwiftScan shared library
201191
private var swiftScanLibInstance: SwiftScan? = nil
202192

203-
internal let scannerRequiresPlaceholderModules: Bool
204-
205193
internal struct CASConfig: Hashable, Equatable {
206194
static func == (lhs: InterModuleDependencyOracle.CASConfig, rhs: InterModuleDependencyOracle.CASConfig) -> Bool {
207195
return lhs.onDiskPath == rhs.onDiskPath &&

0 commit comments

Comments
 (0)