Skip to content

[Dependency Scanning] Remove references to per-triple PCM variant compilation #1788

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

Merged
merged 1 commit into from
Jan 30, 2025
Merged
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
4 changes: 0 additions & 4 deletions Sources/CSwiftScan/include/swiftscan_header.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@ typedef struct {
(*swiftscan_swift_textual_detail_get_command_line)(swiftscan_module_details_t);
swiftscan_string_set_t *
(*swiftscan_swift_textual_detail_get_bridging_pch_command_line)(swiftscan_module_details_t);
swiftscan_string_set_t *
(*swiftscan_swift_textual_detail_get_extra_pcm_args)(swiftscan_module_details_t);
swiftscan_string_ref_t
(*swiftscan_swift_textual_detail_get_context_hash)(swiftscan_module_details_t);
bool
Expand Down Expand Up @@ -181,8 +179,6 @@ typedef struct {
(*swiftscan_clang_detail_get_context_hash)(swiftscan_module_details_t);
swiftscan_string_set_t *
(*swiftscan_clang_detail_get_command_line)(swiftscan_module_details_t);
swiftscan_string_set_t *
(*swiftscan_clang_detail_get_captured_pcm_args)(swiftscan_module_details_t);
swiftscan_string_ref_t
(*swiftscan_clang_detail_get_module_cache_key)(swiftscan_module_details_t);

Expand Down
3 changes: 0 additions & 3 deletions Sources/SwiftDriver/Driver/Driver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public struct Driver {
case optionRequiresAnother(String, String)
// Explicit Module Build Failures
case malformedModuleDependency(String, String)
case missingPCMArguments(String)
case missingModuleDependency(String)
case missingContextHashOnSwiftDependency(String)
case dependencyScanningFailure(Int, String)
Expand Down Expand Up @@ -124,8 +123,6 @@ public struct Driver {
// Explicit Module Build Failures
case .malformedModuleDependency(let moduleName, let errorDescription):
return "Malformed Module Dependency: \(moduleName), \(errorDescription)"
case .missingPCMArguments(let moduleName):
return "Missing extraPcmArgs to build Clang module: \(moduleName)"
case .missingModuleDependency(let moduleName):
return "Missing Module Dependency Info: \(moduleName)"
case .missingContextHashOnSwiftDependency(let moduleName):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,7 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
return jobs
}

/// Generate a build job for each Clang module in the set of supplied `dependencies`. Once per each required
/// PCMArgSet as queried from the supplied `clangPCMSetMap`
/// Generate a build job for each Clang module in the set of supplied `dependencies`.
private mutating func generateClangDependenciesBuildJobs(for dependencies: Set<ModuleDependencyId>)
throws -> [Job] {
var jobs: [Job] = []
Expand Down Expand Up @@ -391,25 +390,6 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
}
}

private func updateClangPCMArgSetMap(for moduleId: ModuleDependencyId,
clangPCMSetMap: inout [ModuleDependencyId : Set<[String]>])
throws {
guard let moduleDependencies = reachabilityMap[moduleId] else {
fatalError("Expected reachability information for the module: \(moduleId.moduleName).")
}
let pcmArgs = try dependencyGraph.swiftModulePCMArgs(of: moduleId)
for dependencyId in moduleDependencies {
guard case .clang(_) = dependencyId else {
continue
}
if clangPCMSetMap[dependencyId] != nil {
clangPCMSetMap[dependencyId]!.insert(pcmArgs)
} else {
clangPCMSetMap[dependencyId] = [pcmArgs]
}
}
}

public func getLinkLibraryLoadCommandFlags(_ commandLine: inout [Job.ArgTemplate]) throws {
var allLinkLibraries: [LinkLibraryInfo] = []
for (_, moduleInfo) in dependencyGraph.modules {
Expand Down Expand Up @@ -550,26 +530,6 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
encoder.outputFormatting = [.prettyPrinted, .sortedKeys]
return try encoder.encode(allDependencyArtifacts)
}

private func getPCMHashParts(pcmArgs: [String], contextHash: String) -> [String] {
var results: [String] = []
results.append(contextHash)
results.append(contentsOf: pcmArgs)
if integratedDriver {
return results
}

// We need this to enable explicit modules in the driver-as-executable mode. For instance,
// we have two Swift targets A and B, where A depends on X.pcm which in turn depends on Y.pcm,
// and B only depends on Y.pcm. In the driver-as-executable mode, the build system isn't aware
// of the shared dependency of Y.pcm so it will be generated multiple times. If all these Y.pcm
// share the same name, X.pcm may fail to be loaded because its dependency Y.pcm may have a
// changed mod time.
// We only differentiate these PCM names in the non-integrated mode due to the lacking of
// inter-module planning.
results.append(mainModuleName!)
return results
}
}

/// Encapsulates some of the common queries of the ExplicitDependencyBuildPlanner with error-checking
Expand Down Expand Up @@ -605,11 +565,6 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
}
return clangModuleDetails
}

