Skip to content

Commit 7056308

Browse files
committed
Error on insufficient optimization record paths with multi-threaded WMO
In multi-threaded whole module optimization mode, using fewer than N -save-optimization-record-path arguments for N input files causes multiple threads to attempt writing to the same file, which is invalid. This commit adds a diagnostic to catch this error case and provides guidance to users: they must either specify one path per input file, use an output file map, or use single-threaded compilation. Key bug fix: The check now correctly counts actual path arguments instead of checking for the presence of any optimization record flag. Previously, the format flag -save-optimization-record=<format> was incorrectly treated as providing a path, causing false positives.
1 parent 17da56c commit 7056308

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

Sources/SwiftDriver/Jobs/CompileJob.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,18 @@ extension Driver {
271271
? inputs.count
272272
: primaryInputs.count
273273

274+
// Check for invalid usage: insufficient optimization record paths with multi-threaded WMO
275+
// If explicit paths are provided, need one path per input file
276+
// Note: .saveOptimizationRecordEQ is for format (yaml/bitstream), not paths
277+
let optRecordPathCount = parsedOptions.arguments(for: .saveOptimizationRecordPath).count
278+
let hasOptRecordFileMapEntries = outputFileMap?.hasEntries(for: optimizationRecordFileType ?? .yamlOptimizationRecord) ?? false
279+
280+
if !compilerMode.usesPrimaryFileInputs && numThreads > 1 && inputs.count > 1 &&
281+
optRecordPathCount > 0 && optRecordPathCount < inputs.count && !hasOptRecordFileMapEntries {
282+
diagnosticEngine.emit(.error_single_opt_record_path_with_multi_threaded_wmo)
283+
throw ErrorDiagnostics.emitted
284+
}
285+
274286
outputs += try addFrontendSupplementaryOutputArguments(
275287
commandLine: &commandLine,
276288
primaryInputs: primaryInputs,

Sources/SwiftDriver/Utilities/Diagnostics.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,4 +182,8 @@ extension Diagnostic.Message {
182182
static var error_no_objc_interop_embedded: Diagnostic.Message {
183183
.error("Objective-C interop cannot be enabled with embedded Swift.")
184184
}
185+
186+
static var error_single_opt_record_path_with_multi_threaded_wmo: Diagnostic.Message {
187+
.error("multi-threaded whole-module optimization requires one '-save-optimization-record-path' per source file")
188+
}
185189
}

0 commit comments

Comments
 (0)