Skip to content

Commit f2ef2d3

Browse files
Merge pull request #81494 from cachemeifyoucan/eng/PR-remove-clang-module-cas-fs
[Caching] Remove CASFS based clang module implementation
2 parents 0777dbd + 1506a0d commit f2ef2d3

22 files changed

+115
-439
lines changed

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ REMARK(matching_output_produced,none,
520520

521521
// Caching related diagnostics
522522
ERROR(error_caching_no_cas_fs, none,
523-
"caching is enabled without -cas-fs option, input is not immutable", ())
523+
"caching is enabled without CAS file-system options, input is not immutable", ())
524524
ERROR(error_prefix_mapping, none, "cannot create scanner prefix mapping: '%0'", (StringRef))
525525

526526
REMARK(replay_output, none, "replay output file '%0': key '%1'", (StringRef, StringRef))

include/swift/AST/ModuleDependencies.h

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,7 @@ using ModuleDependenciesKindMap =
10001000
/// Track swift dependency
10011001
class SwiftDependencyTracker {
10021002
public:
1003-
SwiftDependencyTracker(llvm::cas::CachingOnDiskFileSystem &FS,
1003+
SwiftDependencyTracker(std::shared_ptr<llvm::cas::ObjectStore> CAS,
10041004
llvm::PrefixMapper *Mapper,
10051005
const CompilerInvocation &CI);
10061006

@@ -1009,7 +1009,8 @@ class SwiftDependencyTracker {
10091009
llvm::Expected<llvm::cas::ObjectProxy> createTreeFromDependencies();
10101010

10111011
private:
1012-
llvm::IntrusiveRefCntPtr<llvm::cas::CachingOnDiskFileSystem> FS;
1012+
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS;
1013+
std::shared_ptr<llvm::cas::ObjectStore> CAS;
10131014
llvm::PrefixMapper *Mapper;
10141015

10151016
struct FileEntry {
@@ -1035,10 +1036,7 @@ class SwiftDependencyScanningService {
10351036
ClangScanningService;
10361037

10371038
/// CachingOnDiskFileSystem for dependency tracking.
1038-
llvm::IntrusiveRefCntPtr<llvm::cas::CachingOnDiskFileSystem> CacheFS;
1039-
1040-
/// If use clang include tree.
1041-
bool UseClangIncludeTree = false;
1039+
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> CacheFS;
10421040

10431041
/// CAS Instance.
10441042
std::shared_ptr<llvm::cas::ObjectStore> CAS;
@@ -1076,8 +1074,8 @@ class SwiftDependencyScanningService {
10761074
return *SharedFilesystemCache;
10771075
}
10781076

1079-
llvm::cas::CachingOnDiskFileSystem &getSharedCachingFS() const {
1080-
assert(CacheFS && "Expect CachingOnDiskFileSystem");
1077+
llvm::vfs::FileSystem &getSharedCachingFS() const {
1078+
assert(CacheFS && "Expect a CASFileSystem");
10811079
return *CacheFS;
10821080
}
10831081

@@ -1088,20 +1086,17 @@ class SwiftDependencyScanningService {
10881086

10891087
std::optional<SwiftDependencyTracker>
10901088
createSwiftDependencyTracker(const CompilerInvocation &CI) {
1091-
if (!CacheFS)
1089+
if (!CAS)
10921090
return std::nullopt;
10931091

1094-
return SwiftDependencyTracker(*CacheFS, Mapper.get(), CI);
1092+
return SwiftDependencyTracker(CAS, Mapper.get(), CI);
10951093
}
10961094

10971095
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> getClangScanningFS() const {
1098-
if (UseClangIncludeTree)
1096+
if (CAS)
10991097
return llvm::cas::createCASProvidingFileSystem(
11001098
CAS, llvm::vfs::createPhysicalFileSystem());
11011099

1102-
if (CacheFS)
1103-
return CacheFS->createProxyFS();
1104-
11051100
return llvm::vfs::createPhysicalFileSystem();
11061101
}
11071102

include/swift/Basic/CASOptions.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ class CASOptions final {
3737
/// CASOptions
3838
clang::CASOptions CASOpts;
3939

40-
/// CASFS Root.
41-
std::vector<std::string> CASFSRootIDs;
42-
4340
/// Clang Include Trees.
4441
std::string ClangIncludeTree;
4542

@@ -62,9 +59,8 @@ class CASOptions final {
6259
/// Check to see if a CASFileSystem is required.
6360
bool requireCASFS() const {
6461
return EnableCaching &&
65-
(!CASFSRootIDs.empty() || !ClangIncludeTree.empty() ||
66-
!ClangIncludeTreeFileList.empty() || !InputFileKey.empty() ||
67-
!BridgingHeaderPCHCacheKey.empty());
62+
(!ClangIncludeTree.empty() || !ClangIncludeTreeFileList.empty() ||
63+
!InputFileKey.empty() || !BridgingHeaderPCHCacheKey.empty());
6864
}
6965

7066
/// Return a hash code of any components from these options that should

include/swift/Basic/LangOptions.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,12 +1094,6 @@ namespace swift {
10941094
/// built and provided to the compiler invocation.
10951095
bool DisableImplicitClangModules = false;
10961096

1097-
/// Enable ClangIncludeTree for explicit module builds scanning.
1098-
bool UseClangIncludeTree = false;
1099-
1100-
/// Using ClangIncludeTreeRoot for compilation.
1101-
bool HasClangIncludeTreeRoot = false;
1102-
11031097
/// Whether the dependency scanner should construct all swift-frontend
11041098
/// invocations directly from clang cc1 args.
11051099
bool ClangImporterDirectCC1Scan = false;

include/swift/ClangImporter/ClangImporter.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -474,11 +474,6 @@ class ClangImporter final : public ClangModuleLoader {
474474
/// Reads the original source file name from PCH.
475475
std::string getOriginalSourceFile(StringRef PCHFilename);
476476

477-
/// Add clang dependency file names.
478-
///
479-
/// \param files The list of file to append dependencies to.
480-
void addClangInvovcationDependencies(std::vector<std::string> &files);
481-
482477
/// Makes a temporary replica of the ClangImporter's CompilerInstance, reads a
483478
/// module map into the replica and emits a PCM file for one of the modules it
484479
/// declares. Delegates to clang for everything except construction of the

include/swift/Frontend/CachingUtils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ std::unique_ptr<llvm::MemoryBuffer> loadCachedCompileResultFromCacheKey(
7070
llvm::StringRef Filename = "");
7171

7272
llvm::Expected<llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>>
73-
createCASFileSystem(llvm::cas::ObjectStore &CAS, ArrayRef<std::string> FSRoots,
73+
createCASFileSystem(llvm::cas::ObjectStore &CAS,
7474
const std::string &IncludeTreeRoot,
7575
const std::string &IncludeTreeFileList);
7676

include/swift/Option/FrontendOptions.td

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,9 +1454,6 @@ def bridging_header_pch_key : Separate<["-"], "bridging-header-pch-key">,
14541454
def no_clang_include_tree: Flag<["-"], "no-clang-include-tree">,
14551455
HelpText<"Do not use clang include tree, fallback to use CAS filesystem to build clang modules">;
14561456

1457-
def cas_fs: Separate<["-"], "cas-fs">,
1458-
HelpText<"Root CASID for CAS FileSystem">, MetaVarName<"<cas-id>">;
1459-
14601457
def clang_include_tree_root: Separate<["-"], "clang-include-tree-root">,
14611458
HelpText<"Clang Include Tree CASID">, MetaVarName<"<cas-id>">;
14621459
def clang_include_tree_filelist: Separate<["-"], "clang-include-tree-filelist">,

lib/AST/ModuleDependencies.cpp

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include "swift/Strings.h"
2626
#include "clang/CAS/IncludeTree.h"
2727
#include "llvm/CAS/CASProvidingFileSystem.h"
28-
#include "llvm/CAS/CachingOnDiskFileSystem.h"
2928
#include "llvm/Config/config.h"
3029
#include "llvm/Support/FileSystem.h"
3130
#include "llvm/Support/Path.h"
@@ -602,13 +601,16 @@ swift::dependencies::registerBackDeployLibraries(
602601
}
603602

604603
SwiftDependencyTracker::SwiftDependencyTracker(
605-
llvm::cas::CachingOnDiskFileSystem &FS, llvm::PrefixMapper *Mapper,
604+
std::shared_ptr<llvm::cas::ObjectStore> CAS, llvm::PrefixMapper *Mapper,
606605
const CompilerInvocation &CI)
607-
: FS(FS.createProxyFS()), Mapper(Mapper) {
606+
: CAS(CAS), Mapper(Mapper) {
608607
auto &SearchPathOpts = CI.getSearchPathOptions();
609608

609+
FS = llvm::cas::createCASProvidingFileSystem(
610+
CAS, llvm::vfs::createPhysicalFileSystem());
611+
610612
auto addCommonFile = [&](StringRef path) {
611-
auto file = FS.openFileForRead(path);
613+
auto file = FS->openFileForRead(path);
612614
if (!file)
613615
return;
614616
auto status = (*file)->status();
@@ -679,7 +681,7 @@ SwiftDependencyTracker::createTreeFromDependencies() {
679681
llvm::SmallVector<clang::cas::IncludeTree::FileList::FileEntry> Files;
680682
for (auto &file : TrackedFiles) {
681683
auto includeTreeFile = clang::cas::IncludeTree::File::create(
682-
FS->getCAS(), file.first, file.second.FileRef);
684+
*CAS, file.first, file.second.FileRef);
683685
if (!includeTreeFile) {
684686
return llvm::createStringError("CASFS createTree failed for " +
685687
file.first + ": " +
@@ -691,7 +693,7 @@ SwiftDependencyTracker::createTreeFromDependencies() {
691693
}
692694

693695
auto includeTreeList =
694-
clang::cas::IncludeTree::FileList::create(FS->getCAS(), Files, {});
696+
clang::cas::IncludeTree::FileList::create(*CAS, Files, {});
695697
if (!includeTreeList)
696698
return llvm::createStringError("casfs include-tree filelist error: " +
697699
toString(includeTreeList.takeError()));
@@ -719,14 +721,8 @@ bool SwiftDependencyScanningService::setupCachingDependencyScanningService(
719721
CAS = Instance.getSharedCASInstance();
720722
ActionCache = Instance.getSharedCacheInstance();
721723

722-
auto CachingFS =
723-
llvm::cas::createCachingOnDiskFileSystem(Instance.getObjectStore());
724-
if (!CachingFS) {
725-
Instance.getDiags().diagnose(SourceLoc(), diag::error_cas_fs_creation,
726-
toString(CachingFS.takeError()));
727-
return true;
728-
}
729-
CacheFS = std::move(*CachingFS);
724+
CacheFS = llvm::cas::createCASProvidingFileSystem(
725+
CAS, llvm::vfs::createPhysicalFileSystem());
730726

731727
// Setup prefix mapping.
732728
auto &ScannerPrefixMapper =
@@ -744,19 +740,14 @@ bool SwiftDependencyScanningService::setupCachingDependencyScanningService(
744740
Mapper->sort();
745741
}
746742

747-
UseClangIncludeTree =
748-
Instance.getInvocation().getClangImporterOptions().UseClangIncludeTree;
749743
const clang::tooling::dependencies::ScanningOutputFormat ClangScanningFormat =
750-
UseClangIncludeTree
751-
? clang::tooling::dependencies::ScanningOutputFormat::FullIncludeTree
752-
: clang::tooling::dependencies::ScanningOutputFormat::FullTree;
744+
clang::tooling::dependencies::ScanningOutputFormat::FullIncludeTree;
753745

754746
ClangScanningService.emplace(
755747
clang::tooling::dependencies::ScanningMode::DependencyDirectivesScan,
756-
ClangScanningFormat,
757-
Instance.getInvocation().getCASOptions().CASOpts,
748+
ClangScanningFormat, Instance.getInvocation().getCASOptions().CASOpts,
758749
Instance.getSharedCASInstance(), Instance.getSharedCacheInstance(),
759-
UseClangIncludeTree ? nullptr : CacheFS,
750+
/*CachingOnDiskFileSystem=*/nullptr,
760751
// The current working directory optimization (off by default)
761752
// should not impact CAS. We set the optization to all to be
762753
// consistent with the non-CAS case.

lib/ClangImporter/ClangImporter.cpp

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,27 +1038,6 @@ std::string ClangImporter::getOriginalSourceFile(StringRef PCHFilename) {
10381038
Impl.Instance->getPCHContainerReader(), Impl.Instance->getDiagnostics());
10391039
}
10401040

1041-
void ClangImporter::addClangInvovcationDependencies(
1042-
std::vector<std::string> &files) {
1043-
auto addFiles = [&files](const auto &F) {
1044-
files.insert(files.end(), F.begin(), F.end());
1045-
};
1046-
auto &invocation = *Impl.Invocation;
1047-
// FIXME: Add file dependencies that are not accounted. The long term solution
1048-
// is to do a dependency scanning for clang importer and use that directly.
1049-
SmallVector<std::string, 4> HeaderMapFileNames;
1050-
Impl.Instance->getPreprocessor().getHeaderSearchInfo().getHeaderMapFileNames(
1051-
HeaderMapFileNames);
1052-
addFiles(HeaderMapFileNames);
1053-
addFiles(invocation.getHeaderSearchOpts().VFSOverlayFiles);
1054-
// FIXME: Should not depend on working directory. Build system/swift driver
1055-
// should not pass working directory here but if that option is passed,
1056-
// repect that and add that into CASFS.
1057-
auto CWD = invocation.getFileSystemOpts().WorkingDir;
1058-
if (!CWD.empty())
1059-
files.push_back(CWD);
1060-
}
1061-
10621041
std::optional<std::string>
10631042
ClangImporter::getPCHFilename(const ClangImporterOptions &ImporterOptions,
10641043
StringRef SwiftPCHHash, bool &isExplicit) {
@@ -1186,7 +1165,7 @@ std::optional<std::vector<std::string>> ClangImporter::getClangCC1Arguments(
11861165
clang::frontend::ActionKind::GenerateModule ||
11871166
CI->getFrontendOpts().ProgramAction ==
11881167
clang::frontend::ActionKind::GeneratePCH) &&
1189-
ctx.ClangImporterOpts.HasClangIncludeTreeRoot) {
1168+
!ctx.CASOpts.ClangIncludeTree.empty()) {
11901169
CI->getFrontendOpts().CASIncludeTreeID = ctx.CASOpts.ClangIncludeTree;
11911170
CI->getFrontendOpts().Inputs.clear();
11921171
}
@@ -1246,7 +1225,7 @@ std::optional<std::vector<std::string>> ClangImporter::getClangCC1Arguments(
12461225

12471226
std::vector<std::string> FilteredModuleMapFiles;
12481227
for (auto ModuleMapFile : CI->getFrontendOpts().ModuleMapFiles) {
1249-
if (ctx.ClangImporterOpts.UseClangIncludeTree) {
1228+
if (ctx.CASOpts.HasImmutableFileSystem) {
12501229
// There is no need to add any module map file here. Issue a warning and
12511230
// drop the option.
12521231
Impl.diagnose(SourceLoc(), diag::module_map_ignored, ModuleMapFile);
@@ -2731,7 +2710,6 @@ ClangImporter::Implementation::Implementation(
27312710
!ctx.ClangImporterOpts.BridgingHeader.empty()),
27322711
DisableOverlayModules(ctx.ClangImporterOpts.DisableOverlayModules),
27332712
EnableClangSPI(ctx.ClangImporterOpts.EnableClangSPI),
2734-
UseClangIncludeTree(ctx.ClangImporterOpts.UseClangIncludeTree),
27352713
IsReadingBridgingPCH(false),
27362714
CurrentVersion(ImportNameVersion::fromOptions(ctx.LangOpts)),
27372715
Walker(DiagnosticWalker(*this)), BuffersForDiagnostics(ctx.SourceMgr),
@@ -4258,11 +4236,9 @@ ClangImporter::getSwiftExplicitModuleDirectCC1Args() const {
42584236
auto &CGOpts = instance.getCodeGenOpts();
42594237
CGOpts.DebugCompilationDir.clear();
42604238

4261-
if (Impl.SwiftContext.ClangImporterOpts.UseClangIncludeTree) {
42624239
// FileSystemOptions.
4263-
auto &FSOpts = instance.getFileSystemOpts();
4264-
FSOpts.WorkingDir.clear();
4265-
}
4240+
auto &FSOpts = instance.getFileSystemOpts();
4241+
FSOpts.WorkingDir.clear();
42664242

42674243
if (!Impl.SwiftContext.SearchPathOpts.ScannerPrefixMapper.empty()) {
42684244
// Remap all the paths if requested.

lib/ClangImporter/ClangModuleDependencyScanner.cpp

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ ModuleDependencyVector ClangImporter::bridgeClangModuleDependencies(
147147
// Swift frontend option for input file path (Foo.modulemap).
148148
swiftArgs.push_back(remapPath(clangModuleDep.ClangModuleMapFile));
149149

150-
// Handle VFSOverlay. If include tree is used, there is no need for overlay.
151-
if (!ctx.ClangImporterOpts.UseClangIncludeTree) {
150+
// Handle VFSOverlay. If caching is enabled, there is no need for overlay.
151+
if (!ctx.CASOpts.EnableCaching) {
152152
for (auto &overlay : ctx.SearchPathOpts.VFSOverlayFiles) {
153153
swiftArgs.push_back("-vfsoverlay");
154154
swiftArgs.push_back(remapPath(overlay));
@@ -217,12 +217,6 @@ ModuleDependencyVector ClangImporter::bridgeClangModuleDependencies(
217217
ctx.CASOpts.enumerateCASConfigurationFlags(
218218
[&](StringRef Arg) { swiftArgs.push_back(Arg.str()); });
219219

220-
if (!RootID.empty()) {
221-
swiftArgs.push_back("-no-clang-include-tree");
222-
swiftArgs.push_back("-cas-fs");
223-
swiftArgs.push_back(RootID);
224-
}
225-
226220
if (!IncludeTree.empty()) {
227221
swiftArgs.push_back("-clang-include-tree-root");
228222
swiftArgs.push_back(IncludeTree);
@@ -324,11 +318,6 @@ void ClangImporter::getBridgingHeaderOptions(
324318
swiftArgs.push_back("-clang-include-tree-root");
325319
swiftArgs.push_back(*Tree);
326320
}
327-
if (auto CASFS = deps.CASFileSystemRootID) {
328-
swiftArgs.push_back("-no-clang-include-tree");
329-
swiftArgs.push_back("-cas-fs");
330-
swiftArgs.push_back(*CASFS);
331-
}
332321
}
333322

334323
ModuleDependencyVector

lib/ClangImporter/ImporterImpl.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,6 @@ class LLVM_LIBRARY_VISIBILITY ClangImporter::Implementation
478478
const bool BridgingHeaderExplicitlyRequested;
479479
const bool DisableOverlayModules;
480480
const bool EnableClangSPI;
481-
const bool UseClangIncludeTree;
482481

483482
bool IsReadingBridgingPCH;
484483
llvm::SmallVector<clang::serialization::SubmoduleID, 2> PCHImportedSubmodules;

lib/DependencyScan/ModuleDependencyScanner.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -595,14 +595,6 @@ ModuleDependencyScanner::getMainModuleDependencyInfo(ModuleDecl *mainModule) {
595595
auto mainDependencies = ModuleDependencyInfo::forSwiftSourceModule(
596596
{}, buildCommands, {}, {}, {});
597597

598-
if (ScanASTContext.CASOpts.EnableCaching) {
599-
std::vector<std::string> clangDependencyFiles;
600-
clangImporter->addClangInvovcationDependencies(clangDependencyFiles);
601-
llvm::for_each(clangDependencyFiles, [&](std::string &file) {
602-
mainDependencies.addAuxiliaryFile(file);
603-
});
604-
}
605-
606598
llvm::StringSet<> alreadyAddedModules;
607599
// Compute Implicit dependencies of the main module
608600
{

lib/DependencyScan/ScanDependencies.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,6 @@ class ExplicitModuleDependencyResolver {
316316
}
317317

318318
// Collect CAS deppendencies from clang modules.
319-
if (!clangDepDetails.CASFileSystemRootID.empty())
320-
rootIDs.push_back(clangDepDetails.CASFileSystemRootID);
321319
if (!clangDepDetails.CASClangIncludeTreeRootID.empty()) {
322320
if (addIncludeTree(clangDepDetails.CASClangIncludeTreeRootID))
323321
return true;
@@ -521,11 +519,6 @@ class ExplicitModuleDependencyResolver {
521519
if (resolvingDepInfo.isSwiftInterfaceModule() ||
522520
resolvingDepInfo.isSwiftSourceModule()) {
523521
// Update with casfs option.
524-
for (auto rootID : rootIDs) {
525-
commandline.push_back("-cas-fs");
526-
commandline.push_back(rootID);
527-
}
528-
529522
if (computeCASFileSystem(dependencyInfoCopy))
530523
return true;
531524
}
@@ -679,7 +672,6 @@ class ExplicitModuleDependencyResolver {
679672
const ModuleDependencyInfo &resolvingDepInfo;
680673

681674
std::optional<SwiftDependencyTracker> tracker;
682-
std::vector<std::string> rootIDs;
683675
std::vector<llvm::cas::ObjectRef> fileListRefs;
684676
std::vector<std::string> commandline;
685677
std::vector<std::string> bridgingHeaderBuildCmd;

0 commit comments

Comments
 (0)