func swiftModulePCMArgs(of moduleId: ModuleDependencyId) throws -> [String] {
let moduleDetails = try swiftModuleDetails(of: moduleId)
return moduleDetails.extraPcmArgs
}
}

internal extension ExplicitDependencyBuildPlanner {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,67 +117,6 @@ extension InterModuleDependencyGraph {
}

@_spi(Testing) public extension InterModuleDependencyGraph {
/// Merge a module with a given ID and Info into a ModuleInfoMap
static func mergeModule(_ moduleId: ModuleDependencyId,
_ moduleInfo: ModuleInfo,
into moduleInfoMap: inout ModuleInfoMap) throws {
switch moduleId {
case .swift:
let prebuiltExternalModuleEquivalentId =
ModuleDependencyId.swiftPrebuiltExternal(moduleId.moduleName)
let placeholderEquivalentId =
ModuleDependencyId.swiftPlaceholder(moduleId.moduleName)
if moduleInfoMap[prebuiltExternalModuleEquivalentId] != nil ||
moduleInfoMap[moduleId] != nil {
// If the set of discovered externalModules contains a .swiftPrebuiltExternal or .swift module
// with the same name, do not replace it.
break
} else if moduleInfoMap[placeholderEquivalentId] != nil {
// Replace the placeholder module with a full .swift ModuleInfo
// and fixup other externalModules' dependencies
replaceModule(originalId: placeholderEquivalentId, replacementId: moduleId,
replacementInfo: moduleInfo, in: &moduleInfoMap)
} else {
// Insert the new module
moduleInfoMap[moduleId] = moduleInfo
}

case .swiftPrebuiltExternal:
// If the set of discovered externalModules contains a .swift module with the same name,
// replace it with the prebuilt version and fixup other externalModules' dependencies
let swiftModuleEquivalentId = ModuleDependencyId.swift(moduleId.moduleName)
let swiftPlaceholderEquivalentId = ModuleDependencyId.swiftPlaceholder(moduleId.moduleName)
if moduleInfoMap[swiftModuleEquivalentId] != nil {
// If the ModuleInfoMap contains an equivalent .swift module, replace it with the prebuilt
// version and update all other externalModules' dependencies
replaceModule(originalId: swiftModuleEquivalentId, replacementId: moduleId,
replacementInfo: moduleInfo, in: &moduleInfoMap)
} else if moduleInfoMap[swiftPlaceholderEquivalentId] != nil {
// If the moduleInfoMap contains an equivalent .swiftPlaceholder module, replace it with
// the prebuilt version and update all other externalModules' dependencies
replaceModule(originalId: swiftPlaceholderEquivalentId, replacementId: moduleId,
replacementInfo: moduleInfo, in: &moduleInfoMap)
} else {
// Insert the new module
moduleInfoMap[moduleId] = moduleInfo
}

case .clang:
guard let existingModuleInfo = moduleInfoMap[moduleId] else {
moduleInfoMap[moduleId] = moduleInfo
break
}
// If this module *has* been seen before, merge the module infos to capture
// the super-set of so-far discovered dependencies of this module at various
// PCMArg scanning actions.
let combinedDependenciesInfo = mergeClangModuleInfoDependencies(moduleInfo,
existingModuleInfo)
replaceModule(originalId: moduleId, replacementId: moduleId,
replacementInfo: combinedDependenciesInfo, in: &moduleInfoMap)
case .swiftPlaceholder:
fatalError("Unresolved placeholder dependency at graph merge operation: \(moduleId)")
}
}

/// Replace an existing module in the moduleInfoMap
static func replaceModule(originalId: ModuleDependencyId, replacementId: ModuleDependencyId,
Expand Down Expand Up @@ -207,53 +146,6 @@ extension InterModuleDependencyGraph {
}
}
}

/// Given two moduleInfos of clang externalModules, merge them by combining their directDependencies and
/// dependenciesCapturedPCMArgs and sourceFiles fields. These fields may differ across the same module
/// scanned at different PCMArgs (e.g. -target option).
static func mergeClangModuleInfoDependencies(_ firstInfo: ModuleInfo, _ secondInfo:ModuleInfo
) -> ModuleInfo {
guard case .clang(let firstDetails) = firstInfo.details,
case .clang(let secondDetails) = secondInfo.details
else {
fatalError("mergeClangModules expected two valid ClangModuleDetails objects.")
}

// As far as their dependencies go, these module infos are identical
if firstInfo.directDependencies == secondInfo.directDependencies,
firstDetails.capturedPCMArgs == secondDetails.capturedPCMArgs,
firstInfo.sourceFiles == secondInfo.sourceFiles {
return firstInfo
}

// Create a new moduleInfo that represents this module with combined dependency information
let firstModuleSources = firstInfo.sourceFiles ?? []
let secondModuleSources = secondInfo.sourceFiles ?? []
let combinedSourceFiles = Array(Set(firstModuleSources + secondModuleSources))

let firstModuleDependencies = firstInfo.directDependencies ?? []
let secondModuleDependencies = secondInfo.directDependencies ?? []
let combinedDependencies = Array(Set(firstModuleDependencies + secondModuleDependencies))
let firstLinkLibraries = firstInfo.linkLibraries ?? []
let secondLinkLibraries = secondInfo.linkLibraries ?? []
let combinedLinkLibraries = Array(Set(firstLinkLibraries + secondLinkLibraries))

let firstModuleCapturedPCMArgs = firstDetails.capturedPCMArgs ?? Set<[String]>()
let secondModuleCapturedPCMArgs = secondDetails.capturedPCMArgs ?? Set<[String]>()
let combinedCapturedPCMArgs = firstModuleCapturedPCMArgs.union(secondModuleCapturedPCMArgs)

let combinedModuleDetails =
ClangModuleDetails(moduleMapPath: firstDetails.moduleMapPath,
contextHash: firstDetails.contextHash,
commandLine: firstDetails.commandLine,
capturedPCMArgs: combinedCapturedPCMArgs)

return ModuleInfo(modulePath: firstInfo.modulePath,
sourceFiles: combinedSourceFiles,
directDependencies: combinedDependencies,
linkLibraries: combinedLinkLibraries,
details: .clang(combinedModuleDetails))
}
}

