Skip to content

Commit 73cfe34

Browse files
committed
Allow -explicit-swift-module-map-file without full explicit module build
This enables the use of `-explicit-swift-module-map-file` for some modules in the build, while still loading implicit modules as before. This is useful to improve the performance of builds with many modules to avoid searching many different directories pass with `-I`. Previously VFS overlays could be used for this use case as well, but it seems valuable to unify on the same infrastructure used for explicit module builds.
1 parent 3ee6325 commit 73cfe34

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

lib/Frontend/Frontend.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,15 +556,17 @@ bool CompilerInstance::setUpModuleLoaders() {
556556
// If implicit modules are disabled, we need to install an explicit module
557557
// loader.
558558
bool ExplicitModuleBuild = Invocation.getFrontendOptions().DisableImplicitModules;
559-
if (ExplicitModuleBuild) {
559+
if (ExplicitModuleBuild || !Invocation.getSearchPathOptions().ExplicitSwiftModuleMap.empty()) {
560560
auto ESML = ExplicitSwiftModuleLoader::create(
561561
*Context,
562562
getDependencyTracker(), MLM,
563563
Invocation.getSearchPathOptions().ExplicitSwiftModuleMap,
564564
IgnoreSourceInfoFile);
565565
this->DefaultSerializedLoader = ESML.get();
566566
Context->addModuleLoader(std::move(ESML));
567-
} else {
567+
}
568+
569+
if (!ExplicitModuleBuild) {
568570
if (MLM != ModuleLoadingMode::OnlySerialized) {
569571
// We only need ModuleInterfaceLoader for implicit modules.
570572
auto PIML = ModuleInterfaceLoader::create(
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: mkdir -p %t/clang-module-cache
3+
// RUN: mkdir -p %t/inputs
4+
// RUN: mkdir -p %t/barinputs
5+
// RUN: echo "public func foo() {}" >> %t/foo.swift
6+
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/inputs/Foo.swiftmodule -emit-module-doc-path %t/inputs/Foo.swiftdoc -emit-module-source-info -emit-module-source-info-path %t/inputs/Foo.swiftsourceinfo -module-cache-path %t.module-cache %t/foo.swift -module-name Foo
7+
// RUN: echo "public func bar() {}" >> %t/bar.swift
8+
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/barinputs/Bar.swiftmodule -emit-module-doc-path %t/barinputs/Bar.swiftdoc -emit-module-source-info -emit-module-source-info-path %t/barinputs/Bar.swiftsourceinfo -module-cache-path %t.module-cache %t/bar.swift -module-name Bar
9+
10+
// RUN: echo "[{" > %/t/inputs/map.json
11+
// RUN: echo "\"moduleName\": \"Foo\"," >> %/t/inputs/map.json
12+
// RUN: echo "\"modulePath\": \"%/t/inputs/Foo.swiftmodule\"," >> %/t/inputs/map.json
13+
// RUN: echo "\"docPath\": \"%/t/inputs/Foo.swiftdoc\"," >> %/t/inputs/map.json
14+
// RUN: echo "\"sourceInfoPath\": \"%/t/inputs/Foo.swiftsourceinfo\"," >> %/t/inputs/map.json
15+
// RUN: echo "\"isFramework\": false" >> %/t/inputs/map.json
16+
// RUN: echo "}]" >> %/t/inputs/map.json
17+
18+
// RUN: not %target-swift-frontend -typecheck %s -explicit-swift-module-map-file %t/inputs/map.json -disable-implicit-swift-modules
19+
// RUN: %target-swift-frontend -typecheck %s -explicit-swift-module-map-file %t/inputs/map.json -I %t/barinputs
20+
import Foo
21+
import Bar

0 commit comments

Comments
 (0)