Skip to content

Commit 06f64d5

Browse files
committedMar 5, 2019
Replace clang::FileData with llvm::vfs::Status
Summary: FileData was only ever used as a container for the values in llvm::vfs::Status, so they might as well be consolidated. The `InPCH` member was also always set to false, and unused. Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D58924 llvm-svn: 355368
1 parent 1c014d7 commit 06f64d5

File tree

6 files changed

+65
-102
lines changed

6 files changed

+65
-102
lines changed
 

‎clang/include/clang/Basic/FileManager.h

+2-6
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,14 @@ class FileEntry {
6767
unsigned UID; // A unique (small) ID for the file.
6868
llvm::sys::fs::UniqueID UniqueID;
6969
bool IsNamedPipe;
70-
bool InPCH;
7170
bool IsValid; // Is this \c FileEntry initialized and valid?
7271

7372
/// The open file, if it is owned by the \p FileEntry.
7473
mutable std::unique_ptr<llvm::vfs::File> File;
7574

7675
public:
7776
FileEntry()
78-
: UniqueID(0, 0), IsNamedPipe(false), InPCH(false), IsValid(false)
77+
: UniqueID(0, 0), IsNamedPipe(false), IsValid(false)
7978
{}
8079

8180
FileEntry(const FileEntry &) = delete;
@@ -87,7 +86,6 @@ class FileEntry {
8786
off_t getSize() const { return Size; }
8887
unsigned getUID() const { return UID; }
8988
const llvm::sys::fs::UniqueID &getUniqueID() const { return UniqueID; }
90-
bool isInPCH() const { return InPCH; }
9189
time_t getModificationTime() const { return ModTime; }
9290

9391
/// Return the directory the file lives in.
@@ -108,8 +106,6 @@ class FileEntry {
108106
bool isOpenForTests() const { return File != nullptr; }
109107
};
110108

111-
struct FileData;
112-
113109
/// Implements support for file system lookup, file system caching,
114110
/// and directory search management.
115111
///
@@ -168,7 +164,7 @@ class FileManager : public RefCountedBase<FileManager> {
168164
// Caching.
169165
std::unique_ptr<FileSystemStatCache> StatCache;
170166

171-
bool getStatValue(StringRef Path, FileData &Data, bool isFile,
167+
bool getStatValue(StringRef Path, llvm::vfs::Status &Status, bool isFile,
172168
std::unique_ptr<llvm::vfs::File> *F);
173169

174170
/// Add all ancestors of the given path (pointing to either a file

‎clang/include/clang/Basic/FileSystemStatCache.h

+8-31
Original file line numberDiff line numberDiff line change
@@ -19,40 +19,15 @@
1919
#include "llvm/ADT/StringRef.h"
2020
#include "llvm/Support/Allocator.h"
2121
#include "llvm/Support/FileSystem.h"
22+
#include "llvm/Support/VirtualFileSystem.h"
2223
#include <cstdint>
2324
#include <ctime>
2425
#include <memory>
2526
#include <string>
2627
#include <utility>
2728

28-
namespace llvm {
29-
30-
namespace vfs {
31-
32-
class File;
33-
class FileSystem;
34-
35-
} // namespace vfs
36-
} // namespace llvm
37-
3829
namespace clang {
3930

40-
// FIXME: should probably replace this with vfs::Status
41-
struct FileData {
42-
std::string Name;
43-
uint64_t Size = 0;
44-
time_t ModTime = 0;
45-
llvm::sys::fs::UniqueID UniqueID;
46-
bool IsDirectory = false;
47-
bool IsNamedPipe = false;
48-
bool InPCH = false;
49-
50-
// FIXME: remove this when files support multiple names
51-
bool IsVFSMapped = false;
52-
53-
FileData() = default;
54-
};
55-
5631
/// Abstract interface for introducing a FileManager cache for 'stat'
5732
/// system calls, which is used by precompiled and pretokenized headers to
5833
/// improve performance.
@@ -80,15 +55,16 @@ class FileSystemStatCache {
8055
/// success for directories (not files). On a successful file lookup, the
8156
/// implementation can optionally fill in \p F with a valid \p File object and
8257
/// the client guarantees that it will close it.
83-
static bool get(StringRef Path, FileData &Data, bool isFile,
58+
static bool get(StringRef Path, llvm::vfs::Status &Status, bool isFile,
8459
std::unique_ptr<llvm::vfs::File> *F,
8560
FileSystemStatCache *Cache, llvm::vfs::FileSystem &FS);
8661

8762
protected:
8863
// FIXME: The pointer here is a non-owning/optional reference to the
8964
// unique_ptr. Optional<unique_ptr<vfs::File>&> might be nicer, but
9065
// Optional needs some work to support references so this isn't possible yet.
91-
virtual LookupResult getStat(StringRef Path, FileData &Data, bool isFile,
66+
virtual LookupResult getStat(StringRef Path, llvm::vfs::Status &Status,
67+
bool isFile,
9268
std::unique_ptr<llvm::vfs::File> *F,
9369
llvm::vfs::FileSystem &FS) = 0;
9470
};
@@ -99,15 +75,16 @@ class FileSystemStatCache {
9975
class MemorizeStatCalls : public FileSystemStatCache {
10076
public:
10177
/// The set of stat() calls that have been seen.
102-
llvm::StringMap<FileData, llvm::BumpPtrAllocator> StatCalls;
78+
llvm::StringMap<llvm::vfs::Status, llvm::BumpPtrAllocator> StatCalls;
10379

10480
using iterator =
105-
llvm::StringMap<FileData, llvm::BumpPtrAllocator>::const_iterator;
81+
llvm::StringMap<llvm::vfs::Status,
82+
llvm::BumpPtrAllocator>::const_iterator;
10683

10784
iterator begin() const { return StatCalls.begin(); }
10885
iterator end() const { return StatCalls.end(); }
10986

110-
LookupResult getStat(StringRef Path, FileData &Data, bool isFile,
87+
LookupResult getStat(StringRef Path, llvm::vfs::Status &Status, bool isFile,
11188
std::unique_ptr<llvm::vfs::File> *F,
11289
llvm::vfs::FileSystem &FS) override;
11390
};

‎clang/lib/Basic/FileManager.cpp

+29-26
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ const DirectoryEntry *FileManager::getDirectory(StringRef DirName,
144144
StringRef InterndDirName = NamedDirEnt.first();
145145

146146
// Check to see if the directory exists.
147-
FileData Data;
148-
if (getStatValue(InterndDirName, Data, false, nullptr /*directory lookup*/)) {
147+
llvm::vfs::Status Status;
148+
if (getStatValue(InterndDirName, Status, false, nullptr /*directory lookup*/)) {
149149
// There's no real directory at the given path.
150150
if (!CacheFailure)
151151
SeenDirEntries.erase(DirName);
@@ -156,7 +156,7 @@ const DirectoryEntry *FileManager::getDirectory(StringRef DirName,
156156
// same inode (this occurs on Unix-like systems when one dir is
157157
// symlinked to another, for example) or the same path (on
158158
// Windows).
159-
DirectoryEntry &UDE = UniqueRealDirs[Data.UniqueID];
159+
DirectoryEntry &UDE = UniqueRealDirs[Status.getUniqueID()];
160160

161161
NamedDirEnt.second = &UDE;
162162
if (UDE.getName().empty()) {
@@ -205,8 +205,8 @@ const FileEntry *FileManager::getFile(StringRef Filename, bool openFile,
205205

206206
// Check to see if the file exists.
207207
std::unique_ptr<llvm::vfs::File> F;
208-
FileData Data;
209-
if (getStatValue(InterndFileName, Data, true, openFile ? &F : nullptr)) {
208+
llvm::vfs::Status Status;
209+
if (getStatValue(InterndFileName, Status, true, openFile ? &F : nullptr)) {
210210
// There's no real file at the given path.
211211
if (!CacheFailure)
212212
SeenFileEntries.erase(Filename);
@@ -218,14 +218,15 @@ const FileEntry *FileManager::getFile(StringRef Filename, bool openFile,
218218

219219
// It exists. See if we have already opened a file with the same inode.
220220
// This occurs when one dir is symlinked to another, for example.
221-
FileEntry &UFE = UniqueRealFiles[Data.UniqueID];
221+
FileEntry &UFE = UniqueRealFiles[Status.getUniqueID()];
222222

223223
NamedFileEnt.second = &UFE;
224224

225225
// If the name returned by getStatValue is different than Filename, re-intern
226226
// the name.
227-
if (Data.Name != Filename) {
228-
auto &NamedFileEnt = *SeenFileEntries.insert({Data.Name, &UFE}).first;
227+
if (Status.getName() != Filename) {
228+
auto &NamedFileEnt =
229+
*SeenFileEntries.insert({Status.getName(), &UFE}).first;
229230
assert(NamedFileEnt.second == &UFE &&
230231
"filename from getStatValue() refers to wrong file");
231232
InterndFileName = NamedFileEnt.first().data();
@@ -239,7 +240,7 @@ const FileEntry *FileManager::getFile(StringRef Filename, bool openFile,
239240
// module's structure when its headers/module map are mapped in the VFS.
240241
// We should remove this as soon as we can properly support a file having
241242
// multiple names.
242-
if (DirInfo != UFE.Dir && Data.IsVFSMapped)
243+
if (DirInfo != UFE.Dir && Status.IsVFSMapped)
243244
UFE.Dir = DirInfo;
244245

245246
// Always update the name to use the last name by which a file was accessed.
@@ -254,13 +255,12 @@ const FileEntry *FileManager::getFile(StringRef Filename, bool openFile,
254255

255256
// Otherwise, we don't have this file yet, add it.
256257
UFE.Name = InterndFileName;
257-
UFE.Size = Data.Size;
258-
UFE.ModTime = Data.ModTime;
258+
UFE.Size = Status.getSize();
259+
UFE.ModTime = llvm::sys::toTimeT(Status.getLastModificationTime());
259260
UFE.Dir = DirInfo;
260261
UFE.UID = NextFileUID++;
261-
UFE.UniqueID = Data.UniqueID;
262-
UFE.IsNamedPipe = Data.IsNamedPipe;
263-
UFE.InPCH = Data.InPCH;
262+
UFE.UniqueID = Status.getUniqueID();
263+
UFE.IsNamedPipe = Status.getType() == llvm::sys::fs::file_type::fifo_file;
264264
UFE.File = std::move(F);
265265
UFE.IsValid = true;
266266

@@ -298,12 +298,15 @@ FileManager::getVirtualFile(StringRef Filename, off_t Size,
298298
"The directory of a virtual file should already be in the cache.");
299299

300300
// Check to see if the file exists. If so, drop the virtual file
301-
FileData Data;
301+
llvm::vfs::Status Status;
302302
const char *InterndFileName = NamedFileEnt.first().data();
303-
if (getStatValue(InterndFileName, Data, true, nullptr) == 0) {
304-
Data.Size = Size;
305-
Data.ModTime = ModificationTime;
306-
UFE = &UniqueRealFiles[Data.UniqueID];
303+
if (getStatValue(InterndFileName, Status, true, nullptr) == 0) {
304+
UFE = &UniqueRealFiles[Status.getUniqueID()];
305+
Status = llvm::vfs::Status(
306+
Status.getName(), Status.getUniqueID(),
307+
llvm::sys::toTimePoint(ModificationTime),
308+
Status.getUser(), Status.getGroup(), Size,
309+
Status.getType(), Status.getPermissions());
307310

308311
NamedFileEnt.second = UFE;
309312

@@ -317,10 +320,9 @@ FileManager::getVirtualFile(StringRef Filename, off_t Size,
317320
if (UFE->isValid())
318321
return UFE;
319322

320-
UFE->UniqueID = Data.UniqueID;
321-
UFE->IsNamedPipe = Data.IsNamedPipe;
322-
UFE->InPCH = Data.InPCH;
323-
fillRealPathName(UFE, Data.Name);
323+
UFE->UniqueID = Status.getUniqueID();
324+
UFE->IsNamedPipe = Status.getType() == llvm::sys::fs::file_type::fifo_file;
325+
fillRealPathName(UFE, Status.getName());
324326
} else {
325327
VirtualFileEntries.push_back(llvm::make_unique<FileEntry>());
326328
UFE = VirtualFileEntries.back().get();
@@ -421,17 +423,18 @@ FileManager::getBufferForFile(StringRef Filename, bool isVolatile) {
421423
/// if the path points to a virtual file or does not exist, or returns
422424
/// false if it's an existent real file. If FileDescriptor is NULL,
423425
/// do directory look-up instead of file look-up.
424-
bool FileManager::getStatValue(StringRef Path, FileData &Data, bool isFile,
426+
bool FileManager::getStatValue(StringRef Path, llvm::vfs::Status &Status,
427+
bool isFile,
425428
std::unique_ptr<llvm::vfs::File> *F) {
426429
// FIXME: FileSystemOpts shouldn't be passed in here, all paths should be
427430
// absolute!
428431
if (FileSystemOpts.WorkingDir.empty())
429-
return FileSystemStatCache::get(Path, Data, isFile, F,StatCache.get(), *FS);
432+
return FileSystemStatCache::get(Path, Status, isFile, F,StatCache.get(), *FS);
430433

431434
SmallString<128> FilePath(Path);
432435
FixupRelativePath(FilePath);
433436

434-
return FileSystemStatCache::get(FilePath.c_str(), Data, isFile, F,
437+
return FileSystemStatCache::get(FilePath.c_str(), Status, isFile, F,
435438
StatCache.get(), *FS);
436439
}
437440

‎clang/lib/Basic/FileSystemStatCache.cpp

+15-25
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,6 @@ using namespace clang;
2121

2222
void FileSystemStatCache::anchor() {}
2323

24-
static void copyStatusToFileData(const llvm::vfs::Status &Status,
25-
FileData &Data) {
26-
Data.Name = Status.getName();
27-
Data.Size = Status.getSize();
28-
Data.ModTime = llvm::sys::toTimeT(Status.getLastModificationTime());
29-
Data.UniqueID = Status.getUniqueID();
30-
Data.IsDirectory = Status.isDirectory();
31-
Data.IsNamedPipe = Status.getType() == llvm::sys::fs::file_type::fifo_file;
32-
Data.InPCH = false;
33-
Data.IsVFSMapped = Status.IsVFSMapped;
34-
}
35-
3624
/// FileSystemStatCache::get - Get the 'stat' information for the specified
3725
/// path, using the cache to accelerate it if possible. This returns true if
3826
/// the path does not exist or false if it exists.
@@ -42,7 +30,8 @@ static void copyStatusToFileData(const llvm::vfs::Status &Status,
4230
/// success for directories (not files). On a successful file lookup, the
4331
/// implementation can optionally fill in FileDescriptor with a valid
4432
/// descriptor and the client guarantees that it will close it.
45-
bool FileSystemStatCache::get(StringRef Path, FileData &Data, bool isFile,
33+
bool FileSystemStatCache::get(StringRef Path, llvm::vfs::Status &Status,
34+
bool isFile,
4635
std::unique_ptr<llvm::vfs::File> *F,
4736
FileSystemStatCache *Cache,
4837
llvm::vfs::FileSystem &FS) {
@@ -51,16 +40,16 @@ bool FileSystemStatCache::get(StringRef Path, FileData &Data, bool isFile,
5140

5241
// If we have a cache, use it to resolve the stat query.
5342
if (Cache)
54-
R = Cache->getStat(Path, Data, isFile, F, FS);
43+
R = Cache->getStat(Path, Status, isFile, F, FS);
5544
else if (isForDir || !F) {
5645
// If this is a directory or a file descriptor is not needed and we have
5746
// no cache, just go to the file system.
58-
llvm::ErrorOr<llvm::vfs::Status> Status = FS.status(Path);
59-
if (!Status) {
47+
llvm::ErrorOr<llvm::vfs::Status> StatusOrErr = FS.status(Path);
48+
if (!StatusOrErr) {
6049
R = CacheMissing;
6150
} else {
6251
R = CacheExists;
63-
copyStatusToFileData(*Status, Data);
52+
Status = *StatusOrErr;
6453
}
6554
} else {
6655
// Otherwise, we have to go to the filesystem. We can always just use
@@ -79,10 +68,10 @@ bool FileSystemStatCache::get(StringRef Path, FileData &Data, bool isFile,
7968
// Otherwise, the open succeeded. Do an fstat to get the information
8069
// about the file. We'll end up returning the open file descriptor to the
8170
// client to do what they please with it.
82-
llvm::ErrorOr<llvm::vfs::Status> Status = (*OwnedFile)->status();
83-
if (Status) {
71+
llvm::ErrorOr<llvm::vfs::Status> StatusOrErr = (*OwnedFile)->status();
72+
if (StatusOrErr) {
8473
R = CacheExists;
85-
copyStatusToFileData(*Status, Data);
74+
Status = *StatusOrErr;
8675
*F = std::move(*OwnedFile);
8776
} else {
8877
// fstat rarely fails. If it does, claim the initial open didn't
@@ -98,7 +87,7 @@ bool FileSystemStatCache::get(StringRef Path, FileData &Data, bool isFile,
9887

9988
// If the path exists, make sure that its "directoryness" matches the clients
10089
// demands.
101-
if (Data.IsDirectory != isForDir) {
90+
if (Status.isDirectory() != isForDir) {
10291
// If not, close the file if opened.
10392
if (F)
10493
*F = nullptr;
@@ -110,10 +99,11 @@ bool FileSystemStatCache::get(StringRef Path, FileData &Data, bool isFile,
11099
}
111100

112101
MemorizeStatCalls::LookupResult
113-
MemorizeStatCalls::getStat(StringRef Path, FileData &Data, bool isFile,
102+
MemorizeStatCalls::getStat(StringRef Path, llvm::vfs::Status &Status,
103+
bool isFile,
114104
std::unique_ptr<llvm::vfs::File> *F,
115105
llvm::vfs::FileSystem &FS) {
116-
if (get(Path, Data, isFile, F, nullptr, FS)) {
106+
if (get(Path, Status, isFile, F, nullptr, FS)) {
117107
// Do not cache failed stats, it is easy to construct common inconsistent
118108
// situations if we do, and they are not important for PCH performance
119109
// (which currently only needs the stats to construct the initial
@@ -122,8 +112,8 @@ MemorizeStatCalls::getStat(StringRef Path, FileData &Data, bool isFile,
122112
}
123113

124114
// Cache file 'stat' results and directories with absolutely paths.
125-
if (!Data.IsDirectory || llvm::sys::path::is_absolute(Path))
126-
StatCalls[Path] = Data;
115+
if (!Status.isDirectory() || llvm::sys::path::is_absolute(Path))
116+
StatCalls[Path] = Status;
127117

128118
return CacheExists;
129119
}

‎clang/lib/Frontend/TextDiagnostic.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -792,8 +792,6 @@ void TextDiagnostic::emitDiagnosticLoc(FullSourceLoc Loc, PresumedLoc PLoc,
792792
const FileEntry *FE = Loc.getFileEntry();
793793
if (FE && FE->isValid()) {
794794
emitFilename(FE->getName(), Loc.getManager());
795-
if (FE->isInPCH())
796-
OS << " (in PCH)";
797795
OS << ": ";
798796
}
799797
}

0 commit comments

Comments
 (0)
Please sign in to comment.