Skip to content

Commit d3ecf88

Browse files
authored
Merge pull request #32991 from nkcsgexi/explicit-module-map-forwarding-module
ExplicitModuleLoader: teach the module loader to accept forwarding modules
2 parents 909e22f + 9a33ac6 commit d3ecf88

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1654,6 +1654,31 @@ std::error_code ExplicitSwiftModuleLoader::findModuleFilesInDirectory(
16541654
moduleInfo.modulePath);
16551655
return moduleBuf.getError();
16561656
}
1657+
1658+
assert(moduleBuf);
1659+
const bool isForwardingModule = !serialization::isSerializedAST(moduleBuf
1660+
.get()->getBuffer());
1661+
// If the module is a forwarding module, read the actual content from the path
1662+
// encoded in the forwarding module as the actual module content.
1663+
if (isForwardingModule) {
1664+
auto forwardingModule = ForwardingModule::load(*moduleBuf.get());
1665+
if (forwardingModule) {
1666+
moduleBuf = fs.getBufferForFile(forwardingModule->underlyingModulePath);
1667+
if (!moduleBuf) {
1668+
// We cannot read the module content, diagnose.
1669+
Ctx.Diags.diagnose(SourceLoc(), diag::error_opening_explicit_module_file,
1670+
moduleInfo.modulePath);
1671+
return moduleBuf.getError();
1672+
}
1673+
} else {
1674+
// We cannot read the module content, diagnose.
1675+
Ctx.Diags.diagnose(SourceLoc(), diag::error_opening_explicit_module_file,
1676+
moduleInfo.modulePath);
1677+
return forwardingModule.getError();
1678+
}
1679+
}
1680+
assert(moduleBuf);
1681+
// Move the opened module buffer to the caller.
16571682
*ModuleBuffer = std::move(moduleBuf.get());
16581683

16591684
// Open .swiftdoc file
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: mkdir -p %t/clang-module-cache
3+
// RUN: mkdir -p %t/inputs
4+
// RUN: echo "/// Some cool comments" > %t/foo.swift
5+
// RUN: echo "public func foo() {}" >> %t/foo.swift
6+
7+
// Step 1: build .swiftmodule and .swiftinterface adjacent to each other from foo.swift
8+
// 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 -emit-module-interface-path %t/inputs/Foo.swiftinterface -module-cache-path %t.module-cache %t/foo.swift -module-name Foo
9+
10+
// Step 2: build .swiftmodule from .swiftinterface and give the adjacent .swiftmodule as a candidate compiled module.
11+
// RUN: %target-swift-frontend -compile-module-from-interface %t/inputs/Foo.swiftinterface -o %t/inputs/Foo-from-interface.swiftmodule -module-name Foo -candidate-module-file %t/inputs/Foo.swiftmodule
12+
13+
// Step 3: the new .swiftmodule should be a fowarding module.
14+
// RUN: %{python} %S/../ModuleInterface/ModuleCache/Inputs/check-is-forwarding-module.py %t/inputs/Foo-from-interface.swiftmodule
15+
16+
// Step 4: using the forwarding module in explicit module map should be OK.
17+
// RUN: echo "[{" > %/t/inputs/map.json
18+
// RUN: echo "\"moduleName\": \"Foo\"," >> %/t/inputs/map.json
19+
// RUN: echo "\"modulePath\": \"%/t/inputs/Foo-from-interface.swiftmodule\"," >> %/t/inputs/map.json
20+
// RUN: echo "\"docPath\": \"%/t/inputs/Foo.swiftdoc\"," >> %/t/inputs/map.json
21+
// RUN: echo "\"sourceInfoPath\": \"%/t/inputs/Foo.swiftsourceinfo\"" >> %/t/inputs/map.json
22+
// RUN: echo "}]" >> %/t/inputs/map.json
23+
24+
// RUN: %target-swift-ide-test -print-module-comments -module-to-print=Foo -enable-swiftsourceinfo -source-filename %s -explicit-swift-module-map-file %t/inputs/map.json | %FileCheck %s
25+
26+
// CHECK: foo.swift:2:13: Func/foo RawComment=[/// Some cool comments

0 commit comments

Comments
 (0)