/// Incremental Build Machinery
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,6 @@ public struct SwiftModuleDetails: Codable, Hashable {
/// corresponding to the main module being built.
public var contextHash: String?

/// To build a PCM to be used by this Swift module, we need to append these
/// arguments to the generic PCM build arguments reported from the dependency
/// graph.
public var extraPcmArgs: [String]

/// A flag to indicate whether or not this module is a framework.
public var isFramework: Bool?

Expand Down Expand Up @@ -192,10 +187,6 @@ public struct ClangModuleDetails: Codable, Hashable {
/// Options to the compile command
public var commandLine: [String] = []

/// Set of PCM Arguments of depending modules which
/// are covered by the directDependencies info of this module
public var capturedPCMArgs: Set<[String]>?

/// The module cache key of the output module.
public var moduleCacheKey: String?
}
Expand Down
15 changes: 0 additions & 15 deletions Sources/SwiftDriver/SwiftScan/DependencyGraphBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,6 @@ private extension SwiftScan {
let bridgingPchCommandLine = supportsBridgingHeaderPCHCommand ?
try getOptionalStringArrayDetail(from: moduleDetailsRef,
using: api.swiftscan_swift_textual_detail_get_bridging_pch_command_line) : nil
let extraPcmArgs =
try getStringArrayDetail(from: moduleDetailsRef,
using: api.swiftscan_swift_textual_detail_get_extra_pcm_args,
fieldName: "extraPCMArgs")
let contextHash =
try getOptionalStringDetail(from: moduleDetailsRef,
using: api.swiftscan_swift_textual_detail_get_context_hash)
Expand All @@ -206,7 +202,6 @@ private extension SwiftScan {
commandLine: commandLine,
bridgingPchCommandLine : bridgingPchCommandLine,
contextHash: contextHash,
extraPcmArgs: extraPcmArgs,
isFramework: isFramework,
swiftOverlayDependencies: swiftOverlayDependencies,
moduleCacheKey: moduleCacheKey)
Expand Down Expand Up @@ -291,22 +286,12 @@ private extension SwiftScan {
using: api.swiftscan_clang_detail_get_command_line,
fieldName: "clang_detail.commandLine")

let capturedPCMArgs : Set<[String]>?
if clangDetailsHaveCapturedPCMArgs {
let capturedArgs = try getStringArrayDetail(from: moduleDetailsRef,
using: api.swiftscan_clang_detail_get_captured_pcm_args,
fieldName: "clang_detail.capturedPCMArgs")
capturedPCMArgs = [capturedArgs]
} else {
capturedPCMArgs = nil
}
let moduleCacheKey = supportsCaching ? try getOptionalStringDetail(from: moduleDetailsRef,
using: api.swiftscan_clang_detail_get_module_cache_key) : nil

return ClangModuleDetails(moduleMapPath: moduleMapPath,
contextHash: contextHash,
commandLine: commandLine,
capturedPCMArgs: capturedPCMArgs,
moduleCacheKey: moduleCacheKey)
}
}
Expand Down
10 changes: 0 additions & 10 deletions Sources/SwiftDriver/SwiftScan/SwiftScan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,6 @@ private extension String {
api.swiftscan_swift_binary_detail_get_header_dependency_module_dependencies != nil
}

