Skip to content

Commit c42e2d8

Browse files
committed
[clang][deps][cas] Reduce diff footprint with upstream
Reduce unnecessary differences with upstream dep scanning code, and group some of the changes so they are in larger regions that are easier to follow.
1 parent 8bc7d8e commit c42e2d8

File tree

7 files changed

+42
-45
lines changed

7 files changed

+42
-45
lines changed

clang/include/clang/Tooling/DependencyScanning/DependencyScanningCASFilesystem.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class DependencyScanningCASFilesystem : public llvm::cas::ThreadSafeFileSystem {
8484
Optional<llvm::cas::ObjectRef> CASContents;
8585
};
8686
llvm::BumpPtrAllocator EntryAlloc;
87-
llvm::StringMap<FileEntry, llvm::BumpPtrAllocator&> Entries;
87+
llvm::StringMap<FileEntry, llvm::BumpPtrAllocator &> Entries;
8888

8989
struct LookupPathResult {
9090
const FileEntry *Entry = nullptr;

clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,10 @@ class DependencyScanningService {
6262
bool ReuseFileManager = true, bool OptimizeArgs = false,
6363
bool OverrideCASTokenCache = false);
6464

65-
~DependencyScanningService();
66-
6765
ScanningMode getMode() const { return Mode; }
6866

6967
ScanningOutputFormat getFormat() const { return Format; }
7068

71-
const CASOptions &getCASOpts() const { return CASOpts; }
72-
7369
bool canReuseFileManager() const { return ReuseFileManager; }
7470

7571
bool canOptimizeArgs() const { return OptimizeArgs; }
@@ -80,6 +76,8 @@ class DependencyScanningService {
8076
return *SharedCache;
8177
}
8278

79+
const CASOptions &getCASOpts() const { return CASOpts; }
80+
8381
bool overrideCASTokenCache() const { return OverrideCASTokenCache; }
8482

8583
llvm::cas::CachingOnDiskFileSystem &getSharedFS() { return *SharedFS; }

clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,7 @@ class FullDependencyConsumer : public DependencyConsumer {
168168
FullDependencyConsumer(const llvm::StringSet<> &AlreadySeen)
169169
: AlreadySeen(AlreadySeen) {}
170170

171-
void
172-
handleDependencyOutputOpts(const DependencyOutputOptions &Opts) override {}
171+
void handleDependencyOutputOpts(const DependencyOutputOptions &) override {}
173172

174173
void handleFileDependency(StringRef File) override {
175174
Dependencies.push_back(std::string(File));
@@ -187,9 +186,9 @@ class FullDependencyConsumer : public DependencyConsumer {
187186
ContextHash = std::move(Hash);
188187
}
189188

190-
Expected<FullDependenciesResult>
191-
getFullDependencies(const std::vector<std::string> &OriginalCommandLine,
192-
llvm::cas::CachingOnDiskFileSystem *FS) const;
189+
FullDependenciesResult getFullDependencies(
190+
const std::vector<std::string> &OriginalCommandLine,
191+
Optional<cas::CASID> CASFileSystemRootID = None) const;
193192

194193
private:
195194
std::vector<std::string> Dependencies;

clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,21 +132,21 @@ class DependencyScanningWorker {
132132
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> RealFS;
133133
/// The in-memory filesystem laid on top the physical filesystem in `RealFS`.
134134
llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFS;
135-
/// The caching file system.
136-
llvm::IntrusiveRefCntPtr<llvm::cas::CachingOnDiskFileSystem> CacheFS;
137135
/// The file system that is used by each worker when scanning for
138136
/// dependencies. This filesystem persists across multiple compiler
139137
/// invocations.
140138
llvm::IntrusiveRefCntPtr<DependencyScanningWorkerFilesystem> DepFS;
141-
/// The CAS Dependency Filesytem. This is not set at the sametime as DepFS;
142-
llvm::IntrusiveRefCntPtr<DependencyScanningCASFilesystem> DepCASFS;
143139
/// The file manager that is reused across multiple invocations by this
144140
/// worker. If null, the file manager will not be reused.
145141
llvm::IntrusiveRefCntPtr<FileManager> Files;
146142
ScanningOutputFormat Format;
147143
/// Whether to optimize the modules' command-line arguments.
148144
bool OptimizeArgs;
149145

146+
/// The caching file system.
147+
llvm::IntrusiveRefCntPtr<llvm::cas::CachingOnDiskFileSystem> CacheFS;
148+
/// The CAS Dependency Filesytem. This is not set at the sametime as DepFS;
149+
llvm::IntrusiveRefCntPtr<DependencyScanningCASFilesystem> DepCASFS;
150150
CASOptions CASOpts;
151151
bool UseCAS;
152152
bool OverrideCASTokenCache;

clang/lib/Tooling/DependencyScanning/DependencyScanningService.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,3 @@ DependencyScanningService::DependencyScanningService(
3232
llvm::InitializeAllAsmPrinters();
3333
llvm::InitializeAllAsmParsers();
3434
}
35-
36-
DependencyScanningService::~DependencyScanningService() = default;

clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -399,12 +399,20 @@ DependencyScanningTool::getFullDependencies(
399399
if (Result)
400400
return std::move(Result);
401401

402-
return Consumer.getFullDependencies(CommandLine, FS);
402+
Optional<cas::CASID> CASFileSystemRootID;
403+
if (FS) {
404+
if (auto Tree = FS->createTreeFromNewAccesses())
405+
CASFileSystemRootID = Tree->getID();
406+
else
407+
return Tree.takeError();
408+
}
409+
410+
return Consumer.getFullDependencies(CommandLine, CASFileSystemRootID);
403411
}
404412

405-
Expected<FullDependenciesResult> FullDependencyConsumer::getFullDependencies(
413+
FullDependenciesResult FullDependencyConsumer::getFullDependencies(
406414
const std::vector<std::string> &OriginalCommandLine,
407-
llvm::cas::CachingOnDiskFileSystem *FS) const {
415+
Optional<cas::CASID> CASFileSystemRootID) const {
408416
FullDependencies FD;
409417

410418
FD.OriginalCommandLine = ArrayRef<std::string>(OriginalCommandLine).slice(1);
@@ -421,12 +429,7 @@ Expected<FullDependenciesResult> FullDependencyConsumer::getFullDependencies(
421429

422430
FD.PrebuiltModuleDeps = std::move(PrebuiltModuleDeps);
423431

424-
if (FS) {
425-
if (auto Tree = FS->createTreeFromNewAccesses())
426-
FD.CASFileSystemRootID = Tree->getID();
427-
else
428-
return Tree.takeError();
429-
}
432+
FD.CASFileSystemRootID = CASFileSystemRootID;
430433

431434
FullDependenciesResult FDR;
432435

clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -196,21 +196,20 @@ class DependencyScanningAction : public tooling::ToolAction {
196196
public:
197197
DependencyScanningAction(
198198
StringRef WorkingDirectory, DependencyConsumer &Consumer,
199-
const CASOptions &CASOpts,
200199
llvm::IntrusiveRefCntPtr<DependencyScanningWorkerFilesystem> DepFS,
201200
llvm::IntrusiveRefCntPtr<DependencyScanningCASFilesystem> DepCASFS,
202-
bool OverrideCASTokenCache, ScanningOutputFormat Format,
203-
bool OptimizeArgs, bool EmitDependencyFile,
204-
bool DiagGenerationAsCompilation, bool DisableFree,
201+
ScanningOutputFormat Format, bool OptimizeArgs, bool DisableFree,
202+
bool EmitDependencyFile, bool DiagGenerationAsCompilation,
203+
const CASOptions &CASOpts, bool OverrideCASTokenCache,
205204
llvm::Optional<StringRef> ModuleName = None,
206205
raw_ostream *VerboseOS = nullptr)
207206
: WorkingDirectory(WorkingDirectory), Consumer(Consumer),
208-
CASOpts(CASOpts), DepFS(std::move(DepFS)),
209-
DepCASFS(std::move(DepCASFS)), Format(Format),
210-
OverrideCASTokenCache(OverrideCASTokenCache),
211-
OptimizeArgs(OptimizeArgs), EmitDependencyFile(EmitDependencyFile),
207+
DepFS(std::move(DepFS)), DepCASFS(std::move(DepCASFS)), Format(Format),
208+
OptimizeArgs(OptimizeArgs), DisableFree(DisableFree),
209+
CASOpts(CASOpts), OverrideCASTokenCache(OverrideCASTokenCache),
210+
EmitDependencyFile(EmitDependencyFile),
212211
DiagGenerationAsCompilation(DiagGenerationAsCompilation),
213-
DisableFree(DisableFree), ModuleName(ModuleName), VerboseOS(VerboseOS) {
212+
ModuleName(ModuleName), VerboseOS(VerboseOS) {
214213
}
215214

216215
bool runInvocation(std::shared_ptr<CompilerInvocation> Invocation,
@@ -371,15 +370,15 @@ class DependencyScanningAction : public tooling::ToolAction {
371370
private:
372371
StringRef WorkingDirectory;
373372
DependencyConsumer &Consumer;
374-
const CASOptions &CASOpts;
375373
llvm::IntrusiveRefCntPtr<DependencyScanningWorkerFilesystem> DepFS;
376374
llvm::IntrusiveRefCntPtr<DependencyScanningCASFilesystem> DepCASFS;
377375
ScanningOutputFormat Format;
378-
bool OverrideCASTokenCache;
379376
bool OptimizeArgs;
377+
bool DisableFree;
378+
const CASOptions &CASOpts;
379+
bool OverrideCASTokenCache;
380380
bool EmitDependencyFile = false;
381381
bool DiagGenerationAsCompilation;
382-
bool DisableFree;
383382
llvm::Optional<StringRef> ModuleName;
384383
raw_ostream *VerboseOS;
385384
};
@@ -480,10 +479,11 @@ llvm::Error DependencyScanningWorker::computeDependencies(
480479
// always true for a driver invocation.
481480
bool DisableFree = true;
482481
DependencyScanningAction Action(
483-
WorkingDirectory, Consumer, getCASOpts(), DepFS,
484-
DepCASFS, OverrideCASTokenCache, Format,
485-
OptimizeArgs, /*EmitDependencyFile=*/false,
486-
/*DiagGenerationAsCompilation=*/false, DisableFree,
482+
WorkingDirectory, Consumer, DepFS, DepCASFS, Format,
483+
OptimizeArgs, DisableFree,
484+
/*EmitDependencyFile=*/false,
485+
/*DiagGenerationAsCompilation=*/false,
486+
getCASOpts(), OverrideCASTokenCache,
487487
ModuleName);
488488
// Create an invocation that uses the underlying file
489489
// system to ensure that any file system requests that
@@ -528,11 +528,10 @@ void DependencyScanningWorker::computeDependenciesFromCompilerInvocation(
528528
// FIXME: EmitDependencyFile should only be set when it's for a real
529529
// compilation.
530530
DependencyScanningAction Action(
531-
WorkingDirectory, DepsConsumer, getCASOpts(), DepFS, DepCASFS,
532-
OverrideCASTokenCache, Format,
533-
/*OptimizeArgs=*/false,
531+
WorkingDirectory, DepsConsumer, DepFS, DepCASFS, Format,
532+
/*OptimizeArgs=*/false, /*DisableFree=*/false,
534533
/*EmitDependencyFile=*/!DepFile.empty(), DiagGenerationAsCompilation,
535-
/*DisableFree=*/false, /*ModuleName=*/None, VerboseOS);
534+
getCASOpts(), OverrideCASTokenCache, /*ModuleName=*/None, VerboseOS);
536535

537536
// Ignore result; we're just collecting dependencies.
538537
//

0 commit comments

Comments
 (0)