Skip to content

Commit 737dcc8

Browse files
authored
Merge pull request #1666 from owenv/owenv/embedded-swift-indexing-6
[6.0] Allow enabling embedded Swift without WMO when not generating SIL
2 parents 76bb150 + 7e833a6 commit 737dcc8

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift

Lines changed: 2 additions & 1 deletion
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

Lines changed: 10 additions & 0 deletions
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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6845,6 +6845,13 @@ final class SwiftDriverTests: XCTestCase {
68456845
_ = try driver.planBuild()
68466846
XCTAssertTrue(diags.diagnostics.first!.message.text == Diagnostic.Message.error_need_wmo_embedded.text)
68476847
} catch _ { }
6848+
do {
6849+
// Indexing embedded Swift code should not require WMO
6850+
let diags = DiagnosticsEngine()
6851+
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)
6852+
_ = try driver.planBuild()
6853+
XCTAssertEqual(diags.diagnostics.count, 0)
6854+
}
68486855
do {
68496856
let diags = DiagnosticsEngine()
68506857
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)