clang 24.0.0git
DependencyScanningFilesystem.cpp
Go to the documentation of this file.
1//===- DependencyScanningFilesystem.cpp - Optimized Scanning FS -----------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
11#include "llvm/Support/MemoryBuffer.h"
12#include "llvm/Support/Threading.h"
13#include <optional>
14
15using namespace clang;
16using namespace dependencies;
17
18llvm::ErrorOr<DependencyScanningWorkerFilesystem::TentativeEntry>
19DependencyScanningWorkerFilesystem::readFile(StringRef Filename,
20 llvm::vfs::FileSystem &FS) {
21 // Load the file and its content from the file system.
22 auto MaybeFile = FS.openFileForRead(Filename);
23 if (!MaybeFile)
24 return MaybeFile.getError();
25 auto File = std::move(*MaybeFile);
26
27 auto MaybeStat = File->status();
28 if (!MaybeStat)
29 return MaybeStat.getError();
30 auto Stat = std::move(*MaybeStat);
31
32 auto MaybeBuffer = File->getBuffer(Stat.getName());
33 if (!MaybeBuffer)
34 return MaybeBuffer.getError();
35 auto Buffer = std::move(*MaybeBuffer);
36
37 // If the file size changed between read and stat, pretend it didn't.
38 if (Stat.getSize() != Buffer->getBufferSize())
39 Stat = llvm::vfs::Status::copyWithNewSize(Stat, Buffer->getBufferSize());
40
41 return TentativeEntry(Stat, std::move(Buffer));
42}
43
45 EntryRef Ref) {
46 auto &Entry = Ref.Entry;
47
48 if (Entry.isError() || Entry.isDirectory())
49 return false;
50
51 CachedFileContents *Contents = Entry.getCachedContents();
52 assert(Contents && "contents not initialized");
53
54 // Double-checked locking.
55 if (Contents->DepDirectives.load())
56 return true;
57
58 std::lock_guard<std::mutex> GuardLock(Contents->ValueLock);
59
60 // Double-checked locking.
61 if (Contents->DepDirectives.load())
62 return true;
63
65 // Scan the file for preprocessor directives that might affect the
66 // dependencies.
67 if (scanSourceForDependencyDirectives(Contents->Original->getBuffer(),
68 Contents->DepDirectiveTokens,
69 Directives)) {
70 Contents->DepDirectiveTokens.clear();
71 // FIXME: Propagate the diagnostic if desired by the client.
72 Contents->DepDirectives.store(new std::optional<DependencyDirectivesTy>());
73 return false;
74 }
75
76 // This function performed double-checked locking using `DepDirectives`.
77 // Assigning it must be the last thing this function does, otherwise other
78 // threads may skip the critical section (`DepDirectives != nullptr`), leading
79 // to a data race.
80 Contents->DepDirectives.store(
81 new std::optional<DependencyDirectivesTy>(std::move(Directives)));
82 return true;
83}
84
87 // This heuristic was chosen using a empirical testing on a
88 // reasonably high core machine (iMacPro 18 cores / 36 threads). The cache
89 // sharding gives a performance edge by reducing the lock contention.
90 // FIXME: A better heuristic might also consider the OS to account for
91 // the different cost of lock contention on different OSes.
92 NumShards =
93 std::max(2u, llvm::hardware_concurrency().compute_thread_count() / 4);
94 CacheShards = std::make_unique<CacheShard[]>(NumShards);
95}
96
99 StringRef Filename) const {
100 assert(llvm::sys::path::is_absolute_gnu(Filename));
101 return CacheShards[llvm::hash_value(Filename) % NumShards];
102}
103
106 llvm::sys::fs::UniqueID UID) const {
107 auto Hash = llvm::hash_combine(UID.getDevice(), UID.getFile());
108 return CacheShards[Hash % NumShards];
109}
110
111std::vector<DependencyScanningFilesystemSharedCache::OutOfDateEntry>
113 llvm::vfs::FileSystem &UnderlyingFS) const {
114 // Iterate through all shards and look for cached stat errors.
115 std::vector<OutOfDateEntry> InvalidDiagInfo;
116 for (unsigned i = 0; i < NumShards; i++) {
117 const CacheShard &Shard = CacheShards[i];
118 std::lock_guard<std::mutex> LockGuard(Shard.CacheLock);
119 for (const auto &[Path, State] : Shard.CacheByFilename) {
120 const CachedFileSystemEntry *Entry = State.Entry;
121 // Skip slots without a resolved entry: real-path-only entries from
122 // getRealPath, or uncached negative stats. Runs post-scan, so no
123 // in-progress slots remain.
124 if (!Entry)
125 continue;
126 llvm::ErrorOr<llvm::vfs::Status> Status = UnderlyingFS.status(Path);
127 if (Status) {
128 if (Entry->getError()) {
129 // This is the case where we have cached the non-existence
130 // of the file at Path first, and a file at the path is created
131 // later. The cache entry is not invalidated (as we have no good
132 // way to do it now), which may lead to missing file build errors.
133 InvalidDiagInfo.emplace_back(Path.data());
134 } else {
135 llvm::vfs::Status CachedStatus = Entry->getStatus();
136 if (Status->getType() == llvm::sys::fs::file_type::regular_file &&
137 Status->getType() == CachedStatus.getType()) {
138 // We only check regular files. Directory files sizes could change
139 // due to content changes, and reporting directory size changes can
140 // lead to false positives.
141 // TODO: At the moment, we do not detect symlinks to files whose
142 // size may change. We need to decide if we want to detect cached
143 // symlink size changes. We can also expand this to detect file
144 // type changes.
145 uint64_t CachedSize = CachedStatus.getSize();
146 uint64_t ActualSize = Status->getSize();
147 if (CachedSize != ActualSize) {
148 // This is the case where the cached file has a different size
149 // from the actual file that comes from the underlying FS.
150 InvalidDiagInfo.emplace_back(Path.data(), CachedSize, ActualSize);
151 }
152 }
153 }
154 }
155 }
156 }
157 return InvalidDiagInfo;
158}
159
160namespace {
161using InProgressEntry =
163using SlotResolved = llvm::ErrorOr<const CachedFileSystemEntry *>;
164using SlotProducer = std::shared_ptr<InProgressEntry>;
165using SlotAcquisitionResult = std::variant<SlotResolved, SlotProducer>;
166
167/// Returns a resolved entry if one is already present or in-flight under
168/// \p K; otherwise installs a fresh \c InProgressEntry and returns it as a
169/// producer slot.
170template <typename Map, typename Key>
171SlotAcquisitionResult acquireSlot(std::mutex &CacheLock, Map &M, const Key &K) {
172 std::shared_ptr<InProgressEntry> Pending;
173 {
174 std::lock_guard<std::mutex> ShardLock(CacheLock);
175 auto &State = M[K];
176
177 // Cache hit.
178 if (State.Entry)
179 return SlotResolved{State.Entry};
180
181 if (!State.InProgress) {
182 State.InProgress = std::make_shared<InProgressEntry>();
183 return SlotProducer{State.InProgress};
184 }
185
186 // Copy the shared_ptr so the slot survives our wait once the shard lock
187 // is released and the producer resets State.InProgress on publish.
188 Pending = State.InProgress;
189 }
190
191 // Wait off the shard lock so unrelated keys in this shard aren't blocked.
192 std::unique_lock<std::mutex> EntryLock(Pending->Mutex);
193 Pending->CondVar.wait(EntryLock, [&] { return Pending->Done; });
194 return SlotResolved{Pending->Result};
195}
196} // namespace
197
198const CachedRealPath *
200 StringRef Filename) const {
201 assert(llvm::sys::path::is_absolute_gnu(Filename));
202 std::lock_guard<std::mutex> LockGuard(CacheLock);
203 auto It = CacheByFilename.find(Filename);
204 return It == CacheByFilename.end() ? nullptr : It->getValue().RealPath;
205}
206
208 getOrEmplaceRealPathForFilename(StringRef Filename,
209 llvm::ErrorOr<llvm::StringRef> RealPath) {
210 std::lock_guard<std::mutex> LockGuard(CacheLock);
211
212 const CachedRealPath *&StoredRealPath = CacheByFilename[Filename].RealPath;
213 if (!StoredRealPath) {
214 auto OwnedRealPath = [&]() -> CachedRealPath {
215 if (!RealPath)
216 return RealPath.getError();
217 return RealPath->str();
218 }();
219
220 StoredRealPath = new (RealPathStorage.Allocate())
221 CachedRealPath(std::move(OwnedRealPath));
222 }
223
224 return *StoredRealPath;
225}
226
230 if (LocalFS) {
231 // LocalFS takes precedence over GlobalFS, like it does for the queries that
232 // don't go through this overlay.
233 auto OverlayVFS = llvm::makeIntrusiveRefCnt<llvm::vfs::OverlayFileSystem>(
234 std::move(GlobalFS));
235 OverlayVFS->pushOverlay(std::move(LocalFS));
236 return OverlayVFS;
237 }
238 return GlobalFS;
239}
240
246 llvm::vfs::ProxyFileSystem>(
247 combineGlobalAndLocalFS(FS, LocalFS)),
248 Service(Service), WorkingDirForCacheLookup(llvm::errc::invalid_argument),
249 LocalFS(std::move(LocalFS)), BaseFS(FS) {
250 updateWorkingDirForCacheLookup();
251}
252
253const CachedFileSystemEntry *DependencyScanningWorkerFilesystem::createEntry(
254 llvm::ErrorOr<TentativeEntry> &TEntry,
255 llvm::SpecificBumpPtrAllocator<CachedFileContents> &ContentsStorage,
256 llvm::SpecificBumpPtrAllocator<CachedFileSystemEntry> &EntryStorage) {
257 if (TEntry) {
258 CachedFileContents *StoredContents = nullptr;
259 if (TEntry->Contents)
260 StoredContents = new (ContentsStorage.Allocate())
261 CachedFileContents(std::move(TEntry->Contents));
262 return new (EntryStorage.Allocate())
263 CachedFileSystemEntry(std::move(TEntry->Status), StoredContents);
264 } else {
265 return new (EntryStorage.Allocate())
266 CachedFileSystemEntry(TEntry.getError());
267 }
268}
269
271DependencyScanningWorkerFilesystem::resolveUIDThroughSharedCache(
272 StringRef OriginalFilename, const llvm::vfs::Status &Stat) {
273 auto &UIDShard = Service.getSharedCache().getShardForUID(Stat.getUniqueID());
274 auto UIDSlot = acquireSlot(UIDShard.CacheLock, UIDShard.EntriesByUID,
275 Stat.getUniqueID());
276 if (auto *Resolved = std::get_if<SlotResolved>(&UIDSlot)) {
277 assert(*Resolved && **Resolved &&
278 "in-progress UID slot fulfilled without an entry");
279 return **Resolved;
280 }
281 auto UIDProducer = std::move(std::get<SlotProducer>(UIDSlot));
282
283 auto TEntry = Stat.isDirectory() ? TentativeEntry(Stat)
284 : readFile(OriginalFilename, *BaseFS);
285
286 // Allocate the entry and bind the UID slot under one shard-lock acquisition
287 // (BumpPtrAllocator isn't thread-safe). On read-failure, the entry wraps
288 // the open error so concurrent UID waiters surface it rather than racing
289 // to retry the open.
290 const CachedFileSystemEntry *SharedEntry;
291 {
292 std::lock_guard<std::mutex> ShardLock(UIDShard.CacheLock);
293 auto &State = UIDShard.EntriesByUID[Stat.getUniqueID()];
294 assert(!State.Entry && "UID slot already published an entry");
295 SharedEntry =
296 createEntry(TEntry, UIDShard.ContentsStorage, UIDShard.EntryStorage);
297 State.Entry = SharedEntry;
298 State.InProgress.reset();
299 }
300 UIDProducer->publish(SharedEntry);
301 return SharedEntry;
302}
303
305DependencyScanningWorkerFilesystem::createCachedFSEntryForLocal(
306 StringRef OriginalFilename, const llvm::vfs::Status &Stat) {
307 assert(LocalFS);
308 auto TEntry = Stat.isDirectory() ? TentativeEntry(Stat)
309 : readFile(OriginalFilename, *LocalFS);
310 return createEntry(TEntry, LocalContentsStorage, LocalEntryStorage);
311}
312
313llvm::ErrorOr<const CachedFileSystemEntry *>
314DependencyScanningWorkerFilesystem::resolveFilenameThroughSharedCache(
315 StringRef OriginalFilename, StringRef FilenameForLookup) {
316 if (LocalFS) {
317 if (auto Stat = LocalFS->status(OriginalFilename)) {
318 return createCachedFSEntryForLocal(OriginalFilename, *Stat);
319 }
320 }
321 assert(llvm::sys::path::is_absolute_gnu(FilenameForLookup));
322 auto &FilenameShard =
323 Service.getSharedCache().getShardForFilename(FilenameForLookup);
324 auto FilenameSlot =
325 acquireSlot(FilenameShard.CacheLock, FilenameShard.CacheByFilename,
326 FilenameForLookup);
327 if (auto *Resolved = std::get_if<SlotResolved>(&FilenameSlot))
328 return *Resolved;
329 auto FilenameProducer = std::move(std::get<SlotProducer>(FilenameSlot));
330
331 // Compute the outcome. Three cases:
332 // - Stat succeeded: delegate to the UID resolver.
333 // - Stat failed, cacheable: defer error-entry allocation to the critical
334 // section below so allocate+bind+reset share one shard-lock acquisition.
335 // - Stat failed, not cacheable: publish the error to current waiters but
336 // don't persist; a later separate query re-runs the stat (so a file
337 // created mid-scan becomes visible).
338 auto Stat = BaseFS->status(OriginalFilename);
339 const bool ShouldCacheNegativeStat =
340 !Stat && Service.getOpts().CacheNegativeStats &&
341 shouldCacheNegativeStatsForPath(OriginalFilename);
342 llvm::ErrorOr<const CachedFileSystemEntry *> Result = std::error_code{};
343 if (Stat)
344 Result = resolveUIDThroughSharedCache(OriginalFilename, *Stat);
345 else if (!ShouldCacheNegativeStat)
346 Result = Stat.getError();
347
348 // Bind the result and reset the in-flight slot under a single critical
349 // section. The cached-negative case allocates here so allocate+bind+reset
350 // share one shard-lock acquisition.
351 {
352 std::lock_guard<std::mutex> ShardLock(FilenameShard.CacheLock);
353 auto &State = FilenameShard.CacheByFilename[FilenameForLookup];
354 assert(!State.Entry && "filename slot already published an entry");
355 if (ShouldCacheNegativeStat) {
356 auto *Entry = new (FilenameShard.EntryStorage.Allocate())
357 CachedFileSystemEntry(Stat.getError());
358 State.Entry = Entry;
359 Result = Entry;
360 } else if (Result) {
361 State.Entry = *Result;
362 }
363 State.InProgress.reset();
364 }
365 FilenameProducer->publish(Result);
366 return Result;
367}
368
369llvm::ErrorOr<EntryRef>
371 StringRef OriginalFilename) {
372 SmallString<256> PathBuf;
373 auto FilenameForLookup = tryGetFilenameForLookup(OriginalFilename, PathBuf);
374 if (!FilenameForLookup)
375 return FilenameForLookup.getError();
376
377 auto &Local = LocalCache[*FilenameForLookup];
378 if (Local.File)
379 return EntryRef(OriginalFilename, *Local.File).unwrapError();
380
381 auto MaybeEntry =
382 resolveFilenameThroughSharedCache(OriginalFilename, *FilenameForLookup);
383 if (!MaybeEntry)
384 return MaybeEntry.getError();
385 Local.File = *MaybeEntry;
386 return EntryRef(OriginalFilename, **MaybeEntry).unwrapError();
387}
388
389llvm::ErrorOr<llvm::vfs::Status>
391 SmallString<256> OwnedFilename;
392 StringRef Filename = Path.toStringRef(OwnedFilename);
393
394 llvm::ErrorOr<EntryRef> Result = getOrCreateFileSystemEntry(Filename);
395 if (!Result)
396 return Result.getError();
397 return Result->getStatus();
398}
399
401 // While some VFS overlay filesystems may implement more-efficient
402 // mechanisms for `exists` queries, `DependencyScanningWorkerFilesystem`
403 // typically wraps `RealFileSystem` which does not specialize `exists`,
404 // so it is not likely to benefit from such optimizations. Instead,
405 // it is more-valuable to have this query go through the
406 // cached-`status` code-path of the `DependencyScanningWorkerFilesystem`.
407 llvm::ErrorOr<llvm::vfs::Status> Status = status(Path);
408 return Status && Status->exists();
409}
410
411namespace {
412
413/// The VFS that is used by clang consumes the \c CachedFileSystemEntry using
414/// this subclass.
415class DepScanFile final : public llvm::vfs::File {
416public:
417 DepScanFile(std::unique_ptr<llvm::MemoryBuffer> Buffer,
418 llvm::vfs::Status Stat)
419 : Buffer(std::move(Buffer)), Stat(std::move(Stat)) {}
420
421 static llvm::ErrorOr<std::unique_ptr<llvm::vfs::File>> create(EntryRef Entry);
422
423 llvm::ErrorOr<llvm::vfs::Status> status() override { return Stat; }
424
425 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
426 getBuffer(const Twine &Name, int64_t FileSize, bool RequiresNullTerminator,
427 bool IsVolatile) override {
428 return llvm::MemoryBuffer::getMemBuffer(Buffer->getMemBufferRef(),
429 RequiresNullTerminator);
430 }
431
432 std::error_code close() override { return {}; }
433
434private:
435 std::unique_ptr<llvm::MemoryBuffer> Buffer;
436 llvm::vfs::Status Stat;
437};
438
439} // end anonymous namespace
440
441llvm::ErrorOr<std::unique_ptr<llvm::vfs::File>>
442DepScanFile::create(EntryRef Entry) {
443 assert(!Entry.isError() && "error");
444
445 if (Entry.isDirectory())
446 return std::make_error_code(std::errc::is_a_directory);
447
448 auto Result = std::make_unique<DepScanFile>(
449 llvm::MemoryBuffer::getMemBuffer(Entry.getContents(),
450 Entry.getStatus().getName(),
451 /*RequiresNullTerminator=*/false),
452 Entry.getStatus());
453
454 return llvm::ErrorOr<std::unique_ptr<llvm::vfs::File>>(
455 std::unique_ptr<llvm::vfs::File>(std::move(Result)));
456}
457
458llvm::ErrorOr<std::unique_ptr<llvm::vfs::File>>
460 SmallString<256> OwnedFilename;
461 StringRef Filename = Path.toStringRef(OwnedFilename);
462
463 llvm::ErrorOr<EntryRef> Result = getOrCreateFileSystemEntry(Filename);
464 if (!Result)
465 return Result.getError();
466 return DepScanFile::create(Result.get());
467}
468
469std::error_code
471 SmallVectorImpl<char> &Output) {
472 SmallString<256> OwnedFilename;
473 StringRef OriginalFilename = Path.toStringRef(OwnedFilename);
474
475 SmallString<256> PathBuf;
476 auto FilenameForLookup = tryGetFilenameForLookup(OriginalFilename, PathBuf);
477 if (!FilenameForLookup)
478 return FilenameForLookup.getError();
479
480 auto HandleCachedRealPath =
481 [&Output](const CachedRealPath &RealPath) -> std::error_code {
482 if (!RealPath)
483 return RealPath.getError();
484 Output.assign(RealPath->begin(), RealPath->end());
485 return {};
486 };
487
488 // If we already have the result in local cache, no work required.
489 auto &Local = LocalCache[*FilenameForLookup];
490 if (Local.RealPath)
491 return HandleCachedRealPath(*Local.RealPath);
492
493 // Resolve through the local VFS without going through the shared cache.
494 if (LocalFS && LocalFS->exists(OriginalFilename)) {
495 std::error_code EC = LocalFS->getRealPath(OriginalFilename, Output);
496 CachedRealPath RealPath = EC;
497 if (!EC)
498 RealPath = std::string(Output.begin(), Output.end());
499 Local.RealPath = new (LocalRealPathStorage.Allocate())
500 CachedRealPath(std::move(RealPath));
501 return HandleCachedRealPath(*Local.RealPath);
502 }
503
504 // If we have the result in the shared cache, cache it locally.
505 auto &Shard =
506 Service.getSharedCache().getShardForFilename(*FilenameForLookup);
507 if (const auto *ShardRealPath =
508 Shard.findRealPathByFilename(*FilenameForLookup)) {
509 Local.RealPath = ShardRealPath;
510 return HandleCachedRealPath(*Local.RealPath);
511 }
512
513 // If we don't know the real path, compute it...
514 std::error_code EC = BaseFS->getRealPath(OriginalFilename, Output);
515 llvm::ErrorOr<llvm::StringRef> ComputedRealPath = EC;
516 if (!EC)
517 ComputedRealPath = StringRef{Output.data(), Output.size()};
518
519 // ...and try to write it into the shared cache. In case some other thread won
520 // this race and already wrote its own result there, just adopt it. Write
521 // whatever is in the shared cache into the local one.
522 const auto &RealPath = Shard.getOrEmplaceRealPathForFilename(
523 *FilenameForLookup, ComputedRealPath);
524 Local.RealPath = &RealPath;
525 return HandleCachedRealPath(*Local.RealPath);
526}
527
529 const Twine &Path) {
530 std::error_code EC = ProxyFileSystem::setCurrentWorkingDirectory(Path);
531 updateWorkingDirForCacheLookup();
532 return EC;
533}
534
535void DependencyScanningWorkerFilesystem::updateWorkingDirForCacheLookup() {
536 llvm::ErrorOr<std::string> CWD =
537 getUnderlyingFS().getCurrentWorkingDirectory();
538 if (!CWD) {
539 WorkingDirForCacheLookup = CWD.getError();
540 } else if (!llvm::sys::path::is_absolute_gnu(*CWD)) {
541 WorkingDirForCacheLookup = llvm::errc::invalid_argument;
542 } else {
543 WorkingDirForCacheLookup = *CWD;
544 }
545 assert(!WorkingDirForCacheLookup ||
546 llvm::sys::path::is_absolute_gnu(*WorkingDirForCacheLookup));
547}
548
549llvm::ErrorOr<StringRef>
550DependencyScanningWorkerFilesystem::tryGetFilenameForLookup(
551 StringRef OriginalFilename, llvm::SmallVectorImpl<char> &PathBuf) const {
552 StringRef FilenameForLookup;
553 if (llvm::sys::path::is_absolute_gnu(OriginalFilename)) {
554 FilenameForLookup = OriginalFilename;
555 } else if (!WorkingDirForCacheLookup) {
556 return WorkingDirForCacheLookup.getError();
557 } else {
558 StringRef RelFilename = OriginalFilename;
559 RelFilename.consume_front("./");
560 PathBuf.assign(WorkingDirForCacheLookup->begin(),
561 WorkingDirForCacheLookup->end());
562 llvm::sys::path::append(PathBuf, RelFilename);
563 FilenameForLookup = StringRef{PathBuf.begin(), PathBuf.size()};
564 }
565 assert(llvm::sys::path::is_absolute_gnu(FilenameForLookup));
566 return FilenameForLookup;
567}
568
static IntrusiveRefCntPtr< llvm::vfs::FileSystem > combineGlobalAndLocalFS(IntrusiveRefCntPtr< llvm::vfs::FileSystem > GlobalFS, IntrusiveRefCntPtr< llvm::vfs::FileSystem > LocalFS)
An in-memory representation of a file system entity that is of interest to the dependency scanning fi...
CacheShard & getShardForFilename(StringRef Filename) const
Returns shard for the given key.
std::vector< OutOfDateEntry > getOutOfDateEntries(llvm::vfs::FileSystem &UnderlyingFS) const
Visits all cached entries and re-stat an entry using UnderlyingFS to check if the cache contains out-...
The dependency scanning service contains shared configuration and state that is used by the individua...
std::error_code getRealPath(const Twine &Path, SmallVectorImpl< char > &Output) override
DependencyScanningWorkerFilesystem(DependencyScanningService &Service, IntrusiveRefCntPtr< llvm::vfs::FileSystem > FS, IntrusiveRefCntPtr< llvm::vfs::FileSystem > LocalFS=nullptr)
bool ensureDirectiveTokensArePopulated(EntryRef Entry)
Ensure the directive tokens are populated for this file entry.
bool exists(const Twine &Path) override
Check whether Path exists.
llvm::ErrorOr< EntryRef > getOrCreateFileSystemEntry(StringRef Filename)
Returns entry for the given filename.
llvm::ErrorOr< std::unique_ptr< llvm::vfs::File > > openFileForRead(const Twine &Path) override
std::error_code setCurrentWorkingDirectory(const Twine &Path) override
llvm::ErrorOr< llvm::vfs::Status > status(const Twine &Path) override
Reference to a CachedFileSystemEntry.
llvm::ErrorOr< EntryRef > unwrapError() const
If the cached entry represents an error, promotes it into ErrorOr.
llvm::ErrorOr< std::string > CachedRealPath
bool shouldCacheNegativeStatsForPath(StringRef Path)
Top level wrappers for InstallAPI frontend operations.
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
bool scanSourceForDependencyDirectives(StringRef Input, SmallVectorImpl< dependency_directives_scan::Token > &Tokens, SmallVectorImpl< dependency_directives_scan::Directive > &Directives, DiagnosticsEngine *Diags=nullptr, SourceLocation InputSourceLoc=SourceLocation())
Scan the input for the preprocessor directives that might have an effect on the dependencies for a co...
@ Result
The result type of a method or function.
Definition TypeBase.h:906
Diagnostic wrappers for TextAPI types for error reporting.
Definition Dominators.h:30
hash_code hash_value(const clang::dependencies::ModuleID &ID)
__builtin_elementwise_add_sat __builtin_elementwise_sub_sat __builtin_riscv_ssha_i32 __builtin_riscv_sshl_u32 __builtin_riscv_nclipu_u32 int64_t
Contents and directive tokens of a cached file entry.
std::unique_ptr< llvm::MemoryBuffer > Original
Owning storage for the original contents.
SmallVector< dependency_directives_scan::Token, 10 > DepDirectiveTokens
std::atomic< const std::optional< DependencyDirectivesTy > * > DepDirectives
Accessor to the directive tokens that's atomic to avoid data races.
std::mutex ValueLock
The mutex that must be locked before mutating directive tokens.
llvm::StringMap< FilenameCacheState, llvm::BumpPtrAllocator > CacheByFilename
Map from filenames to their cached state.
llvm::SpecificBumpPtrAllocator< CachedRealPath > RealPathStorage
The backing storage for cached real paths.
const CachedRealPath * findRealPathByFilename(StringRef Filename) const
Returns the real path associated with the filename or nullptr if none is found.
std::mutex CacheLock
The mutex that needs to be locked before mutation of any member.
const CachedRealPath & getOrEmplaceRealPathForFilename(StringRef Filename, llvm::ErrorOr< StringRef > RealPath)
Returns the real path associated with the filename if there is some.
In-flight slot used to dedup concurrent producers for the same key.