Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d204e54

Browse files
committedApr 2, 2025·
[Caching] Support -resolved-plugin-validation
Add support for `-resolved-plugin-validation`: * Unconditionally add the flag if supported for explicit module scan * Append `-cache-replay-prefix-map` to interface compilation jobs
1 parent e9ca0c6 commit d204e54

File tree

5 files changed

+44
-2
lines changed

5 files changed

+44
-2
lines changed
 

‎Sources/SwiftDriver/ExplicitModuleBuilds/ExplicitDependencyBuildPlanner.swift

+16-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
5353
private let mainModuleName: String?
5454
private let cas: SwiftScanCAS?
5555
private let swiftScanOracle: InterModuleDependencyOracle
56+
private let prefixMap: [(AbsolutePath, AbsolutePath)]
5657

5758
/// Clang PCM names contain a hash of the command-line arguments that were used to build them.
5859
/// We avoid re-running the hash computation with the use of this cache
@@ -73,7 +74,8 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
7374
dependencyOracle: InterModuleDependencyOracle,
7475
integratedDriver: Bool = true,
7576
supportsExplicitInterfaceBuild: Bool = false,
76-
cas: SwiftScanCAS? = nil) throws {
77+
cas: SwiftScanCAS? = nil,
78+
prefixMap: [(AbsolutePath, AbsolutePath)] = []) throws {
7779
self.dependencyGraph = dependencyGraph
7880
self.toolchain = toolchain
7981
self.swiftScanOracle = dependencyOracle
@@ -82,6 +84,7 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
8284
self.reachabilityMap = try dependencyGraph.computeTransitiveClosure()
8385
self.supportsExplicitInterfaceBuild = supportsExplicitInterfaceBuild
8486
self.cas = cas
87+
self.prefixMap = prefixMap
8588
}
8689

8790
/// Supports resolving bridging header pch command from swiftScan.
@@ -185,6 +188,12 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
185188
}
186189
}
187190

191+
// Add prefix mapping. The option is cache invariant so it can be added without affecting cache key.
192+
for (key, value) in prefixMap {
193+
commandLine.appendFlag("-cache-replay-prefix-map")
194+
commandLine.appendFlag(value.pathString + "=" + key.pathString)
195+
}
196+
188197
jobs.append(Job(
189198
moduleName: moduleId.moduleName,
190199
kind: .compileModuleFromInterface,
@@ -238,6 +247,12 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
238247
cacheKeys = [:]
239248
}
240249

250+
// Add prefix mapping. The option is cache invariant so it can be added without affecting cache key.
251+
for (key, value) in prefixMap {
252+
commandLine.appendFlag("-cache-replay-prefix-map")
253+
commandLine.appendFlag(value.pathString + "=" + key.pathString)
254+
}
255+
241256
jobs.append(Job(
242257
moduleName: moduleId.moduleName,
243258
kind: .generatePCM,

‎Sources/SwiftDriver/ExplicitModuleBuilds/ModuleDependencyScanning.swift

+4
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,10 @@ public extension Driver {
195195
}
196196
}
197197

198+
if isFrontendArgSupported(.resolvedPluginVerification) {
199+
commandLine.appendFlag(.resolvedPluginVerification)
200+
}
201+
198202
// Pass on the input files
199203
commandLine.append(contentsOf: inputFiles.filter { $0.type == .swift }.map { .path($0.file) })
200204
return (inputs, commandLine)

‎Sources/SwiftDriver/Jobs/Planning.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,8 @@ extension Driver {
688688
integratedDriver: integratedDriver,
689689
supportsExplicitInterfaceBuild:
690690
isFrontendArgSupported(.explicitInterfaceModuleBuild),
691-
cas: cas)
691+
cas: cas,
692+
prefixMap: prefixMapping)
692693

693694
return try explicitDependencyBuildPlanner!.generateExplicitModuleDependenciesBuildJobs()
694695
}

‎Sources/SwiftOptions/Options.swift

