Skip to content

Commit 9120a53

Browse files
Merge pull request #84960 from cachemeifyoucan/eng/cas-fs-for-11638
[CAS] Update swift CAS file system usage after llvm-project change
2 parents 6fb1773 + 1beef99 commit 9120a53

File tree

5 files changed

+28
-22
lines changed

5 files changed

+28
-22
lines changed

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ GROUPED_ERROR(error_invalid_cas_id, CompilationCaching, none, "CAS cannot parse
527527
GROUPED_ERROR(error_cas, CompilationCaching, none, "CAS error encountered during %0: %1", (StringRef, StringRef))
528528
GROUPED_ERROR(error_cas_fs_creation, CompilationCaching, none, "cannot create CAS filesystem: %0", (StringRef))
529529
GROUPED_ERROR(error_cache_key_creation, CompilationCaching, none, "cannot create cache key for compilation %0: %1", (StringRef, StringRef))
530-
GROUPED_ERROR(error_cas_file_ref, CompilationCaching, none, "cannot load file %0 from CAS filesystem", (StringRef))
530+
GROUPED_ERROR(error_cas_file_ref, CompilationCaching, none, "cannot load file %0 from CAS filesystem: %1", (StringRef, StringRef))
531531
GROUPED_ERROR(error_cas_conflict_options, CompilationCaching, none, "cannot setup CAS due to conflicting '-cas-*' options", ())
532532
GROUPED_ERROR(error_cas_initialization, CompilationCaching, none, "CAS cannot be initialized from the specified '-cas-*' options: %0", (StringRef))
533533
GROUPED_ERROR(error_cas_malformed_input, CompilationCaching, none, "CAS input '%0' is malformed: %1", (StringRef, StringRef))

include/swift/DependencyScan/ModuleDependencyScanner.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "swift/Serialization/ScanningLoaders.h"
1818
#include "clang/Tooling/DependencyScanning/DependencyScanningTool.h"
1919
#include "llvm/CAS/CASReference.h"
20+
#include "llvm/CAS/CASFileSystem.h"
2021
#include "llvm/Support/ThreadPool.h"
2122

2223
namespace swift {
@@ -249,7 +250,7 @@ class ModuleDependencyScanner {
249250
return *CAS;
250251
}
251252

252-
llvm::vfs::FileSystem &getSharedCachingFS() const {
253+
llvm::cas::CASBackedFileSystem &getSharedCachingFS() const {
253254
assert(CacheFS && "Expect CacheFS available");
254255
return *CacheFS;
255256
}
@@ -358,7 +359,7 @@ class ModuleDependencyScanner {
358359
/// File prefix mapper.
359360
std::unique_ptr<llvm::PrefixMapper> PrefixMapper;
360361
/// CAS file system for loading file content.
361-
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> CacheFS;
362+
llvm::IntrusiveRefCntPtr<llvm::cas::CASBackedFileSystem> CacheFS;
362363
/// Protect worker access.
363364
std::mutex WorkersLock;
364365
/// Count of filesystem queries performed

lib/DependencyScan/ModuleDependencyScanner.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -436,12 +436,14 @@ SwiftDependencyTracker::SwiftDependencyTracker(
436436
auto status = (*file)->status();
437437
if (!status)
438438
return;
439-
auto fileRef = (*file)->getObjectRefForContent();
440-
if (!fileRef)
439+
440+
auto casFile = dyn_cast<llvm::cas::CASBackedFile>(*file);
441+
if (!casFile)
441442
return;
442443

444+
auto fileRef = casFile->getObjectRefForContent();
443445
std::string realPath = Mapper ? Mapper->mapToString(path) : path.str();
444-
CommonFiles.try_emplace(realPath, **fileRef, (size_t)status->getSize());
446+
CommonFiles.try_emplace(realPath, fileRef, (size_t)status->getSize());
445447
};
446448

447449
// Add SDKSetting file.
@@ -493,12 +495,13 @@ void SwiftDependencyTracker::trackFile(const Twine &path) {
493495
auto status = (*file)->status();
494496
if (!status)
495497
return;
496-
auto fileRef = (*file)->getObjectRefForContent();
497-
if (!fileRef)
498+
auto CASFile = dyn_cast<llvm::cas::CASBackedFile>(*file);
499+
if (!CASFile)
498500
return;
501+
auto fileRef = CASFile->getObjectRefForContent();
499502
std::string realPath =
500503
Mapper ? Mapper->mapToString(path.str()) : path.str();
501-
TrackedFiles.try_emplace(realPath, **fileRef, (size_t)status->getSize());
504+
TrackedFiles.try_emplace(realPath, fileRef, (size_t)status->getSize());
502505
}
503506

504507
llvm::Expected<llvm::cas::ObjectProxy>
@@ -557,8 +560,9 @@ ModuleDependencyScanner::ModuleDependencyScanner(
557560
}
558561

559562
if (CAS)
560-
CacheFS = llvm::cas::createCASProvidingFileSystem(
561-
CAS, ScanASTContext.SourceMgr.getFileSystem());
563+
CacheFS = cast<llvm::cas::CASBackedFileSystem>(
564+
llvm::cas::createCASProvidingFileSystem(
565+
CAS, ScanASTContext.SourceMgr.getFileSystem()));
562566

563567
// TODO: Make num threads configurable
564568
for (size_t i = 0; i < NumThreads; ++i)

lib/DependencyScan/ScanDependencies.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -549,22 +549,22 @@ class ExplicitModuleDependencyResolver {
549549
// action cache. We just use the CASID of the binary module itself as key.
550550
auto Ref = CASFS.getObjectRefForFileContent(path);
551551
if (!Ref) {
552-
instance.getDiags().diagnose(SourceLoc(), diag::error_cas_file_ref, path);
552+
instance.getDiags().diagnose(SourceLoc(), diag::error_cas_file_ref, path,
553+
toString(Ref.takeError()));
553554
return true;
554555
}
555-
assert(*Ref && "Binary module should be loaded into CASFS already");
556-
depInfo.updateModuleCacheKey(CAS.getID(**Ref).toString());
556+
depInfo.updateModuleCacheKey(CAS.getID(*Ref).toString());
557557

558558
swift::cas::CompileJobCacheResult::Builder Builder;
559-
Builder.addOutput(file_types::ID::TY_SwiftModuleFile, **Ref);
559+
Builder.addOutput(file_types::ID::TY_SwiftModuleFile, *Ref);
560560
auto Result = Builder.build(CAS);
561561
if (!Result) {
562562
instance.getDiags().diagnose(SourceLoc(), diag::error_cas,
563563
"adding binary module dependencies",
564564
toString(Result.takeError()));
565565
return true;
566566
}
567-
if (auto E = instance.getActionCache().put(CAS.getID(**Ref),
567+
if (auto E = instance.getActionCache().put(CAS.getID(*Ref),
568568
CAS.getID(*Result))) {
569569
instance.getDiags().diagnose(
570570
SourceLoc(), diag::error_cas,

lib/Frontend/CachedDiagnostics.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "llvm/ADT/StringExtras.h"
3131
#include "llvm/ADT/StringRef.h"
3232
#include "llvm/ADT/TinyPtrVector.h"
33+
#include "llvm/CAS/CASFileSystem.h"
3334
#include "llvm/CAS/ObjectStore.h"
3435
#include "llvm/Support/Compression.h"
3536
#include "llvm/Support/Debug.h"
@@ -643,13 +644,13 @@ DiagnosticSerializer::serializeEmittedDiagnostics(llvm::raw_ostream &os) {
643644
if (!File.Content.empty() || !File.ContentCASID.empty())
644645
continue;
645646

646-
auto Ref =
647-
SrcMgr.getFileSystem()->getObjectRefForFileContent(File.FileName);
648-
if (!Ref)
649-
return llvm::createFileError(File.FileName, Ref.getError());
647+
if (auto CASFS =
648+
dyn_cast<llvm::cas::CASBackedFileSystem>(SrcMgr.getFileSystem())) {
649+
auto Ref = CASFS->getObjectRefForFileContent(File.FileName);
650+
if (!Ref)
651+
return Ref.takeError();
650652

651-
if (*Ref) {
652-
File.ContentCASID = CAS.getID(**Ref).toString();
653+
File.ContentCASID = CAS.getID(*Ref).toString();
653654
continue;
654655
}
655656

0 commit comments

Comments
 (0)