Skip to content

Commit 57c3aad

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 68a78a6 commit 57c3aad

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

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)