+20
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ extension Option {
157157
public static let directClangCc1ModuleBuild: Option = Option("-direct-clang-cc1-module-build", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Use the specified -Xcc options to build a PCM by using Clang frontend directly, bypassing the Clang driver")
158158
public static let disableAccessControl: Option = Option("-disable-access-control", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Don't respect access control restrictions")
159159
public static let disableActorDataRaceChecks: Option = Option("-disable-actor-data-race-checks", .flag, attributes: [.frontend, .doesNotAffectIncrementalBuild], helpText: "Disable runtime checks for actor data races")
160+
public static let disableAddressDependencies: Option = Option("-disable-address-dependencies", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Disable enforcement of lifetime dependencies on addressable values.")
160161
public static let disableAggressiveReg2mem: Option = Option("-disable-aggressive-reg2mem", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Disable a more aggressive reg2mem heuristic")
161162
public static let disableAliasModuleNamesInModuleInterface: Option = Option("-disable-alias-module-names-in-module-interface", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "When emitting a module interface, disable disambiguating modules using distinct alias names")
162163
public static let disableAllAutolinking: Option = Option("-disable-all-autolinking", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Disable all Swift autolink directives")
@@ -223,6 +224,7 @@ extension Option {
223224
public static let disableLlvmMergeFunctionsPass: Option = Option("-disable-llvm-merge-functions-pass", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Disable the MergeFunctionPass LLVM IR pass")
224225
public static let disableLlvmOptzns: Option = Option("-disable-llvm-optzns", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Don't run LLVM optimization passes")
225226
public static let disableLlvmValueNames: Option = Option("-disable-llvm-value-names", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Don't add names to local values in LLVM IR")
227+
public static let disableLlvmVerifyEach: Option = Option("-disable-llvm-verify-each", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Don't run the LLVM IR verifier after every pass.")
226228
public static let disableLlvmVerify: Option = Option("-disable-llvm-verify", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Don't run the LLVM IR verifier.")
227229
public static let disableMigratorFixits: Option = Option("-disable-migrator-fixits", .flag, attributes: [.frontend, .noInteractive], helpText: "Disable the Migrator phase which automatically applies fix-its")
228230
public static let disableModulesValidateSystemHeaders: Option = Option("-disable-modules-validate-system-headers", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Disable validating system headers in the Clang importer")
@@ -279,6 +281,7 @@ extension Option {
279281
public static let disableVerifyExclusivity: Option = Option("-disable-verify-exclusivity", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Disable verification of access markers used to enforce exclusivity.")
280282
public static let disableX8664Corocc: Option = Option("-disable-x86_64-corocc", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Don't use swiftcorocc for yield_once_2 routines on x86_64.")
281283
public static let disallowForwardingDriver: Option = Option("-disallow-use-new-driver", .flag, helpText: "Disable using new swift-driver")
284+
public static let disableCondFailMessageAnnotation: Option = Option("-dissable-cond-fail-message-annotation", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Disable cond_fail message annotation.")
282285
public static let downgradeTypecheckInterfaceError: Option = Option("-downgrade-typecheck-interface-error", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Downgrade error to warning when typechecking emitted module interfaces")
283286
public static let driverAlwaysRebuildDependents: Option = Option("-driver-always-rebuild-dependents", .flag, attributes: [.helpHidden, .doesNotAffectIncrementalBuild], helpText: "Always rebuild dependents of files that have been modified", group: .internalDebug)
284287
public static let driverBatchCount: Option = Option("-driver-batch-count", .separate, attributes: [.helpHidden, .doesNotAffectIncrementalBuild], helpText: "Use the given number of batch-mode partitions, rather than partitioning dynamically", group: .internalDebug)
@@ -426,6 +429,7 @@ extension Option {
426429
public static let EnableCMOEverything: Option = Option("-enable-cmo-everything", .flag, attributes: [.helpHidden, .frontend], helpText: "Perform cross-module optimization on everything (all APIs). This is the same level of serialization as Embedded Swift.")
427430
public static let enableCollocateMetadataFunctions: Option = Option("-enable-collocate-metadata-functions", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Enable collocate metadata functions")
428431
public static let enableColocateTypeDescriptors: Option = Option("-enable-colocate-type-descriptors", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Enable colocate type descriptors")
432+
public static let enableCondFailMessageAnnotation: Option = Option("-enable-cond-fail-message-annotation", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Enable cond_fail message annotation. Will serialize a .o.yaml file per .o file.")
429433
public static let copyPropagationStateEQ: Option = Option("-enable-copy-propagation=", .joined, attributes: [.frontend, .noDriver], metaVar: "true|requested-passes-only|false", helpText: "Whether to enable copy propagation")
430434
public static let enableCopyPropagation: Option = Option("-enable-copy-propagation", .flag, attributes: [.frontend, .noDriver], helpText: "Run SIL copy propagation with lexical lifetimes to shorten object lifetimes while preserving variable lifetimes.")
431435
public static let enableCrossImportOverlays: Option = Option("-enable-cross-import-overlays", .flag, attributes: [.frontend, .noDriver], helpText: "Automatically import declared cross-import overlays.")
@@ -470,6 +474,7 @@ extension Option {
470474
public static let enableLibraryEvolution: Option = Option("-enable-library-evolution", .flag, attributes: [.frontend, .moduleInterface], helpText: "Build the module to allow binary-compatible library evolution")
471475
public static let enableLifetimeDependenceDiagnostics: Option = Option("-enable-lifetime-dependence-diagnostics", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Enable lifetime dependence diagnostics for Nonescapable types.")
472476
public static let enableLlvmValueNames: Option = Option("-enable-llvm-value-names", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Add names to local values in LLVM IR")
477+
public static let enableLlvmVerifyEach: Option = Option("-enable-llvm-verify-each", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Run the LLVM IR verifier after every pass.")
473478
public static let enableLlvmVfe: Option = Option("-enable-llvm-vfe", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Use LLVM IR Virtual Function Elimination on Swift class virtual tables")
474479
public static let enableLlvmWme: Option = Option("-enable-llvm-wme", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Use LLVM IR Witness Method Elimination on Swift protocol witness tables")
475480
public static let enableMoveInoutStackProtector: Option = Option("-enable-move-inout-stack-protector", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Enable the stack protector by moving values to temporaries")
@@ -518,6 +523,8 @@ extension Option {
518523
public static let entryPointFunctionName: Option = Option("-entry-point-function-name", .separate, attributes: [.helpHidden, .frontend, .noDriver], metaVar: "<string>", helpText: "Name of the entry point function")
519524
public static let errorOnAbiBreakage: Option = Option("-error-on-abi-breakage", .flag, attributes: [.noDriver], helpText: "Always treat ABI checker issues as errors")
520525
public static let errorOnAbiBreakage_: Option = Option("--error-on-abi-breakage", .flag, alias: Option.errorOnAbiBreakage, attributes: [.noDriver], helpText: "Always treat ABI checker issues as errors")
526+
public static let executorFactoryEQ: Option = Option("-executor-factory=", .joined, alias: Option.executorFactory, attributes: [.frontend])
527+
public static let executorFactory: Option = Option("-executor-factory", .joinedOrSeparate, attributes: [.frontend], metaVar: "<factory-type>", helpText: "Specify the factory to use to create the default executors for Swift Concurrency. This must be a type conforming to the 'ExecutorFactory' protocol.")
521528
public static let experimentalAllowModuleWithCompilerErrors: Option = Option("-experimental-allow-module-with-compiler-errors", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Attempt to output .swiftmodule, regardless of compilation errors")
522529
public static let experimentalAllowNonResilientAccess: Option = Option("-experimental-allow-non-resilient-access", .flag, attributes: [.frontend], helpText: "Deprecated; use -allow-non-resilient-access instead")
523530
public static let experimentalAllowedReexportedModules: Option = Option("-experimental-allowed-reexported-modules=", .commaJoined, attributes: [.noDriver], helpText: "Allow reexporting symbols from the provided modules if they are themselves exported from the main module. This is a comma separated list of module names.")
@@ -659,6 +666,7 @@ extension Option {
659666
public static let l: Option = Option("-l", .joinedOrSeparate, attributes: [.frontend, .doesNotAffectIncrementalBuild], helpText: "Specifies a library which should be linked against", group: .linkerOption)
660667
public static let mergeModules: Option = Option("-merge-modules", .flag, attributes: [.frontend, .noDriver], helpText: "Merge the input modules without otherwise processing them", group: .modes)
661668
public static let mergeableSymbols: Option = Option("-mergeable-symbols", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Emit symbol definitions as mergeable (linkonce_odr)")
669+
public static let mergeableTraps: Option = Option("-mergeable-traps", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Emit mergeable traps even in optimized builds")
662670
public static let migrateKeepObjcVisibility: Option = Option("-migrate-keep-objc-visibility", .flag, attributes: [.frontend, .noInteractive], helpText: "When migrating, add '@objc' to declarations that would've been implicitly visible in Swift 3")
663671
public static let migratorUpdateSdk: Option = Option("-migrator-update-sdk", .flag, attributes: [.frontend, .noInteractive], helpText: "Does nothing. Temporary compatibility flag for Xcode.")
664672
public static let migratorUpdateSwift: Option = Option("-migrator-update-swift", .flag, attributes: [.frontend, .noInteractive], helpText: "Does nothing. Temporary compatibility flag for Xcode.")
@@ -768,6 +776,7 @@ extension Option {
768776
public static let protocolRequirementAllowList_: Option = Option("--protocol-requirement-allow-list", .separate, alias: Option.protocolRequirementAllowList, attributes: [.noDriver, .argumentIsPath], metaVar: "<path>", helpText: "File containing a new-line separated list of protocol names")
769777
public static let publicAutolinkLibrary: Option = Option("-public-autolink-library", .separate, attributes: [.helpHidden, .frontend, .noDriver, .moduleInterface], helpText: "Add public dependent library")
770778
public static let publicModuleName: Option = Option("-public-module-name", .separate, attributes: [.frontend], helpText: "Public facing module name to use in diagnostics and documentation")
779+
public static let remarkAbiInference: Option = Option("-Rabi-inference", .flag, attributes: [.frontend, .doesNotAffectIncrementalBuild], helpText: "Emit a remark when an '@abi' attribute adds an attribute or modifier to the ABI declaration based on its presence in the API")
771780
public static let RaccessNoteEQ: Option = Option("-Raccess-note=", .joined, alias: Option.RaccessNote, attributes: [.frontend, .noDriver])
772781
public static let RaccessNote: Option = Option("-Raccess-note", .separate, attributes: [.frontend, .noDriver], metaVar: "none|failures|all|all-validate", helpText: "Control access note remarks (default: all)")
773782
public static let cacheRemarks: Option = Option("-Rcache-compile-job", .flag, attributes: [.frontend, .cacheInvariant], helpText: "Show remarks for compiler caching")
@@ -787,6 +796,7 @@ extension Option {
787796
public static let requirementMachineMaxRuleLength: Option = Option("-requirement-machine-max-rule-length=", .joined, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Set the maximum rule length before giving up")
788797
public static let requirementMachineMaxSplitConcreteEquivClassAttempts: Option = Option("-requirement-machine-max-split-concrete-equiv-class-attempts=", .joined, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Set the maximum concrete number of attempts at splitting concrete equivalence classes before giving up. There should never be a reason to change this")
789798
public static let resolveImports: Option = Option("-resolve-imports", .flag, attributes: [.frontend, .noInteractive, .doesNotAffectIncrementalBuild], helpText: "Parse and resolve imports in input file(s)", group: .modes)
799+
public static let resolvedPluginVerification: Option = Option("-resolved-plugin-verification", .flag, attributes: [.frontend, .noDriver], helpText: "verify resolved plugins")
790800
public static let resourceDir: Option = Option("-resource-dir", .separate, attributes: [.helpHidden, .frontend, .synthesizeInterface, .argumentIsPath], metaVar: "</usr/lib/swift>", helpText: "The directory that holds the compiler resource files")
791801
public static let remarkIndexingSystemModule: Option = Option("-Rindexing-system-module", .flag, attributes: [.frontend, .doesNotAffectIncrementalBuild], helpText: "Emit a remark when indexing a system module")
792802
public static let remarkMacroLoading: Option = Option("-Rmacro-loading", .flag, attributes: [.frontend, .doesNotAffectIncrementalBuild], helpText: "Emit remarks about loaded macro implementations")
@@ -1104,6 +1114,7 @@ extension Option {
11041114
Option.directClangCc1ModuleBuild,
11051115
Option.disableAccessControl,
11061116
Option.disableActorDataRaceChecks,
1117+
Option.disableAddressDependencies,
11071118
Option.disableAggressiveReg2mem,
11081119
Option.disableAliasModuleNamesInModuleInterface,
11091120
Option.disableAllAutolinking,
@@ -1170,6 +1181,7 @@ extension Option {
11701181
Option.disableLlvmMergeFunctionsPass,
11711182
Option.disableLlvmOptzns,
11721183
Option.disableLlvmValueNames,
1184+
Option.disableLlvmVerifyEach,
11731185
Option.disableLlvmVerify,
11741186
Option.disableMigratorFixits,
11751187
Option.disableModulesValidateSystemHeaders,
@@ -1226,6 +1238,7 @@ extension Option {
12261238
Option.disableVerifyExclusivity,
12271239
Option.disableX8664Corocc,
12281240
Option.disallowForwardingDriver,
1241+
Option.disableCondFailMessageAnnotation,
12291242
Option.downgradeTypecheckInterfaceError,
12301243
Option.driverAlwaysRebuildDependents,
12311244
Option.driverBatchCount,
@@ -1373,6 +1386,7 @@ extension Option {
13731386
Option.EnableCMOEverything,
13741387
Option.enableCollocateMetadataFunctions,
13751388
Option.enableColocateTypeDescriptors,
1389+
Option.enableCondFailMessageAnnotation,
13761390
Option.copyPropagationStateEQ,
13771391
Option.enableCopyPropagation,
13781392
Option.enableCrossImportOverlays,
@@ -1417,6 +1431,7 @@ extension Option {
14171431
Option.enableLibraryEvolution,
14181432
Option.enableLifetimeDependenceDiagnostics,
14191433
Option.enableLlvmValueNames,
1434+
Option.enableLlvmVerifyEach,
14201435
Option.enableLlvmVfe,
14211436
Option.enableLlvmWme,
14221437
Option.enableMoveInoutStackProtector,
@@ -1465,6 +1480,8 @@ extension Option {
14651480
Option.entryPointFunctionName,
14661481
Option.errorOnAbiBreakage,
14671482
Option.errorOnAbiBreakage_,
1483+
Option.executorFactoryEQ,
1484+
Option.executorFactory,
14681485
Option.experimentalAllowModuleWithCompilerErrors,
14691486
Option.experimentalAllowNonResilientAccess,
14701487
Option.experimentalAllowedReexportedModules,
@@ -1606,6 +1623,7 @@ extension Option {
16061623
Option.l,
16071624
Option.mergeModules,
16081625
Option.mergeableSymbols,
1626+
Option.mergeableTraps,
16091627
Option.migrateKeepObjcVisibility,
16101628
Option.migratorUpdateSdk,
16111629
Option.migratorUpdateSwift,
@@ -1715,6 +1733,7 @@ extension Option {
17151733
Option.protocolRequirementAllowList_,
17161734
Option.publicAutolinkLibrary,
17171735
Option.publicModuleName,
1736+
Option.remarkAbiInference,
17181737
Option.RaccessNoteEQ,
17191738
Option.RaccessNote,
17201739
Option.cacheRemarks,
@@ -1734,6 +1753,7 @@ extension Option {
17341753
Option.requirementMachineMaxRuleLength,
17351754
Option.requirementMachineMaxSplitConcreteEquivClassAttempts,
17361755
Option.resolveImports,
1756+
Option.resolvedPluginVerification,
17371757
Option.resourceDir,
17381758
Option.remarkIndexingSystemModule,
17391759
Option.remarkMacroLoading,

‎Tests/SwiftDriverTests/CachingBuildTests.swift

+2
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,8 @@ final class CachingBuildTests: XCTestCase {
939939
XCTAssertFalse(try command.contains {
940940
$0.starts(with: try testInputsPath.description)
941941
})
942+
/// command-line that compiles swift should contains -cache-replay-prefix-map
943+
XCTAssertTrue(command.contains { $0 == "-cache-replay-prefix-map" })
942944
}
943945
}
944946
}

0 commit comments

Comments
 (0)
Please sign in to comment.