Skip to content

Commit 0585ca7

Browse files
committed
[Explicit Module Builds] When building Swift modules, switch over to loading Clang modules eagerly instead of lazily
Swift import resolution already does an equivalent to eager module loading during its import resolution phase.
1 parent 8e72a01 commit 0585ca7

File tree

6 files changed

+25
-38
lines changed

6 files changed

+25
-38
lines changed

lib/AST/ModuleDependencies.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,9 @@ SwiftDependencyScanningService::SwiftDependencyScanningService() {
425425
clang::CASOptions(),
426426
/* CAS (llvm::cas::ObjectStore) */ nullptr,
427427
/* Cache (llvm::cas::ActionCache) */ nullptr,
428-
/* SharedFS */ nullptr);
428+
/* SharedFS */ nullptr,
429+
/* OptimizeArgs */ clang::tooling::dependencies::ScanningOptimizations::Default,
430+
/* EagerModules */ false);
429431
SharedFilesystemCache.emplace();
430432
}
431433

lib/DependencyScan/ScanDependencies.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -276,15 +276,8 @@ static llvm::Error resolveExplicitModuleInputs(
276276
assert(clangDepDetails && "Expected Clang Module dependency.");
277277
if (!resolvingDepInfo.isClangModule()) {
278278
commandLine.push_back("-Xcc");
279-
commandLine.push_back("-fmodule-file=" + depModuleID.ModuleName + "=" +
279+
commandLine.push_back("-fmodule-file=" +
280280
clangDepDetails->mappedPCMPath);
281-
if (!instance.getInvocation()
282-
.getClangImporterOptions()
283-
.UseClangIncludeTree) {
284-
commandLine.push_back("-Xcc");
285-
commandLine.push_back("-fmodule-map-file=" +
286-
remapPath(clangDepDetails->moduleMapFile));
287-
}
288281
}
289282
if (!clangDepDetails->moduleCacheKey.empty()) {
290283
commandLine.push_back("-Xcc");

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2187,19 +2187,17 @@ struct ExplicitSwiftModuleLoader::Implementation {
21872187
std::vector<std::string> &extraClangArgs = Ctx.ClangImporterOpts.ExtraArgs;
21882188
for (auto &entry : ExplicitClangModuleMap) {
21892189
const auto &moduleMapPath = entry.getValue().moduleMapPath;
2190-
if (!moduleMapPath.empty() &&
2191-
moduleMapsSeen.find(moduleMapPath) == moduleMapsSeen.end()) {
2192-
moduleMapsSeen.insert(moduleMapPath);
2193-
extraClangArgs.push_back(
2194-
(Twine("-fmodule-map-file=") + moduleMapPath).str());
2195-
}
2196-
21972190
const auto &modulePath = entry.getValue().modulePath;
21982191
if (!modulePath.empty()) {
21992192
extraClangArgs.push_back(
2200-
(Twine("-fmodule-file=") + entry.getKey() + "=" + modulePath)
2193+
(Twine("-fmodule-file=" + modulePath))
22012194
.str());
2202-
}
2195+
} else if (!moduleMapPath.empty() &&
2196+
moduleMapsSeen.find(moduleMapPath) == moduleMapsSeen.end()) {
2197+
moduleMapsSeen.insert(moduleMapPath);
2198+
extraClangArgs.push_back(
2199+
(Twine("-fmodule-map-file=") + moduleMapPath).str());
2200+
}
22032201
}
22042202
}
22052203

test/ScanDependencies/explicit-module-map-clang-explicit.swift

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// REQUIRES: objc_interop
12
// RUN: %empty-directory(%t)
23
// RUN: mkdir -p %t/clang-module-cache
34
// RUN: mkdir -p %t/inputs
@@ -19,18 +20,15 @@
1920
// RUN: echo "\"isFramework\": false" >> %/t/inputs/map.json
2021
// RUN: echo "}," >> %/t/inputs/map.json
2122
// RUN: echo "{" >> %/t/inputs/map.json
22-
// RUN: echo "\"moduleName\": \"_Concurrency\"," >> %/t/inputs/map.json
23-
// RUN: echo "\"modulePath\": \"%/concurrency_module\"," >> %/t/inputs/map.json
24-
// RUN: echo "\"isFramework\": false" >> %/t/inputs/map.json
25-
// RUN: echo "}," >> %/t/inputs/map.json
26-
// RUN: echo "{" >> %/t/inputs/map.json
27-
// RUN: echo "\"moduleName\": \"_StringProcessing\"," >> %/t/inputs/map.json
28-
// RUN: echo "\"modulePath\": \"%/string_processing_module\"," >> %/t/inputs/map.json
29-
// RUN: echo "\"isFramework\": false" >> %/t/inputs/map.json
23+
// RUN: echo "\"moduleName\": \"SwiftShims\"," >> %/t/inputs/map.json
24+
// RUN: echo "\"isFramework\": false," >> %/t/inputs/map.json
25+
// RUN: echo "\"clangModuleMapPath\": \"%swift-lib-dir/swift/shims/module.modulemap\"," >> %/t/inputs/map.json
26+
// RUN: echo "\"clangModulePath\": \"%t/inputs/SwiftShims.pcm\"" >> %/t/inputs/map.json
3027
// RUN: echo "}]" >> %/t/inputs/map.json
3128

29+
// RUN: %target-swift-emit-pcm -module-name SwiftShims %swift-lib-dir/swift/shims/module.modulemap -o %t/inputs/SwiftShims.pcm
3230
// RUN: %target-swift-emit-pcm -module-name A -o %t/inputs/A.pcm %S/Inputs/CHeaders/module.modulemap
33-
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/Foo.swiftmodule -module-cache-path %t.module-cache -explicit-swift-module-map-file %t/inputs/map.json %s
31+
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/Foo.swiftmodule -module-cache-path %t.module-cache -explicit-swift-module-map-file %t/inputs/map.json %s -disable-implicit-swift-modules -disable-implicit-concurrency-module-import -disable-implicit-string-processing-module-import
3432

3533
import A
3634

test/ScanDependencies/explicit-module-map-clang-implicit.swift

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// REQUIRES: objc_interop
12
// RUN: %empty-directory(%t)
23
// RUN: mkdir -p %t/clang-module-cache
34
// RUN: mkdir -p %t/inputs
@@ -18,17 +19,12 @@
1819
// RUN: echo "\"isFramework\": false" >> %/t/inputs/map.json
1920
// RUN: echo "}," >> %/t/inputs/map.json
2021
// RUN: echo "{" >> %/t/inputs/map.json
21-
// RUN: echo "\"moduleName\": \"_Concurrency\"," >> %/t/inputs/map.json
22-
// RUN: echo "\"modulePath\": \"%/concurrency_module\"," >> %/t/inputs/map.json
23-
// RUN: echo "\"isFramework\": false" >> %/t/inputs/map.json
24-
// RUN: echo "}," >> %/t/inputs/map.json
25-
// RUN: echo "{" >> %/t/inputs/map.json
26-
// RUN: echo "\"moduleName\": \"_StringProcessing\"," >> %/t/inputs/map.json
27-
// RUN: echo "\"modulePath\": \"%/string_processing_module\"," >> %/t/inputs/map.json
28-
// RUN: echo "\"isFramework\": false" >> %/t/inputs/map.json
22+
// RUN: echo "\"moduleName\": \"SwiftShims\"," >> %/t/inputs/map.json
23+
// RUN: echo "\"isFramework\": false," >> %/t/inputs/map.json
24+
// RUN: echo "\"clangModuleMapPath\": \"%swift-lib-dir/swift/shims/module.modulemap\"," >> %/t/inputs/map.json
2925
// RUN: echo "}]" >> %/t/inputs/map.json
3026

31-
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/Foo.swiftmodule -module-cache-path %t.module-cache -explicit-swift-module-map-file %t/inputs/map.json %s
27+
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/Foo.swiftmodule -module-cache-path %t.module-cache -explicit-swift-module-map-file %t/inputs/map.json %s -disable-implicit-concurrency-module-import -disable-implicit-string-processing-module-import
3228

3329
import A
3430

test/ScanDependencies/explicit-swift-dependencies.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,5 @@ import F
5151
// CHECK-NEXT: "{{.*}}{{/|\\}}F-{{.*}}.swiftmodule"
5252
// CHECK-DAG: "-swift-module-file=Swift={{.*}}{{/|\\}}Swift-{{.*}}.swiftmodule"
5353
// CHECK-DAG: "-swift-module-file=SwiftOnoneSupport={{.*}}{{/|\\}}SwiftOnoneSupport-{{.*}}.swiftmodule"
54-
// CHECK-DAG: "-fmodule-file=F={{.*}}{{/|\\}}F-{{.*}}.pcm",
55-
// CHECK-DAG: "-fmodule-file=SwiftShims={{.*}}{{/|\\}}SwiftShims-{{.*}}.pcm",
54+
// CHECK-DAG: "-fmodule-file={{.*}}{{/|\\}}F-{{.*}}.pcm"
55+
// CHECK-DAG: "-fmodule-file={{.*}}{{/|\\}}SwiftShims-{{.*}}.pcm"

0 commit comments

Comments
 (0)