@_spi(Testing) public var clangDetailsHaveCapturedPCMArgs : Bool {
api.swiftscan_clang_detail_get_captured_pcm_args != nil
}

@_spi(Testing) public var supportsBinaryModuleHeaderDependencies : Bool {
return api.swiftscan_swift_binary_detail_get_header_dependencies != nil
}
Expand Down Expand Up @@ -478,10 +474,6 @@ private extension swiftscan_functions_t {
self.swiftscan_compiler_target_info_query_v2 =
loadOptional("swiftscan_compiler_target_info_query_v2")

// Clang dependency captured PCM args
self.swiftscan_clang_detail_get_captured_pcm_args =
loadOptional("swiftscan_clang_detail_get_captured_pcm_args")

// Scanner diagnostic emission query
self.swiftscan_scanner_diagnostics_query =
loadOptional("swiftscan_scanner_diagnostics_query")
Expand Down Expand Up @@ -657,8 +649,6 @@ private extension swiftscan_functions_t {
try loadRequired("swiftscan_swift_textual_detail_get_bridging_module_dependencies")
self.swiftscan_swift_textual_detail_get_command_line =
try loadRequired("swiftscan_swift_textual_detail_get_command_line")
self.swiftscan_swift_textual_detail_get_extra_pcm_args =
try loadRequired("swiftscan_swift_textual_detail_get_extra_pcm_args")
self.swiftscan_scan_invocation_get_argc =
try loadRequired("swiftscan_scan_invocation_get_argc")
self.swiftscan_scan_invocation_get_argv =
Expand Down
Loading