Skip to content

Commit 27ea72f

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 8e47ffe commit 27ea72f

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ extension Driver {
135135
throw ErrorDiagnostics.emitted
136136
}
137137

138-
if embeddedEnabled &&
138+
if embeddedEnabled && compilerOutputType?.requiresSILGen == true &&
139139
(!parsedOptions.hasArgument(.wmo) || !parsedOptions.hasArgument(.wholeModuleOptimization)) {
140140
diagnosticEngine.emit(.error_need_wmo_embedded)
141141
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
@@ -6503,6 +6503,13 @@ final class SwiftDriverTests: XCTestCase {
65036503
_ = try driver.planBuild()
65046504
XCTAssertTrue(diags.diagnostics.first!.message.text == Diagnostic.Message.error_need_wmo_embedded.text)
65056505
} catch _ { }
6506+
do {
6507+
// Indexing embedded Swift code should not require WMO
6508+
let diags = DiagnosticsEngine()
6509+
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)
6510+
_ = try driver.planBuild()
6511+
XCTAssertEqual(diags.diagnostics.count, 0)
6512+
}
65066513
do {
65076514
let diags = DiagnosticsEngine()
65086515
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)