Skip to content

Commit 9007eeb

Browse files
committed
Previews break with explicit modules enabled <rdar://146184835>
With the new previews execution mode, we don't need to be as aggressive stripping compiler flags for thunk builds like we did for the old dynamic replacement execution mode. And doing so actually breaks when explicit modules are turned on. After auditing the minimum number of flags needed to request single file compiler invocations that don't break with explict modules enabled, this change moves the remaining flags into clauses that only affect dynamic replacement mode. Updated unit tests to match (including some better formatting for the large parameter checks).
1 parent 7023e47 commit 9007eeb

File tree

3 files changed

+183
-34
lines changed

3 files changed

+183
-34
lines changed

Sources/SWBCore/SpecImplementations/Tools/SwiftCompiler.swift

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3241,42 +3241,42 @@ public final class SwiftCompilerSpec : CompilerSpec, SpecIdentifierType, SwiftDi
32413241
// Preview thunks does not need this
32423242
"-emit-objc-header",
32433243

3244-
// Stripping for completeness, but XOJIT Previews are already forced as `-Onone`.
3245-
// We add back `-Onone` below.
3244+
// Previews only work on unoptimized build products.
32463245
"-O",
3247-
"-Onone",
32483246
"-Osize",
32493247

32503248
// _Very_ deprecated, but continuing to strip for backwards compatibility
32513249
"-embed-bitcode",
32523250
"-embed-bitcode-marker",
32533251

3254-
// Stripped for historical reasons. Previews can add it back if it needs debugging information.
3255-
"-g",
3256-
"-dwarf-version=4",
3257-
"-dwarf-version=5",
3258-
32593252
// Previews does not use compiler output
32603253
"-parseable-output",
32613254
"-use-frontend-parseable-output",
32623255

32633256
// Writes more intermediates that Previews does not need
32643257
"-emit-const-values",
32653258
"-save-temps",
3266-
3267-
"-explicit-module-build",
3268-
3269-
// Strip until builder SDKs include a swift-driver with this flag. Do not remove without also removing -clang-build-session-file.
3270-
"-validate-clang-modules-once"
32713259
] {
32723260
while let index = commandLine.firstIndex(of: arg) {
32733261
commandLine.remove(at: index)
32743262
}
32753263
}
32763264
if payload.previewStyle == .dynamicReplacement {
32773265
for arg in [
3266+
// Debug symbols aren't needed in dynamic replacement preview info.
3267+
"-g",
3268+
3269+
// We add back `-Onone` below in dynamic replacement.
3270+
"-Onone",
3271+
32783272
// Dynamic replacement thunks don't need this.
32793273
"-import-underlying-module",
3274+
3275+
// This property was always stripped in dynamic replacement.
3276+
"-explicit-module-build",
3277+
3278+
// Strip until builder SDKs include a swift-driver with this flag. Do not remove without also removing -clang-build-session-file.
3279+
"-validate-clang-modules-once"
32803280
] {
32813281
while let index = commandLine.firstIndex(of: arg) {
32823282
commandLine.remove(at: index)
@@ -3334,17 +3334,17 @@ public final class SwiftCompilerSpec : CompilerSpec, SpecIdentifierType, SwiftDi
33343334
removeWithPrefix("-cache-compile-job")
33353335
commandLine.append("-disable-bridging-pch")
33363336

3337-
for (arg, newValue) in [
3338-
// Previews needs a path to _a_ module cache so it has a place to store built modules.
3339-
("-module-cache-path", previewPayload.moduleCacheDir.str)
3340-
] {
3341-
removeWithParameter(arg)
3342-
if !newValue.isEmpty {
3343-
commandLine += [arg, newValue]
3337+
if payload.previewStyle == .dynamicReplacement {
3338+
for (arg, newValue) in [
3339+
// Previews needs a path to _a_ module cache so it has a place to store built modules.
3340+
("-module-cache-path", previewPayload.moduleCacheDir.str)
3341+
] {
3342+
removeWithParameter(arg)
3343+
if !newValue.isEmpty {
3344+
commandLine += [arg, newValue]
3345+
}
33443346
}
3345-
}
33463347

3347-
if payload.previewStyle == .dynamicReplacement {
33483348
for arg in [
33493349
// We want the objc header in XOJIT mode so ignore in dynamic replacement mode
33503350
"-import-objc-header",
@@ -3414,16 +3414,16 @@ public final class SwiftCompilerSpec : CompilerSpec, SpecIdentifierType, SwiftDi
34143414
"\(payload.moduleName)_PreviewReplacement_\(sourceFile.basenameWithoutSuffix)_\(thunkVariantSuffix)".mangledToC99ExtendedIdentifier(),
34153415
])
34163416
commandLine.append("-parse-as-library")
3417-
}
34183417

3419-
// Faster thunk builds
3420-
commandLine.append("-Onone")
3418+
// Faster thunk builds
3419+
commandLine.append("-Onone")
34213420

3422-
// Faster thunk builds
3423-
commandLine.append(contentsOf: [
3424-
"-Xfrontend",
3425-
"-disable-modules-validate-system-headers",
3426-
])
3421+
// Faster thunk builds
3422+
commandLine.append(contentsOf: [
3423+
"-Xfrontend",
3424+
"-disable-modules-validate-system-headers",
3425+
])
3426+
}
34273427

34283428
// For XOJIT previews, we want the frontend (`swift-frontend`) invocation rather than the driver (`swiftc`) invocation, so ask libSwiftDriver for it and replace the command line with the result for propagation back to the request.
34293429
if let driverPayload = payload.driverPayload, payload.previewStyle == .xojit {

0 commit comments

Comments
 (0)