From f92478423684db432aaf60a84e310be5211cac63 Mon Sep 17 00:00:00 2001 From: Artem Chikin Date: Tue, 3 Jun 2025 17:00:14 -0700 Subject: [PATCH] [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. --- Sources/CSwiftScan/include/swiftscan_header.h | 9 --- Sources/SwiftDriver/Driver/Driver.swift | 42 ++++++---- .../ExplicitDependencyBuildPlanner.swift | 3 +- .../CommonDependencyOperations.swift | 53 ------------- .../InterModuleDependencyGraph.swift | 51 +++--------- .../InterModuleDependencyOracle.swift | 14 +--- .../ModuleDependencyScanning.swift | 39 ---------- Sources/SwiftDriver/Jobs/Planning.swift | 4 +- .../SwiftScan/DependencyGraphBuilder.swift | 18 ----- Sources/SwiftDriver/SwiftScan/SwiftScan.swift | 6 -- .../DOTModuleDependencyGraphSerializer.swift | 4 - .../SwiftDriverTests/CachingBuildTests.swift | 4 - .../ExplicitModuleBuildTests.swift | 54 ------------- .../ExplicitModuleDependencyBuildInputs.swift | 78 ------------------- 14 files changed, 41 insertions(+), 338 deletions(-) diff --git a/Sources/CSwiftScan/include/swiftscan_header.h b/Sources/CSwiftScan/include/swiftscan_header.h index b751978ff..becbab208 100644 --- a/Sources/CSwiftScan/include/swiftscan_header.h +++ b/Sources/CSwiftScan/include/swiftscan_header.h @@ -35,7 +35,6 @@ typedef struct { typedef enum { SWIFTSCAN_DEPENDENCY_INFO_SWIFT_TEXTUAL = 0, SWIFTSCAN_DEPENDENCY_INFO_SWIFT_BINARY = 1, - SWIFTSCAN_DEPENDENCY_INFO_SWIFT_PLACEHOLDER = 2, SWIFTSCAN_DEPENDENCY_INFO_CLANG = 3 } swiftscan_dependency_info_kind_t; @@ -170,14 +169,6 @@ typedef struct { swiftscan_string_set_t * (*swiftscan_swift_binary_detail_get_header_dependencies)(swiftscan_module_details_t); - //=== Swift Placeholder Module Details query APIs -------------------------===// - swiftscan_string_ref_t - (*swiftscan_swift_placeholder_detail_get_compiled_module_path)(swiftscan_module_details_t); - swiftscan_string_ref_t - (*swiftscan_swift_placeholder_detail_get_module_doc_path)(swiftscan_module_details_t); - swiftscan_string_ref_t - (*swiftscan_swift_placeholder_detail_get_module_source_info_path)(swiftscan_module_details_t); - //=== Clang Module Details query APIs -------------------------------------===// swiftscan_string_ref_t (*swiftscan_clang_detail_get_module_map_path)(swiftscan_module_details_t); diff --git a/Sources/SwiftDriver/Driver/Driver.swift b/Sources/SwiftDriver/Driver/Driver.swift index db11ab3cc..f0bd3c5b7 100644 --- a/Sources/SwiftDriver/Driver/Driver.swift +++ b/Sources/SwiftDriver/Driver/Driver.swift @@ -638,10 +638,6 @@ public struct Driver { /// is shared across many targets; otherwise, a new instance is created by the driver itself. @_spi(Testing) public let interModuleDependencyOracle: InterModuleDependencyOracle - /// A dictionary of external targets that are a part of the same build, mapping to filesystem paths - /// of their module files - @_spi(Testing) public var externalTargetModuleDetailsMap: ExternalTargetModuleDetailsMap? = nil - /// A collection of all the flags the selected toolchain's `swift-frontend` supports public let supportedFrontendFlags: Set @@ -768,6 +764,7 @@ public struct Driver { } @available(*, deprecated, renamed: "init(args:env:diagnosticsOutput:fileSystem:executor:integratedDriver:compilerExecutableDir:externalTargetModuleDetailsMap:interModuleDependencyOracle:)") + @_disfavoredOverload public init( args: [String], env: [String: String] = ProcessEnv.vars, @@ -788,12 +785,12 @@ public struct Driver { integratedDriver: integratedDriver, compilerIntegratedTooling: false, compilerExecutableDir: compilerExecutableDir, - externalTargetModuleDetailsMap: externalTargetModuleDetailsMap, interModuleDependencyOracle: interModuleDependencyOracle ) } @available(*, deprecated, renamed: "init(args:env:diagnosticsOutput:fileSystem:executor:integratedDriver:compilerIntegratedTooling:compilerExecutableDir:externalTargetModuleDetailsMap:interModuleDependencyOracle:)") + @_disfavoredOverload public init( args: [String], env: [String: String] = ProcessEnv.vars, @@ -814,7 +811,33 @@ public struct Driver { integratedDriver: integratedDriver, compilerIntegratedTooling: false, compilerExecutableDir: compilerExecutableDir, - externalTargetModuleDetailsMap: externalTargetModuleDetailsMap, + interModuleDependencyOracle: interModuleDependencyOracle + ) + } + + @available(*, deprecated, renamed: "init(args:env:diagnosticsOutput:fileSystem:executor:integratedDriver:compilerExecutableDir:interModuleDependencyOracle:)") + @_disfavoredOverload + public init( + args: [String], + env: [String: String] = ProcessEnv.vars, + diagnosticsOutput: DiagnosticsOutput = .engine(DiagnosticsEngine(handlers: [Driver.stderrDiagnosticsHandler])), + fileSystem: FileSystem = localFileSystem, + executor: DriverExecutor, + integratedDriver: Bool = true, + compilerIntegratedTooling: Bool = false, + compilerExecutableDir: AbsolutePath? = nil, + externalTargetModuleDetailsMap: ExternalTargetModuleDetailsMap? = nil, + interModuleDependencyOracle: InterModuleDependencyOracle? = nil + ) throws { + try self.init( + args: args, + env: env, + diagnosticsOutput: diagnosticsOutput, + fileSystem: fileSystem, + executor: executor, + integratedDriver: integratedDriver, + compilerIntegratedTooling: false, + compilerExecutableDir: compilerExecutableDir, interModuleDependencyOracle: interModuleDependencyOracle ) } @@ -837,9 +860,6 @@ public struct Driver { /// Swift compiler image which contains symbols normally queried from a libSwiftScan instance. /// - Parameter compilerExecutableDir: Directory that contains the compiler executable to be used. /// Used when in `integratedDriver` mode as a substitute for the driver knowing its executable path. - /// - Parameter externalTargetModuleDetailsMap: A dictionary of external targets that are a part of - /// the same build, mapping to a details value which includes a filesystem path of their - /// `.swiftmodule` and a flag indicating whether the external target is a framework. /// - Parameter interModuleDependencyOracle: An oracle for querying inter-module dependencies, /// shared across different module builds by a build system. public init( @@ -851,7 +871,6 @@ public struct Driver { integratedDriver: Bool = true, compilerIntegratedTooling: Bool = false, compilerExecutableDir: AbsolutePath? = nil, - externalTargetModuleDetailsMap: ExternalTargetModuleDetailsMap? = nil, interModuleDependencyOracle: InterModuleDependencyOracle? = nil ) throws { self.env = env @@ -869,7 +888,6 @@ public struct Driver { self.diagnosticEngine = diagnosticsEngine self.executor = executor - self.externalTargetModuleDetailsMap = externalTargetModuleDetailsMap if case .subcommand = try Self.invocationRunMode(forArgs: args).mode { throw Error.subcommandPassedToDriver @@ -1775,8 +1793,6 @@ extension Driver { pathString = pathString + "[" + moduleName + "]" case .clang(let moduleName): pathString = pathString + "[" + moduleName + "](ObjC)" - case .swiftPlaceholder(_): - fatalError("Unexpected unresolved Placeholder module") } if index < path.count - 1 { pathString = pathString + " -> " diff --git a/Sources/SwiftDriver/ExplicitModuleBuilds/ExplicitDependencyBuildPlanner.swift b/Sources/SwiftDriver/ExplicitModuleBuilds/ExplicitDependencyBuildPlanner.swift index 3e3769fe4..9600c7e95 100644 --- a/Sources/SwiftDriver/ExplicitModuleBuilds/ExplicitDependencyBuildPlanner.swift +++ b/Sources/SwiftDriver/ExplicitModuleBuilds/ExplicitDependencyBuildPlanner.swift @@ -33,6 +33,7 @@ public struct ChainedBridgingHeaderFile { let content: String } +// Deprecated public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalTargetModuleDetails] /// In Explicit Module Build mode, this planner is responsible for generating and providing @@ -363,8 +364,6 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT headerDependencies: prebuiltModuleDetails.headerDependencyPaths, isFramework: isFramework, moduleCacheKey: prebuiltModuleDetails.moduleCacheKey)) - case .swiftPlaceholder: - fatalError("Unresolved placeholder dependencies at planning stage: \(dependencyId) of \(moduleId)") } } diff --git a/Sources/SwiftDriver/ExplicitModuleBuilds/InterModuleDependencies/CommonDependencyOperations.swift b/Sources/SwiftDriver/ExplicitModuleBuilds/InterModuleDependencies/CommonDependencyOperations.swift index 9ea3b5e1b..ba1303753 100644 --- a/Sources/SwiftDriver/ExplicitModuleBuilds/InterModuleDependencies/CommonDependencyOperations.swift +++ b/Sources/SwiftDriver/ExplicitModuleBuilds/InterModuleDependencies/CommonDependencyOperations.swift @@ -13,49 +13,6 @@ import func TSCBasic.topologicalSort import protocol TSCBasic.FileSystem -@_spi(Testing) public extension InterModuleDependencyGraph { - /// For targets that are built alongside the driver's current module, the scanning action will report them as - /// textual targets to be built from source. Because we can rely on these targets to have been built prior - /// to the driver's current target, we resolve such external targets as prebuilt binary modules, in the graph. - mutating func resolveExternalDependencies(for externalTargetModuleDetailsMap: ExternalTargetModuleDetailsMap) - throws { - for (externalModuleId, externalModuleDetails) in externalTargetModuleDetailsMap { - let externalModulePath = externalModuleDetails.path - // Replace the occurrence of a Swift module to-be-built from source-file - // to an info that describes a pre-built binary module. - let swiftModuleId: ModuleDependencyId = .swift(externalModuleId.moduleName) - let prebuiltModuleId: ModuleDependencyId = .swiftPrebuiltExternal(externalModuleId.moduleName) - if let currentInfo = modules[swiftModuleId], - externalModuleId.moduleName != mainModuleName { - let newExternalModuleDetails = - SwiftPrebuiltExternalModuleDetails(compiledModulePath: - TextualVirtualPath(path: VirtualPath.absolute(externalModulePath).intern()), - isFramework: externalModuleDetails.isFramework) - let newInfo = ModuleInfo(modulePath: TextualVirtualPath(path: VirtualPath.absolute(externalModulePath).intern()), - sourceFiles: [], - directDependencies: currentInfo.directDependencies, - linkLibraries: currentInfo.linkLibraries, - details: .swiftPrebuiltExternal(newExternalModuleDetails)) - Self.replaceModule(originalId: swiftModuleId, replacementId: prebuiltModuleId, - replacementInfo: newInfo, in: &modules) - } else if let currentPrebuiltInfo = modules[prebuiltModuleId] { - // Just update the isFramework bit on this prebuilt module dependency - let newExternalModuleDetails = - SwiftPrebuiltExternalModuleDetails(compiledModulePath: - TextualVirtualPath(path: VirtualPath.absolute(externalModulePath).intern()), - isFramework: externalModuleDetails.isFramework) - let newInfo = ModuleInfo(modulePath: TextualVirtualPath(path: VirtualPath.absolute(externalModulePath).intern()), - sourceFiles: [], - directDependencies: currentPrebuiltInfo.directDependencies, - linkLibraries: currentPrebuiltInfo.linkLibraries, - details: .swiftPrebuiltExternal(newExternalModuleDetails)) - Self.replaceModule(originalId: prebuiltModuleId, replacementId: prebuiltModuleId, - replacementInfo: newInfo, in: &modules) - } - } - } -} - extension InterModuleDependencyGraph { var topologicalSorting: [ModuleDependencyId] { get throws { @@ -114,10 +71,6 @@ extension InterModuleDependencyGraph { in moduleInfoMap: inout ModuleInfoMap) { for moduleId in moduleInfoMap.keys { var moduleInfo = moduleInfoMap[moduleId]! - // Skip over placeholders, they do not have dependencies - if case .swiftPlaceholder(_) = moduleId { - continue - } if let originalModuleIndex = moduleInfo.directDependencies?.firstIndex(of: originalId) { moduleInfo.directDependencies![originalModuleIndex] = replacementId; moduleInfoMap[moduleId] = moduleInfo @@ -246,9 +199,6 @@ internal extension InterModuleDependencyGraph { return try casOutputMissing(clangDetails.moduleCacheKey) case .swiftPrebuiltExternal(_): return false; - case .swiftPlaceholder(_): - // TODO: This should never ever happen. Hard error? - return true; } } @@ -340,9 +290,6 @@ internal extension InterModuleDependencyGraph { } case .swiftPrebuiltExternal(_): return true; - case .swiftPlaceholder(_): - // TODO: This should never ever happen. Hard error? - return false; } return true diff --git a/Sources/SwiftDriver/ExplicitModuleBuilds/InterModuleDependencies/InterModuleDependencyGraph.swift b/Sources/SwiftDriver/ExplicitModuleBuilds/InterModuleDependencies/InterModuleDependencyGraph.swift index 85b9b04c2..5e816d405 100644 --- a/Sources/SwiftDriver/ExplicitModuleBuilds/InterModuleDependencies/InterModuleDependencyGraph.swift +++ b/Sources/SwiftDriver/ExplicitModuleBuilds/InterModuleDependencies/InterModuleDependencyGraph.swift @@ -18,14 +18,12 @@ public typealias ModuleInfoMap = [ModuleDependencyId: ModuleInfo] public enum ModuleDependencyId: Hashable { case swift(String) - case swiftPlaceholder(String) case swiftPrebuiltExternal(String) case clang(String) public var moduleName: String { switch self { case .swift(let name): return name - case .swiftPlaceholder(let name): return name case .swiftPrebuiltExternal(let name): return name case .clang(let name): return name } @@ -34,7 +32,6 @@ public enum ModuleDependencyId: Hashable { internal var moduleNameForDiagnostic: String { switch self { case .swift(let name): return name - case .swiftPlaceholder(let name): return name + "(placeholder)" case .swiftPrebuiltExternal(let name): return name + "(swiftmodule)" case .clang(let name): return name + "(pcm)" } @@ -44,7 +41,6 @@ public enum ModuleDependencyId: Hashable { extension ModuleDependencyId: Codable { enum CodingKeys: CodingKey { case swift - case swiftPlaceholder case swiftPrebuiltExternal case clang } @@ -56,16 +52,11 @@ extension ModuleDependencyId: Codable { self = .swift(moduleName) } catch { do { - let moduleName = try container.decode(String.self, forKey: .swiftPlaceholder) - self = .swiftPlaceholder(moduleName) + let moduleName = try container.decode(String.self, forKey: .swiftPrebuiltExternal) + self = .swiftPrebuiltExternal(moduleName) } catch { - do { - let moduleName = try container.decode(String.self, forKey: .swiftPrebuiltExternal) - self = .swiftPrebuiltExternal(moduleName) - } catch { - let moduleName = try container.decode(String.self, forKey: .clang) - self = .clang(moduleName) - } + let moduleName = try container.decode(String.self, forKey: .clang) + self = .clang(moduleName) } } } @@ -75,8 +66,6 @@ extension ModuleDependencyId: Codable { switch self { case .swift(let moduleName): try container.encode(moduleName, forKey: .swift) - case .swiftPlaceholder(let moduleName): - try container.encode(moduleName, forKey: .swiftPlaceholder) case .swiftPrebuiltExternal(let moduleName): try container.encode(moduleName, forKey: .swiftPrebuiltExternal) case .clang(let moduleName): @@ -147,15 +136,6 @@ public struct SwiftModuleDetails: Codable, Hashable { public var chainedBridgingHeaderContent: String? } -/// Details specific to Swift placeholder dependencies. -public struct SwiftPlaceholderModuleDetails: Codable, Hashable { - /// The path to the .swiftModuleDoc file. - var moduleDocPath: TextualVirtualPath? - - /// The path to the .swiftSourceInfo file. - var moduleSourceInfoPath: TextualVirtualPath? -} - /// Details specific to Swift externally-pre-built modules. public struct SwiftPrebuiltExternalModuleDetails: Codable, Hashable { /// The path to the already-compiled module that must be used instead of @@ -221,10 +201,6 @@ public struct ModuleInfo: Codable, Hashable { /// a bridging header. case swift(SwiftModuleDetails) - /// Swift placeholder modules carry additional details that specify their - /// module doc path and source info paths. - case swiftPlaceholder(SwiftPlaceholderModuleDetails) - /// Swift externally-prebuilt modules must communicate the path to pre-built binary artifacts case swiftPrebuiltExternal(SwiftPrebuiltExternalModuleDetails) @@ -248,7 +224,6 @@ public struct ModuleInfo: Codable, Hashable { extension ModuleInfo.Details: Codable { enum CodingKeys: CodingKey { case swift - case swiftPlaceholder case swiftPrebuiltExternal case clang } @@ -260,18 +235,12 @@ extension ModuleInfo.Details: Codable { self = .swift(details) } catch { do { - let details = try container.decode(SwiftPlaceholderModuleDetails.self, - forKey: .swiftPlaceholder) - self = .swiftPlaceholder(details) + let details = try container.decode(SwiftPrebuiltExternalModuleDetails.self, + forKey: .swiftPrebuiltExternal) + self = .swiftPrebuiltExternal(details) } catch { - do { - let details = try container.decode(SwiftPrebuiltExternalModuleDetails.self, - forKey: .swiftPrebuiltExternal) - self = .swiftPrebuiltExternal(details) - } catch { - let details = try container.decode(ClangModuleDetails.self, forKey: .clang) - self = .clang(details) - } + let details = try container.decode(ClangModuleDetails.self, forKey: .clang) + self = .clang(details) } } } @@ -281,8 +250,6 @@ extension ModuleInfo.Details: Codable { switch self { case .swift(let details): try container.encode(details, forKey: .swift) - case .swiftPlaceholder(let details): - try container.encode(details, forKey: .swiftPlaceholder) case .swiftPrebuiltExternal(let details): try container.encode(details, forKey: .swiftPrebuiltExternal) case .clang(let details): diff --git a/Sources/SwiftDriver/ExplicitModuleBuilds/InterModuleDependencies/InterModuleDependencyOracle.swift b/Sources/SwiftDriver/ExplicitModuleBuilds/InterModuleDependencies/InterModuleDependencyOracle.swift index c5463de10..9e930f154 100644 --- a/Sources/SwiftDriver/ExplicitModuleBuilds/InterModuleDependencies/InterModuleDependencyOracle.swift +++ b/Sources/SwiftDriver/ExplicitModuleBuilds/InterModuleDependencies/InterModuleDependencyOracle.swift @@ -32,17 +32,7 @@ import Dispatch /// An abstraction of a cache and query-engine of inter-module dependencies public class InterModuleDependencyOracle { /// Allow external clients to instantiate the oracle - /// - Parameter scannerRequiresPlaceholderModules: Configures this driver's/oracle's scanner invocations to - /// specify external module dependencies to be treated as placeholders. This is required in contexts - /// where the dependency scanning action is invoked for a module which depends on another module - /// that is part of the same build but has not yet been built. Treating it as a placeholder - /// will allow the scanning action to not fail when it fails to detect this dependency on - /// the filesystem. For example, SwiftPM plans all targets belonging to a package before *any* of them - /// are built. So this setting is meant to be used there. In contexts where planning a module - /// necessarily means all of its dependencies have already been built this is not necessary. - public init(scannerRequiresPlaceholderModules: Bool = false) { - self.scannerRequiresPlaceholderModules = scannerRequiresPlaceholderModules - } + public init() {} @_spi(Testing) public func getDependencies(workingDirectory: AbsolutePath, moduleAliases: [String: String]? = nil, @@ -193,8 +183,6 @@ public class InterModuleDependencyOracle { /// A reference to an instance of the compiler's libSwiftScan shared library private var swiftScanLibInstance: SwiftScan? = nil - internal let scannerRequiresPlaceholderModules: Bool - internal struct CASConfig: Hashable, Equatable { static func == (lhs: InterModuleDependencyOracle.CASConfig, rhs: InterModuleDependencyOracle.CASConfig) -> Bool { return lhs.onDiskPath == rhs.onDiskPath && diff --git a/Sources/SwiftDriver/ExplicitModuleBuilds/ModuleDependencyScanning.swift b/Sources/SwiftDriver/ExplicitModuleBuilds/ModuleDependencyScanning.swift index d6f488f62..f1700b76a 100644 --- a/Sources/SwiftDriver/ExplicitModuleBuilds/ModuleDependencyScanning.swift +++ b/Sources/SwiftDriver/ExplicitModuleBuilds/ModuleDependencyScanning.swift @@ -59,18 +59,6 @@ extension Diagnostic.Message { stdoutStream.flush() } - if let externalTargetDetails = externalTargetModuleDetailsMap { - // Resolve external dependencies in the dependency graph, if any. - try dependencyGraph.resolveExternalDependencies(for: externalTargetDetails) - } - - // Re-scan Clang modules at all the targets they will be built against. - // This is currently disabled because we are investigating it being unnecessary - // try resolveVersionedClangDependencies(dependencyGraph: &dependencyGraph) - - // Set dependency modules' paths to be saved in the module cache. - // try resolveDependencyModulePaths(dependencyGraph: &dependencyGraph) - if parsedOptions.hasArgument(.printExplicitDependencyGraph) { let outputFormat = parsedOptions.getLastArgument(.explicitDependencyGraphFormat)?.asSingle if outputFormat == nil || outputFormat == "json" { @@ -117,15 +105,6 @@ public extension Driver { moduleDependencyGraphUse: .dependencyScan) try addRuntimeLibraryFlags(commandLine: &commandLine) - // Pass in external target dependencies to be treated as placeholder dependencies by the scanner - if let externalTargetDetailsMap = externalTargetModuleDetailsMap, - interModuleDependencyOracle.scannerRequiresPlaceholderModules { - let dependencyPlaceholderMapFile = - try serializeExternalDependencyArtifacts(externalTargetDependencyDetails: externalTargetDetailsMap) - commandLine.appendFlag("-placeholder-dependency-module-map-file") - commandLine.appendPath(dependencyPlaceholderMapFile) - } - if isFrontendArgSupported(.clangScannerModuleCachePath) { try commandLine.appendLast(.clangScannerModuleCachePath, from: &parsedOptions) } @@ -204,24 +183,6 @@ public extension Driver { return (inputs, commandLine) } - /// Serialize a map of placeholder (external) dependencies for the dependency scanner. - private func serializeExternalDependencyArtifacts(externalTargetDependencyDetails: ExternalTargetModuleDetailsMap) - throws -> VirtualPath { - var placeholderArtifacts: [SwiftModuleArtifactInfo] = [] - // Explicit external targets - for (moduleId, dependencyDetails) in externalTargetDependencyDetails { - let modPath = TextualVirtualPath(path: VirtualPath.absolute(dependencyDetails.path).intern()) - placeholderArtifacts.append( - SwiftModuleArtifactInfo(name: moduleId.moduleName, - modulePath: modPath)) - } - let encoder = JSONEncoder() - encoder.outputFormatting = [.prettyPrinted] - let contents = try encoder.encode(placeholderArtifacts) - return try VirtualPath.createUniqueTemporaryFileWithKnownContents(.init(validating: "\(moduleOutputInfo.name)-external-modules.json"), - contents) - } - static func sanitizeCommandForLibScanInvocation(_ command: inout [String]) { // Remove the tool executable to only leave the arguments. When passing the // command line into libSwiftScan, the library is itself the tool and only diff --git a/Sources/SwiftDriver/Jobs/Planning.swift b/Sources/SwiftDriver/Jobs/Planning.swift index d224cb54e..6d7bb65c1 100644 --- a/Sources/SwiftDriver/Jobs/Planning.swift +++ b/Sources/SwiftDriver/Jobs/Planning.swift @@ -674,10 +674,8 @@ extension Driver { } } - /// Prescan the source files to produce a module dependency graph and turn it into a set + /// Scan the source files to produce a module dependency graph and turn it into a set /// of jobs required to build all dependencies. - /// Preprocess the graph by resolving placeholder dependencies, if any are present and - /// by re-scanning all Clang modules against all possible targets they will be built against. public mutating func generateExplicitModuleDependenciesJobs(dependencyGraph: InterModuleDependencyGraph) throws -> [Job] { // Plan build jobs for all direct and transitive module dependencies of the current target diff --git a/Sources/SwiftDriver/SwiftScan/DependencyGraphBuilder.swift b/Sources/SwiftDriver/SwiftScan/DependencyGraphBuilder.swift index 4e2cb06c2..f383ca9ab 100644 --- a/Sources/SwiftDriver/SwiftScan/DependencyGraphBuilder.swift +++ b/Sources/SwiftDriver/SwiftScan/DependencyGraphBuilder.swift @@ -135,8 +135,6 @@ private extension SwiftScan { moduleAliases: moduleAliases)) case SWIFTSCAN_DEPENDENCY_INFO_SWIFT_BINARY: return .swiftPrebuiltExternal(try constructSwiftBinaryModuleDetails(from: moduleDetailsRef)) - case SWIFTSCAN_DEPENDENCY_INFO_SWIFT_PLACEHOLDER: - return .swiftPlaceholder(try constructPlaceholderModuleDetails(from: moduleDetailsRef)) case SWIFTSCAN_DEPENDENCY_INFO_CLANG: return .clang(try constructClangModuleDetails(from: moduleDetailsRef)) default: @@ -263,19 +261,6 @@ private extension SwiftScan { moduleCacheKey: moduleCacheKey) } - /// Construct a `SwiftPlaceholderModuleDetails` from a `swiftscan_module_details_t` reference - func constructPlaceholderModuleDetails(from moduleDetailsRef: swiftscan_module_details_t) - throws -> SwiftPlaceholderModuleDetails { - let moduleDocPath = - try getOptionalPathDetail(from: moduleDetailsRef, - using: api.swiftscan_swift_placeholder_detail_get_module_doc_path) - let moduleSourceInfoPath = - try getOptionalPathDetail(from: moduleDetailsRef, - using: api.swiftscan_swift_placeholder_detail_get_module_source_info_path) - return SwiftPlaceholderModuleDetails(moduleDocPath: moduleDocPath, - moduleSourceInfoPath: moduleSourceInfoPath) - } - /// Construct a `ClangModuleDetails` from a `swiftscan_module_details_t` reference func constructClangModuleDetails(from moduleDetailsRef: swiftscan_module_details_t) throws -> ClangModuleDetails { @@ -426,7 +411,6 @@ private extension SwiftScan { /// where `module-kind` is one of: /// "swiftTextual" /// "swiftBinary" - /// "swiftPlaceholder" /// "clang"" func decodeModuleNameAndKind(from encodedName: String, moduleAliases: [String: String]?) throws -> ModuleDependencyId { @@ -443,8 +427,6 @@ private extension SwiftScan { namePart = realName } return .swiftPrebuiltExternal(namePart) - case _ where encodedName.starts(with: "swiftPlaceholder:"): - return .swiftPlaceholder(String(encodedName.suffix(encodedName.count - "swiftPlaceholder:".count))) case _ where encodedName.starts(with: "clang:"): return .clang(String(encodedName.suffix(encodedName.count - "clang:".count))) default: diff --git a/Sources/SwiftDriver/SwiftScan/SwiftScan.swift b/Sources/SwiftDriver/SwiftScan/SwiftScan.swift index ed878f944..1d7b2b668 100644 --- a/Sources/SwiftDriver/SwiftScan/SwiftScan.swift +++ b/Sources/SwiftDriver/SwiftScan/SwiftScan.swift @@ -613,12 +613,6 @@ private extension swiftscan_functions_t { try loadRequired("swiftscan_clang_detail_get_context_hash") self.swiftscan_clang_detail_get_module_map_path = try loadRequired("swiftscan_clang_detail_get_module_map_path") - self.swiftscan_swift_placeholder_detail_get_module_source_info_path = - try loadRequired("swiftscan_swift_placeholder_detail_get_module_source_info_path") - self.swiftscan_swift_placeholder_detail_get_module_doc_path = - try loadRequired("swiftscan_swift_placeholder_detail_get_module_doc_path") - self.swiftscan_swift_placeholder_detail_get_compiled_module_path = - try loadRequired("swiftscan_swift_placeholder_detail_get_compiled_module_path") self.swiftscan_swift_binary_detail_get_module_source_info_path = try loadRequired("swiftscan_swift_binary_detail_get_module_source_info_path") self.swiftscan_swift_binary_detail_get_module_doc_path = diff --git a/Sources/SwiftDriver/Utilities/DOTModuleDependencyGraphSerializer.swift b/Sources/SwiftDriver/Utilities/DOTModuleDependencyGraphSerializer.swift index ba89b1689..823e49926 100644 --- a/Sources/SwiftDriver/Utilities/DOTModuleDependencyGraphSerializer.swift +++ b/Sources/SwiftDriver/Utilities/DOTModuleDependencyGraphSerializer.swift @@ -24,8 +24,6 @@ import TSCBasic switch moduleId { case .swift(let string): label = "\(string)" - case .swiftPlaceholder(let string): - label = "\(string) (Placeholder)" case .swiftPrebuiltExternal(let string): label = "\(string) (Prebuilt)" case .clang(let string): @@ -49,8 +47,6 @@ import TSCBasic switch moduleId { case .swift(_): output = " \(nodeName) [style=bold, color=orange, style=filled, \(font)];\n" - case .swiftPlaceholder(_): - output = " \(nodeName) [style=bold, color=gold, style=filled, \(font)];\n" case .swiftPrebuiltExternal(_): output = " \(nodeName) [style=bold, color=darkorange3, style=filled, \(font)];\n" case .clang(_): diff --git a/Tests/SwiftDriverTests/CachingBuildTests.swift b/Tests/SwiftDriverTests/CachingBuildTests.swift index 189cf781c..2656e38d5 100644 --- a/Tests/SwiftDriverTests/CachingBuildTests.swift +++ b/Tests/SwiftDriverTests/CachingBuildTests.swift @@ -61,8 +61,6 @@ throws { XCTAssertEqual(job.description, "Compiling Clang module \(moduleId.moduleName)") case .swiftPrebuiltExternal(_): XCTFail("Unexpected prebuilt external module dependency found.") - case .swiftPlaceholder(_): - XCTFail("Placeholder dependency found.") } // Ensure the frontend was prohibited from doing implicit module builds XCTAssertTrue(job.commandLine.contains(.flag(String("-fno-implicit-modules")))) @@ -181,8 +179,6 @@ private func checkCachingBuildJobDependencies(job: Job, try validateBinaryCommandLineDependency(dependencyId, swiftDependencyDetails) case .clang(let clangDependencyDetails): try validateClangCommandLineDependency(dependencyId, dependencyInfo, clangDependencyDetails) - case .swiftPlaceholder(_): - XCTFail("Placeholder dependency found.") } // Ensure all transitive dependencies got added as well. diff --git a/Tests/SwiftDriverTests/ExplicitModuleBuildTests.swift b/Tests/SwiftDriverTests/ExplicitModuleBuildTests.swift index 4d420fc59..e9f1d824d 100644 --- a/Tests/SwiftDriverTests/ExplicitModuleBuildTests.swift +++ b/Tests/SwiftDriverTests/ExplicitModuleBuildTests.swift @@ -56,8 +56,6 @@ throws { XCTAssertEqual(job.description, "Compiling Clang module \(moduleId.moduleName)") case .swiftPrebuiltExternal(_): XCTFail("Unexpected prebuilt external module dependency found.") - case .swiftPlaceholder(_): - XCTFail("Placeholder dependency found.") } // Ensure the frontend was prohibited from doing implicit module builds XCTAssertJobInvocationMatches(job, .flag("-fno-implicit-modules")) @@ -97,8 +95,6 @@ private func checkExplicitModuleBuildJobDependencies(job: Job, validateSwiftCommandLineDependency(dependencyId, dependencyInfo) case .clang(let clangDependencyDetails): validateClangCommandLineDependency(dependencyId, dependencyInfo, clangDependencyDetails) - case .swiftPlaceholder(_): - XCTFail("Placeholder dependency found.") } // Ensure all transitive dependencies got added as well. @@ -219,56 +215,6 @@ final class ExplicitModuleBuildTests: XCTestCase { } } - func testModuleDependencyBuildCommandGenerationWithExternalFramework() throws { - do { - let externalDetails: ExternalTargetModuleDetailsMap = - [.swiftPrebuiltExternal("A"): ExternalTargetModuleDetails(path: try AbsolutePath(validating: "/tmp/A.swiftmodule"), - isFramework: true), - .swiftPrebuiltExternal("K"): ExternalTargetModuleDetails(path: try AbsolutePath(validating: "/tmp/K.swiftmodule"), - isFramework: true), - .swiftPrebuiltExternal("simpleTestModule"): ExternalTargetModuleDetails(path: try AbsolutePath(validating: "/tmp/simpleTestModule.swiftmodule"), - isFramework: true)] - var driver = try Driver(args: ["swiftc", "-explicit-module-build", - "-module-name", "simpleTestModule", - "test.swift"]) - var moduleDependencyGraph = - try JSONDecoder().decode( - InterModuleDependencyGraph.self, - from: ModuleDependenciesInputs.simpleDependencyGraphInput.data(using: .utf8)!) - // Key part of this test, using the external info to generate dependency pre-build jobs - try moduleDependencyGraph.resolveExternalDependencies(for: externalDetails) - - // Ensure the main module was not overriden by an external dependency - XCTAssertNotNil(moduleDependencyGraph.modules[.swift("simpleTestModule")]) - - // Ensure the "K" module's framework status got resolved via `externalDetails` - guard case .swiftPrebuiltExternal(let kPrebuiltDetails) = moduleDependencyGraph.modules[.swiftPrebuiltExternal("K")]?.details else { - XCTFail("Expected prebuilt module details for module \"K\"") - return - } - XCTAssertTrue(kPrebuiltDetails.isFramework) - let jobsInPhases = try driver.computeJobsForPhasedStandardBuild(moduleDependencyGraph: moduleDependencyGraph) - let job = try XCTUnwrap(jobsInPhases.allJobs.first(where: { $0.kind == .compile })) - // Load the dependency JSON and verify this dependency was encoded correctly - XCTAssertJobInvocationMatches(job, .flag("-explicit-swift-module-map-file")) - let jsonDepsPathIndex = try XCTUnwrap(job.commandLine.firstIndex(of: .flag("-explicit-swift-module-map-file"))) - let jsonDepsPathArg = job.commandLine[jsonDepsPathIndex + 1] - guard case .path(let jsonDepsPath) = jsonDepsPathArg else { - return XCTFail("No JSON dependency file path found.") - } - guard case let .temporaryWithKnownContents(_, contents) = jsonDepsPath else { - return XCTFail("Unexpected path type") - } - let dependencyInfoList = try JSONDecoder().decode(Array.self, - from: contents) - XCTAssertEqual(dependencyInfoList.count, 2) - let dependencyArtifacts = - dependencyInfoList.first(where:{ $0.moduleName == "A" })! - // Ensure this is a framework, as specified by the externalDetails above. - XCTAssertEqual(dependencyArtifacts.isFramework, true) - } - } - func testModuleDependencyBuildCommandUniqueDepFile() throws { let (stdlibPath, shimsPath, _, _) = try getDriverArtifactsForScanning() try withTemporaryDirectory { path in diff --git a/Tests/SwiftDriverTests/Inputs/ExplicitModuleDependencyBuildInputs.swift b/Tests/SwiftDriverTests/Inputs/ExplicitModuleDependencyBuildInputs.swift index 90211ffbc..7bf9bf173 100644 --- a/Tests/SwiftDriverTests/Inputs/ExplicitModuleDependencyBuildInputs.swift +++ b/Tests/SwiftDriverTests/Inputs/ExplicitModuleDependencyBuildInputs.swift @@ -255,84 +255,6 @@ enum ModuleDependenciesInputs { """ } - static var fastDependencyScannerPlaceholderOutput: String { - """ - { - "mainModuleName": "A", - "modules": [ - { - "swift": "A" - }, - { - "modulePath": "A.swiftmodule", - "sourceFiles": [ - "main.swift", - "A.swift" - ], - "directDependencies": [ - { - "swiftPlaceholder": "B" - }, - { - "swiftPlaceholder": "Swift" - }, - { - "swiftPlaceholder": "SwiftOnoneSupport" - } - ], - "details": { - "swift": { - "isFramework": false - } - } - }, - { - "swiftPlaceholder": "B" - }, - { - "modulePath": "/Volumes/Data/Current/Driver/ExplicitPMTest/.build/x86_64-apple-macosx/debug/B.swiftmodule", - "sourceFiles": [ - ], - "directDependencies" : [ - ], - "details": { - "swiftPlaceholder": { - } - } - }, - { - "swiftPlaceholder": "Swift" - }, - { - "modulePath": "Swift.swiftmodule", - "sourceFiles": [ - ], - "directDependencies": [ - ], - "details": { - "swiftPlaceholder": { - } - } - }, - { - "swiftPlaceholder": "SwiftOnoneSupport" - }, - { - "modulePath": "SwiftOnoneSupport.swiftmodule", - "sourceFiles": [ - ], - "directDependencies": [ - ], - "details": { - "swiftPlaceholder": { - } - } - } - ] - } - """ - } - static var mergeGraphInput1: String { """ {