Skip to content

Commit 7a7e376

Browse files
committed
Allow enabling embedded Swift without WMO when not generating SIL
This allows modes like -index-file to work the same way they do when not using embedded Swift
1 parent f2522c6 commit 7a7e376

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ extension Driver {
144144
throw ErrorDiagnostics.emitted
145145
}
146146

147-
if isEmbeddedEnabled &&
147+
// Building embedded Swift requires WMO, unless we're not generating SIL. This allows modes like -index-file to work the same way they do when not using embedded Swift
148+
if isEmbeddedEnabled && compilerOutputType?.requiresSILGen == true &&
148149
(!parsedOptions.hasArgument(.wmo) || !parsedOptions.hasArgument(.wholeModuleOptimization)) {
149150
diagnosticEngine.emit(.error_need_wmo_embedded)
150151
throw ErrorDiagnostics.emitted

Sources/SwiftDriver/Utilities/FileType.swift

+10
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,16 @@ extension FileType {
441441
}
442442
}
443443

444+
/// Returns true if producing the file type requires running SILGen.
445+
var requiresSILGen: Bool {
446+
switch self {
447+
case .swift, .ast, .indexData, .indexUnitOutputPath, .jsonCompilerFeatures, .jsonTargetInfo:
448+
return false
449+
case .sil, .sib, .image, .object, .dSYM, .dependencies, .autolink, .swiftModule, .swiftDocumentation, .swiftInterface, .privateSwiftInterface, .packageSwiftInterface, .swiftSourceInfoFile, .swiftConstValues, .assembly, .raw_sil, .raw_sib, .llvmIR, .llvmBitcode, .diagnostics, .emitModuleDiagnostics, .emitModuleDependencies, .objcHeader, .swiftDeps, .modDepCache, .remap, .importedModules, .tbd, .jsonDependencies, .jsonSwiftArtifacts, .moduleTrace, .yamlOptimizationRecord, .bitstreamOptimizationRecord, .pcm, .pch, .clangModuleMap, .jsonAPIBaseline, .jsonABIBaseline, .jsonAPIDescriptor, .moduleSummary, .moduleSemanticInfo, .cachedDiagnostics:
450+
return true
451+
}
452+
}
453+
444454
/// Returns true if the type can be cached as output.
445455
var supportCaching: Bool {
446456
switch self {

Tests/SwiftDriverTests/SwiftDriverTests.swift

+7
Original file line numberDiff line numberDiff line change
@@ -6914,6 +6914,13 @@ final class SwiftDriverTests: XCTestCase {
69146914
_ = try driver.planBuild()
69156915
XCTAssertTrue(diags.diagnostics.first!.message.text == Diagnostic.Message.error_need_wmo_embedded.text)
69166916
} catch _ { }
6917+
do {
6918+
// Indexing embedded Swift code should not require WMO
6919+
let diags = DiagnosticsEngine()
6920+
var driver = try Driver(args: ["swiftc", "-target", "arm64-apple-macosx10.13", "test.swift", "-index-file", "-index-file-path", "test.swift", "-enable-experimental-feature", "Embedded", "-parse-as-library", "-o", "a.out", "-module-name", "main"], diagnosticsEngine: diags)
6921+
_ = try driver.planBuild()
6922+
XCTAssertEqual(diags.diagnostics.count, 0)
6923+
}
69176924
do {
69186925
let diags = DiagnosticsEngine()
69196926
var driver = try Driver(args: ["swiftc", "-target", "arm64-apple-macosx10.13", "test.swift", "-enable-experimental-feature", "Embedded", "-parse-as-library", "-wmo", "-o", "a.out", "-module-name", "main", "-enable-objc-interop"], diagnosticsEngine: diags)

0 commit comments

Comments
 (0)