Skip to content

Commit 75ee48c

Browse files
committed
[Dependency Scanning] Do now write out bridging header dependencies of binary modules unless in CAS mode
We only record these dependencies in CAS mode, because we require explicit PCH tasks to be produced for imported header of binary module dependencies. In the meantime, in non-CAS mode loading clients will consume the `.h` files encoded in the `.swiftmodules` directly. Followup changes to SwiftDriver will enable explicit PCH compilation of such dependenceis, but for the time being restore prior behavior for non-CAS explicit module builds. Resolves rdar://116006619
1 parent 3bb5424 commit 75ee48c

File tree

5 files changed

+31
-12
lines changed

5 files changed

+31
-12
lines changed

include/swift/Serialization/SerializationOptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ namespace swift {
158158
bool EmbeddedSwiftModule = false;
159159
bool IsOSSA = false;
160160
bool SkipNonExportableDecls = false;
161+
bool ExplicitModuleBuild = false;
161162
};
162163

163164
} // end namespace swift

lib/Frontend/Frontend.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,8 @@ SerializationOptions CompilerInvocation::computeSerializationOptions(
240240

241241
serializationOpts.SkipNonExportableDecls = opts.SkipNonExportableDecls;
242242

243+
serializationOpts.ExplicitModuleBuild = FrontendOpts.DisableImplicitModules;
244+
243245
return serializationOpts;
244246
}
245247

lib/Serialization/Serialization.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1303,7 +1303,8 @@ void Serializer::writeInputBlock() {
13031303
// We do not want to serialize the explicitly-specified .pch path if one was
13041304
// provided. Instead we write out the path to the original header source so
13051305
// that clients can consume it.
1306-
if (llvm::sys::path::extension(importedHeaderPath)
1306+
if (Options.ExplicitModuleBuild &&
1307+
llvm::sys::path::extension(importedHeaderPath)
13071308
.endswith(file_types::getExtension(file_types::TY_PCH)))
13081309
importedHeaderPath = clangImporter->getClangInstance()
13091310
.getASTReader()

lib/Serialization/SerializedModuleLoader.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -477,12 +477,19 @@ SerializedModuleLoaderBase::scanModuleFile(Twine modulePath, bool isFramework) {
477477

478478
auto importedHeaderSet = binaryModuleImports.get().headerImports;
479479
std::vector<std::string> importedHeaders;
480-
importedHeaders.reserve(importedHeaderSet.size());
481-
llvm::transform(importedHeaderSet.keys(),
482-
std::back_inserter(importedHeaders),
483-
[](llvm::StringRef N) {
484-
return N.str();
485-
});
480+
// FIXME: We only record these dependencies in CAS mode, because
481+
// we require explicit PCH tasks to be produced for imported header
482+
// of binary module dependencies. In the meantime, in non-CAS mode
483+
// loading clients will consume the `.h` files encoded in the `.swiftmodules`
484+
// directly.
485+
if (Ctx.ClangImporterOpts.CASOpts) {
486+
importedHeaders.reserve(importedHeaderSet.size());
487+
llvm::transform(importedHeaderSet.keys(),
488+
std::back_inserter(importedHeaders),
489+
[](llvm::StringRef N) {
490+
return N.str();
491+
});
492+
}
486493

487494
auto &importedOptionalModuleSet = binaryModuleOptionalImports.get().moduleImports;
488495
std::vector<std::string> importedOptionalModuleNames;

test/ScanDependencies/header_deps_of_binary.swift

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,20 @@
22
// RUN: %empty-directory(%t)
33
// RUN: %empty-directory(%t/clang-module-cache)
44
// RUN: %empty-directory(%t/PCH)
5+
// RUN: %empty-directory(%t/HEADER)
56
// RUN: %empty-directory(%t/SwiftModules)
7+
// RUN: %empty-directory(%t/CAS)
68

79
// - Set up Foo Swift dependency
810
// RUN: echo "extension Profiler {" >> %t/foo.swift
911
// RUN: echo " public static let count: Int = 42" >> %t/foo.swift
1012
// RUN: echo "}" >> %t/foo.swift
1113

1214
// - Set up Foo bridging header
13-
// RUN: echo "struct Profiler { void* ptr; };" >> %t/foo.h
15+
// RUN: echo "struct Profiler { void* ptr; };" >> %t/HEADER/foo.h
1416

1517
// - Compile bridging header
16-
// RUN: %target-swift-frontend -enable-objc-interop -emit-pch %t/foo.h -o %t/PCH/foo.pch -disable-implicit-swift-modules
18+
// RUN: %target-swift-frontend -enable-objc-interop -emit-pch %t/HEADER/foo.h -o %t/PCH/foo.pch -disable-implicit-swift-modules
1719

1820
// - Set up explicit dependencies for Foo
1921
// RUN: %target-swift-emit-pcm -module-name SwiftShims %swift-lib-dir/swift/shims/module.modulemap -o %t/inputs/SwiftShims.pcm
@@ -50,21 +52,27 @@
5052
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/SwiftModules/Foo.swiftmodule %t/foo.swift -module-name Foo -import-objc-header %t/PCH/foo.pch -disable-implicit-concurrency-module-import -disable-implicit-string-processing-module-import -disable-implicit-swift-modules -explicit-swift-module-map-file %t/foo_inputs_map.json
5153

5254
// - Scan main module
53-
// RUN: %target-swift-frontend -scan-dependencies %s -I %t/SwiftModules -I %S/Inputs/Swift -o %t/deps.json
55+
// RUN: %target-swift-frontend -scan-dependencies %s -I %t/SwiftModules -I %S/Inputs/Swift -o %t/deps.json -cache-compile-job -cas-path %t/cas
5456
// RUN: %validate-json %t/deps.json | %FileCheck %s
5557

58+
// - Scan main module without a CAS and ensure no headerDependencies are emitted
59+
// RUN: %target-swift-frontend -scan-dependencies %s -I %t/SwiftModules -I %S/Inputs/Swift -o %t/deps_nocas.json
60+
// RUN: %validate-json %t/deps_nocas.json | %FileCheck %s --check-prefix=CHECK-NO-HEADERS
61+
5662
// CHECK: "swift": "FooClient"
5763
// CHECK: "swift": "FooClient"
5864
// CHECK: "swiftPrebuiltExternal": "Foo"
5965
// CHECK: "commandLine": [
6066
// CHECK: "-include-pch",
6167
// CHECK-NEXT: "-Xcc",
62-
// CHECK-NEXT: "{{.*}}{{/|\\}}PCH{{/|\\}}foo.pch"
68+
// CHECK-NEXT: "{{.*}}{{/|\\}}HEADER{{/|\\}}foo.h"
6369

6470

6571
// CHECK: "swiftPrebuiltExternal": "Foo"
6672
// CHECK: "headerDependencies": [
67-
// CHECK: "{{.*}}{{/|\\}}PCH{{/|\\}}foo.pch"
73+
// CHECK: "{{.*}}{{/|\\}}HEADER{{/|\\}}foo.h"
6874
// CHECK: ],
6975

76+
// CHECK-NO-HEADERS-NOT: "headerDependencies"
77+
7078
import FooClient

0 commit comments

Comments
 (0)