Skip to content

Commit 6c1b3cc

Browse files
Merge pull request #76020 from rastogishubham/FixReplay
Add MCCAS support to SwiftCaching.cpp
2 parents 8eb583c + 2458226 commit 6c1b3cc

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

test/CAS/swift-scan-test-mccas.swift

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// REQUIRES: OS=macosx
2+
// RUN: %empty-directory(%t)
3+
4+
// RUN: %target-swift-frontend -scan-dependencies -module-name Test -O \
5+
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -parse-stdlib \
6+
// RUN: %s -o %t/deps.json -swift-version 5 -cache-compile-job -cas-backend -cas-backend-mode=verify -cas-path %t/cas
7+
8+
// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps.json Test > %t/MyApp.cmd
9+
// RUN: echo "\"-disable-implicit-string-processing-module-import\"" >> %t/MyApp.cmd
10+
// RUN: echo "\"-disable-implicit-concurrency-module-import\"" >> %t/MyApp.cmd
11+
// RUN: echo "\"-parse-stdlib\"" >> %t/MyApp.cmd
12+
13+
// RUN: %swift-scan-test -action compute_cache_key -cas-path %t/cas -input %s -- %target-swift-frontend -cache-compile-job -cas-backend -cas-backend-mode=verify -Rcache-compile-job %s \
14+
// RUN: -emit-module -emit-module-path %t/Test.swiftmodule -c -emit-dependencies -module-name Test -o %t/test.o -cas-path %t/cas \
15+
// RUN: @%t/MyApp.cmd > %t/key.casid
16+
17+
// RUN: %target-swift-frontend -cache-compile-job -cas-backend -cas-backend-mode=verify -Rcache-compile-job %s -emit-module -emit-module-path %t/Test.swiftmodule -c -emit-dependencies \
18+
// RUN: -module-name Test -o %t/test.o -cas-path %t/cas @%t/MyApp.cmd
19+
20+
// RUN: %swift-scan-test -action cache_query -id @%t/key.casid -cas-path %t/cas | %FileCheck %s --check-prefix=CHECK-QUERY
21+
22+
// RUN: %swift-scan-test -action replay_result -cas-path %t/cas -id @%t/key.casid -- %target-swift-frontend -cache-compile-job -cas-backend -cas-backend-mode=verify -Rcache-compile-job %s \
23+
// RUN: -emit-module -emit-module-path %t/Test2.swiftmodule -c -emit-dependencies -module-name Test -o %t/test2.o -cas-path %t/cas \
24+
// RUN: @%t/MyApp.cmd
25+
26+
// RUN: diff %t/Test.swiftmodule %t/Test2.swiftmodule
27+
// RUN: diff %t/test.o %t/test2.o
28+
29+
// CHECK-QUERY: Cached Compilation for key "llvmcas://{{.*}}" has 4 outputs:
30+
// CHECK-QUERY-NEXT: object: llvmcas://
31+
// CHECK-QUERY-NEXT: dependencies: llvmcas://
32+
// CHECK-QUERY-NEXT: swiftmodule: llvmcas://
33+
// CHECK-QUERY-NEXT: cached-diagnostics: llvmcas://
34+
35+
func testFunc() {}

tools/libSwiftScan/SwiftCaching.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "llvm/CAS/BuiltinUnifiedCASDatabases.h"
4040
#include "llvm/CAS/CASReference.h"
4141
#include "llvm/CAS/ObjectStore.h"
42+
#include "llvm/MCCAS/MCCASObjectV1.h"
4243
#include "llvm/Support/Allocator.h"
4344
#include "llvm/Support/Endian.h"
4445
#include "llvm/Support/Error.h"
@@ -940,6 +941,8 @@ static llvm::Error replayCompilation(SwiftScanReplayInstance &Instance,
940941
};
941942
SmallVector<OutputEntry> OutputProxies;
942943
std::optional<llvm::cas::ObjectProxy> DiagnosticsOutput;
944+
bool UseCASBackend = Invocation.getIRGenOptions().UseCASBackend;
945+
std::string ObjFile;
943946

944947
swift::cas::CachedResultLoader Loader(CAS, Comp.Output);
945948
if (auto Err = Loader.replay(
@@ -953,6 +956,9 @@ static llvm::Error replayCompilation(SwiftScanReplayInstance &Instance,
953956
if (!Proxy)
954957
return Proxy.takeError();
955958

959+
if (Kind == file_types::ID::TY_Object && UseCASBackend)
960+
ObjFile = OutputPath->second;
961+
956962
if (Kind == file_types::ID::TY_CachedDiagnostics) {
957963
assert(!DiagnosticsOutput && "more than 1 diagnostics found");
958964
DiagnosticsOutput = std::move(*Proxy);
@@ -1000,8 +1006,13 @@ static llvm::Error replayCompilation(SwiftScanReplayInstance &Instance,
10001006
auto File = Backend.createFile(Output.Path);
10011007
if (!File)
10021008
return File.takeError();
1003-
1004-
*File << Output.Proxy.getData();
1009+
if (UseCASBackend && Output.Path == ObjFile) {
1010+
auto Schema = std::make_unique<llvm::mccasformats::v1::MCSchema>(CAS);
1011+
if (auto E = Schema->serializeObjectFile(Output.Proxy, *File))
1012+
Inst.getDiags().diagnose(SourceLoc(), diag::error_mccas,
1013+
toString(std::move(E)));
1014+
} else
1015+
*File << Output.Proxy.getData();
10051016
if (auto E = File->keep())
10061017
return E;
10071018

0 commit comments

Comments
 (0)