From 14c478a439f8325d423e301046cbbaf22bc7abb1 Mon Sep 17 00:00:00 2001 From: Ryan Mansfield Date: Tue, 18 Nov 2025 11:06:21 -0500 Subject: [PATCH] Skip default CMO when emitting module separately Cross-module optimization is incompatible with emitting the module separately. Previously, an assertion caught this condition, but the assertion would not fire in release builds. This changes the logic to simply skip enabling default CMO when emitModuleSeparately is true, rather than asserting or erroring. --- Sources/SwiftDriver/Jobs/CompileJob.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sources/SwiftDriver/Jobs/CompileJob.swift b/Sources/SwiftDriver/Jobs/CompileJob.swift index 7a19daaca..3044c8f52 100644 --- a/Sources/SwiftDriver/Jobs/CompileJob.swift +++ b/Sources/SwiftDriver/Jobs/CompileJob.swift @@ -296,12 +296,14 @@ extension Driver { forObject: outputType == .object) try addRuntimeLibraryFlags(commandLine: &commandLine) + // Enable default cross-module optimization when possible, but only if we're not + // emitting the module separately (CMO is incompatible with separate module emission) if Driver.canDoCrossModuleOptimization(parsedOptions: &parsedOptions) && // For historical reasons, -cross-module-optimization turns on "aggressive" CMO // which is different from "default" CMO. !parsedOptions.hasArgument(.CrossModuleOptimization) && - !parsedOptions.hasArgument(.EnableCMOEverything) { - assert(!emitModuleSeparately, "Cannot emit module separately with cross-module-optimization") + !parsedOptions.hasArgument(.EnableCMOEverything) && + !emitModuleSeparately { commandLine.appendFlag("-enable-default-cmo") }