Skip to content

Commit 22d39e9

Browse files
committed
[Explicit Moduele Builds] Look through forwarding modules for 'canImport' version check.
Otherwise we default to version 0 for all modules which get forwarded. Resolves rdar://119346213
1 parent f5e2b24 commit 22d39e9

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2246,6 +2246,21 @@ bool ExplicitSwiftModuleLoader::canImportModule(
22462246
it->second.modulePath);
22472247
return false;
22482248
}
2249+
2250+
// If it's a forwarding module, load the YAML file from disk and get the path
2251+
// to the actual module for the version check.
2252+
if (!serialization::isSerializedAST((*moduleBuf)->getBuffer())) {
2253+
if (auto forwardingModule = ForwardingModule::load(**moduleBuf)) {
2254+
moduleBuf = fs.getBufferForFile(forwardingModule->underlyingModulePath);
2255+
if (!moduleBuf) {
2256+
Ctx.Diags.diagnose(SourceLoc(),
2257+
diag::error_opening_explicit_module_file,
2258+
forwardingModule->underlyingModulePath);
2259+
return false;
2260+
}
2261+
}
2262+
}
2263+
22492264
auto metaData = serialization::validateSerializedAST(
22502265
(*moduleBuf)->getBuffer(), Ctx.SILOpts.EnableOSSAModules,
22512266
Ctx.LangOpts.SDKName, !Ctx.LangOpts.DebuggerSupport);
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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 -user-module-version 9001
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/ForwardingFoo.swiftmodule
11+
// RUN: echo "path: '%/t/inputs/Foo.swiftmodule'" >> %t/inputs/ForwardingFoo.swiftmodule
12+
// RUN: echo "dependencies: []" >> %t/inputs/ForwardingFoo.swiftmodule
13+
// RUN: echo "version: 1 " >> %t/inputs/ForwardingFoo.swiftmodule
14+
// RUN: echo "..." >> %t/inputs/ForwardingFoo.swiftmodule
15+
16+
// RUN: echo "[{" > %/t/inputs/map.json
17+
// RUN: echo "\"moduleName\": \"Foo\"," >> %/t/inputs/map.json
18+
// RUN: echo "\"modulePath\": \"%/t/inputs/ForwardingFoo.swiftmodule\"," >> %/t/inputs/map.json
19+
// RUN: echo "\"docPath\": \"%/t/inputs/Foo.swiftdoc\"," >> %/t/inputs/map.json
20+
// RUN: echo "\"sourceInfoPath\": \"%/t/inputs/Foo.swiftsourceinfo\"," >> %/t/inputs/map.json
21+
// RUN: echo "\"isFramework\": false" >> %/t/inputs/map.json
22+
// RUN: echo "}]" >> %/t/inputs/map.json
23+
24+
// RUN: not %target-swift-frontend -typecheck %s -explicit-swift-module-map-file %t/inputs/map.json -disable-implicit-swift-modules
25+
// RUN: %target-swift-frontend -typecheck %s -explicit-swift-module-map-file %t/inputs/map.json -I %t/barinputs -Rmodule-loading 2>&1 | %FileCheck -check-prefix=POSITIVE-CHECK %s
26+
27+
#if canImport(Foo, _version: 9000)
28+
import Bar
29+
#endif
30+
31+
// 'Bar' can only be imported if the explicitly-loaded 'Foo' is known to be over 9000
32+
// POSITIVE-CHECK: remark: loaded module 'Bar'
33+
34+
// Re-build Foo with a lower version and ensure we do not import `Bar`
35+
// 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 -user-module-version 7000
36+
// RUN: %target-swift-frontend -typecheck %s -explicit-swift-module-map-file %t/inputs/map.json -I %t/barinputs -Rmodule-loading 2>&1 | %FileCheck -check-prefix=NEGATIVE-CHECK %s
37+
38+
// 'Bar' can only be imported if the explicitly-loaded 'Foo' is known to be over 9000
39+
// NEGATIVE-CHECK-NOT: remark: loaded module 'Bar'

0 commit comments

Comments
 (0)