Skip to content

Commit

Permalink
Merge pull request #1513 from owenv/owenv/embedded-without-wmo-when-t…
Browse files Browse the repository at this point in the history
…ypechecking

Allow enabling embedded Swift without WMO when not generating SIL
  • Loading branch information
owenv authored Jul 16, 2024
2 parents f2522c6 + 7a7e376 commit 8d32f70
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ extension Driver {
throw ErrorDiagnostics.emitted
}

if isEmbeddedEnabled &&
// 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
if isEmbeddedEnabled && compilerOutputType?.requiresSILGen == true &&
(!parsedOptions.hasArgument(.wmo) || !parsedOptions.hasArgument(.wholeModuleOptimization)) {
diagnosticEngine.emit(.error_need_wmo_embedded)
throw ErrorDiagnostics.emitted
Expand Down
10 changes: 10 additions & 0 deletions Sources/SwiftDriver/Utilities/FileType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,16 @@ extension FileType {
}
}

/// Returns true if producing the file type requires running SILGen.
var requiresSILGen: Bool {
switch self {
case .swift, .ast, .indexData, .indexUnitOutputPath, .jsonCompilerFeatures, .jsonTargetInfo:
return false
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:
return true
}
}

/// Returns true if the type can be cached as output.
var supportCaching: Bool {
switch self {
Expand Down
7 changes: 7 additions & 0 deletions Tests/SwiftDriverTests/SwiftDriverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6914,6 +6914,13 @@ final class SwiftDriverTests: XCTestCase {
_ = try driver.planBuild()
XCTAssertTrue(diags.diagnostics.first!.message.text == Diagnostic.Message.error_need_wmo_embedded.text)
} catch _ { }
do {
// Indexing embedded Swift code should not require WMO
let diags = DiagnosticsEngine()
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)
_ = try driver.planBuild()
XCTAssertEqual(diags.diagnostics.count, 0)
}
do {
let diags = DiagnosticsEngine()
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)
Expand Down

0 comments on commit 8d32f70

Please sign in to comment.