Skip to content

[Caching] Fix versioned canImport check for swift module #71260

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions lib/Frontend/ModuleInterfaceLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "swift/Basic/Platform.h"
#include "swift/Basic/StringExtras.h"
#include "swift/Frontend/CachingUtils.h"
#include "swift/Frontend/CompileJobCacheResult.h"
#include "swift/Frontend/Frontend.h"
#include "swift/Frontend/ModuleInterfaceSupport.h"
#include "swift/Parse/ParseVersion.h"
Expand Down Expand Up @@ -2446,12 +2447,19 @@ struct ExplicitCASModuleLoader::Implementation {
if (!moduleRef)
return nullptr;

clang::cas::CompileJobResultSchema schema(CAS);
auto proxy = CAS.getProxy(*moduleRef);
if (!proxy)
return proxy.takeError();

swift::cas::CompileJobResultSchema schema(CAS);
if (!schema.isRootNode(*proxy))
return nullptr;

auto result = schema.load(*moduleRef);
if (!result)
return result.takeError();
auto output = result->getOutput(
clang::cas::CompileJobCacheResult::OutputKind::MainOutput);

auto output = result->getOutput(file_types::ID::TY_SwiftModuleFile);
if (!output)
return nullptr;

Expand Down
17 changes: 17 additions & 0 deletions test/CAS/can-import.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps.json clang:B > %t/B.cmd
// RUN: %swift_frontend_plain @%t/B.cmd

// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps.json C > %t/C.cmd
// RUN: %swift_frontend_plain @%t/C.cmd

// RUN: %{python} %S/Inputs/GenerateExplicitModuleMap.py %t/deps.json > %t/map.json
// RUN: llvm-cas --cas %t/cas --make-blob --data %t/map.json > %t/map.casid

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

#if canImport(C, _version: 1.0)
import C
#endif

#if canImport(C, _version: 2.0)
import Missing
#endif

func useA() {
a()
b()
c()
}

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

//--- include/B.h
void notused2(void);

//--- include/C.swiftinterface
// swift-interface-format-version: 1.0
// 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
public func c() { }