Skip to content

Commit 1ababc0

Browse files
[Caching] Fix versioned canImport check for swift module
Fix the ExplicitCASModuleLoader check for if `canImport` works for a specific swift module. It was mistakenly using the clang caching schema to load the underlying module but in reality, it should only load swift module with swift caching schema. In future, we should let dependency scanner to report version/underlying version for the modules it enounters so the versioned canImport check doesn't need to load and parse the module/TBD file to figure out if the check is successful or not. rdar://120554271
1 parent 29cfe61 commit 1ababc0

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "swift/Basic/Platform.h"
2323
#include "swift/Basic/StringExtras.h"
2424
#include "swift/Frontend/CachingUtils.h"
25+
#include "swift/Frontend/CompileJobCacheResult.h"
2526
#include "swift/Frontend/Frontend.h"
2627
#include "swift/Frontend/ModuleInterfaceSupport.h"
2728
#include "swift/Parse/ParseVersion.h"
@@ -2446,12 +2447,19 @@ struct ExplicitCASModuleLoader::Implementation {
24462447
if (!moduleRef)
24472448
return nullptr;
24482449

2449-
clang::cas::CompileJobResultSchema schema(CAS);
2450+
auto proxy = CAS.getProxy(*moduleRef);
2451+
if (!proxy)
2452+
return proxy.takeError();
2453+
2454+
swift::cas::CompileJobResultSchema schema(CAS);
2455+
if (!schema.isRootNode(*proxy))
2456+
return nullptr;
2457+
24502458
auto result = schema.load(*moduleRef);
24512459
if (!result)
24522460
return result.takeError();
2453-
auto output = result->getOutput(
2454-
clang::cas::CompileJobCacheResult::OutputKind::MainOutput);
2461+
2462+
auto output = result->getOutput(file_types::ID::TY_SwiftModuleFile);
24552463
if (!output)
24562464
return nullptr;
24572465

test/CAS/can-import.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps.json clang:B > %t/B.cmd
1515
// RUN: %swift_frontend_plain @%t/B.cmd
1616

17+
// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps.json C > %t/C.cmd
18+
// RUN: %swift_frontend_plain @%t/C.cmd
19+
1720
// RUN: %{python} %S/Inputs/GenerateExplicitModuleMap.py %t/deps.json > %t/map.json
1821
// RUN: llvm-cas --cas %t/cas --make-blob --data %t/map.json > %t/map.casid
1922

@@ -38,9 +41,18 @@ import A.Missing
3841
func b() {}
3942
#endif
4043

44+
#if canImport(C, _version: 1.0)
45+
import C
46+
#endif
47+
48+
#if canImport(C, _version: 2.0)
49+
import Missing
50+
#endif
51+
4152
func useA() {
4253
a()
4354
b()
55+
c()
4456
}
4557

4658
//--- include/module.modulemap
@@ -61,3 +73,8 @@ void notused(void);
6173

6274
//--- include/B.h
6375
void notused2(void);
76+
77+
//--- include/C.swiftinterface
78+
// swift-interface-format-version: 1.0
79+
// swift-module-flags: -module-name C -O -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -parse-stdlib -user-module-version 1.0
80+
public func c() { }

0 commit comments

Comments
 (0)