Skip to content

Commit 6c1dbd5

Browse files
authored
[clang] NFC: Remove {File,Directory}Entry::getName() (#74910)
The files and directories that Clang accesses are uniqued by their inode. For each inode `FileManager` will create exactly one `FileEntry` or `DirectoryEntry` object, which makes answering the question _"Are these two files/directories the same?"_ a simple pointer equality check. However, since the same inode can be accessed through multiple different paths, asking the `FileEntry` or `DirectoryEntry` object _"What is your name?"_ doesn't have clear semantics. In c0ff990 we started reporting the most recent name used to access the entry, which turned out to be necessary for Clang modules. However, the long-term solution has always been to explicitly track the as-requested name. This has been implemented in 4dc5573 as `FileEntryRef` and `DirectoryEntryRef`. The `DirectoryEntry::getName()` interface has been deprecated since the Clang 17 release and `FileEntry::getName()` since Clang 18. We have replaced uses of these deprecated APIs in `main` with `DirectoryEntryRef::getName()` and `FileEntryRef::getName()` respectively. This makes it possible to remove `{File,Directory}Entry::getName()` for good along with the `FileManager` code that implements them.
1 parent 56444d5 commit 6c1dbd5

File tree

7 files changed

+0
-71
lines changed

7 files changed

+0
-71
lines changed

clang/include/clang/Basic/DirectoryEntry.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,6 @@ class DirectoryEntry {
4141
DirectoryEntry &operator=(const DirectoryEntry &) = delete;
4242
friend class FileManager;
4343
friend class FileEntryTestHelper;
44-
45-
// FIXME: We should not be storing a directory entry name here.
46-
StringRef Name; // Name of the directory.
47-
48-
public:
49-
LLVM_DEPRECATED("Use DirectoryEntryRef::getName() instead.", "")
50-
StringRef getName() const { return Name; }
5144
};
5245

5346
/// A reference to a \c DirectoryEntry that includes the name of the directory

clang/include/clang/Basic/FileEntry.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -318,18 +318,8 @@ class FileEntry {
318318
/// The file content, if it is owned by the \p FileEntry.
319319
std::unique_ptr<llvm::MemoryBuffer> Content;
320320

321-
// First access name for this FileEntry.
322-
//
323-
// This is Optional only to allow delayed construction (FileEntryRef has no
324-
// default constructor). It should always have a value in practice.
325-
//
326-
// TODO: remove this once everyone that needs a name uses FileEntryRef.
327-
OptionalFileEntryRef LastRef;
328-
329321
public:
330322
~FileEntry();
331-
LLVM_DEPRECATED("Use FileEntryRef::getName() instead.", "")
332-
StringRef getName() const { return LastRef->getName(); }
333323

334324
StringRef tryGetRealPathName() const { return RealPathName; }
335325
off_t getSize() const { return Size; }

clang/lib/Basic/FileManager.cpp

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ void FileManager::addAncestorsAsVirtualDirs(StringRef Path) {
107107

108108
// Add the virtual directory to the cache.
109109
auto *UDE = new (DirsAlloc.Allocate()) DirectoryEntry();
110-
UDE->Name = NamedDirEnt.first();
111110
NamedDirEnt.second = *UDE;
112111
VirtualDirectoryEntries.push_back(UDE);
113112

@@ -179,7 +178,6 @@ FileManager::getDirectoryRef(StringRef DirName, bool CacheFailure) {
179178
// We don't have this directory yet, add it. We use the string
180179
// key from the SeenDirEntries map as the string.
181180
UDE = new (DirsAlloc.Allocate()) DirectoryEntry();
182-
UDE->Name = InterndDirName;
183181
}
184182
NamedDirEnt.second = *UDE;
185183

@@ -324,32 +322,10 @@ FileManager::getFileRef(StringRef Filename, bool openFile, bool CacheFailure) {
324322

325323
FileEntryRef ReturnedRef(*NamedFileEnt);
326324
if (ReusingEntry) { // Already have an entry with this inode, return it.
327-
328-
// FIXME: This hack ensures that `getDir()` will use the path that was
329-
// used to lookup this file, even if we found a file by different path
330-
// first. This is required in order to find a module's structure when its
331-
// headers/module map are mapped in the VFS.
332-
//
333-
// See above for how this will eventually be removed. `IsVFSMapped`
334-
// *cannot* be narrowed to `ExposesExternalVFSPath` as crash reproducers
335-
// also depend on this logic and they have `use-external-paths: false`.
336-
if (&DirInfo.getDirEntry() != UFE->Dir && Status.IsVFSMapped)
337-
UFE->Dir = &DirInfo.getDirEntry();
338-
339-
// Always update LastRef to the last name by which a file was accessed.
340-
// FIXME: Neither this nor always using the first reference is correct; we
341-
// want to switch towards a design where we return a FileName object that
342-
// encapsulates both the name by which the file was accessed and the
343-
// corresponding FileEntry.
344-
// FIXME: LastRef should be removed from FileEntry once all clients adopt
345-
// FileEntryRef.
346-
UFE->LastRef = ReturnedRef;
347-
348325
return ReturnedRef;
349326
}
350327

351328
// Otherwise, we don't have this file yet, add it.
352-
UFE->LastRef = ReturnedRef;
353329
UFE->Size = Status.getSize();
354330
UFE->ModTime = llvm::sys::toTimeT(Status.getLastModificationTime());
355331
UFE->Dir = &DirInfo.getDirEntry();
@@ -461,7 +437,6 @@ FileEntryRef FileManager::getVirtualFileRef(StringRef Filename, off_t Size,
461437
}
462438

463439
NamedFileEnt.second = FileEntryRef::MapValue(*UFE, *DirInfo);
464-
UFE->LastRef = FileEntryRef(NamedFileEnt);
465440
UFE->Size = Size;
466441
UFE->ModTime = ModificationTime;
467442
UFE->Dir = &DirInfo->getDirEntry();
@@ -490,7 +465,6 @@ OptionalFileEntryRef FileManager::getBypassFile(FileEntryRef VF) {
490465
FileEntry *BFE = new (FilesAlloc.Allocate()) FileEntry();
491466
BypassFileEntries.push_back(BFE);
492467
Insertion.first->second = FileEntryRef::MapValue(*BFE, VF.getDir());
493-
BFE->LastRef = FileEntryRef(*Insertion.first);
494468
BFE->Size = Status.getSize();
495469
BFE->Dir = VF.getFileEntry().Dir;
496470
BFE->ModTime = llvm::sys::toTimeT(Status.getLastModificationTime());

clang/unittests/Basic/FileManagerTest.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,6 @@ TEST_F(FileManagerTest, getFileRefReturnsCorrectNameForDifferentStatPath) {
284284
ASSERT_FALSE(!F1Alias);
285285
ASSERT_FALSE(!F1Alias2);
286286
EXPECT_EQ("dir/f1.cpp", F1->getName());
287-
LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_PUSH
288-
EXPECT_EQ("dir/f1.cpp", F1->getFileEntry().getName());
289-
LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_POP
290287
EXPECT_EQ("dir/f1.cpp", F1Alias->getName());
291288
EXPECT_EQ("dir/f1.cpp", F1Alias2->getName());
292289
EXPECT_EQ(&F1->getFileEntry(), &F1Alias->getFileEntry());
@@ -305,9 +302,6 @@ TEST_F(FileManagerTest, getFileRefReturnsCorrectNameForDifferentStatPath) {
305302
ASSERT_FALSE(!F2Alias);
306303
ASSERT_FALSE(!F2Alias2);
307304
EXPECT_EQ("dir/f2.cpp", F2->getName());
308-
LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_PUSH
309-
EXPECT_EQ("dir/f2.cpp", F2->getFileEntry().getName());
310-
LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_POP
311305
EXPECT_EQ("dir/f2.cpp", F2Alias->getName());
312306
EXPECT_EQ("dir/f2.cpp", F2Alias2->getName());
313307
EXPECT_EQ(&F2->getFileEntry(), &F2Alias->getFileEntry());

llvm/include/llvm/Support/VirtualFileSystem.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@ class Status {
5555
llvm::sys::fs::perms Perms;
5656

5757
public:
58-
// FIXME: remove when files support multiple names
59-
bool IsVFSMapped = false;
60-
6158
/// Whether this entity has an external path different from the virtual path,
6259
/// and the external path is exposed by leaking it through the abstraction.
6360
/// For example, a RedirectingFileSystem will set this for paths where

llvm/lib/Support/VirtualFileSystem.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2334,7 +2334,6 @@ static Status getRedirectedFileStatus(const Twine &OriginalPath,
23342334
S = Status::copyWithNewName(S, OriginalPath);
23352335
else
23362336
S.ExposesExternalVFSPath = true;
2337-
S.IsVFSMapped = true;
23382337
return S;
23392338
}
23402339

llvm/unittests/Support/VirtualFileSystemTest.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,13 +1563,11 @@ TEST_F(VFSFromYAMLTest, MappedFiles) {
15631563
ErrorOr<vfs::Status> S = O->status("//root/file1");
15641564
ASSERT_FALSE(S.getError());
15651565
EXPECT_EQ("//root/foo/bar/a", S->getName());
1566-
EXPECT_TRUE(S->IsVFSMapped);
15671566
EXPECT_TRUE(S->ExposesExternalVFSPath);
15681567

15691568
ErrorOr<vfs::Status> SLower = O->status("//root/foo/bar/a");
15701569
EXPECT_EQ("//root/foo/bar/a", SLower->getName());
15711570
EXPECT_TRUE(S->equivalent(*SLower));
1572-
EXPECT_FALSE(SLower->IsVFSMapped);
15731571
EXPECT_FALSE(SLower->ExposesExternalVFSPath);
15741572

15751573
// file after opening
@@ -1578,7 +1576,6 @@ TEST_F(VFSFromYAMLTest, MappedFiles) {
15781576
auto OpenedS = (*OpenedF)->status();
15791577
ASSERT_FALSE(OpenedS.getError());
15801578
EXPECT_EQ("//root/foo/bar/a", OpenedS->getName());
1581-
EXPECT_TRUE(OpenedS->IsVFSMapped);
15821579
EXPECT_TRUE(OpenedS->ExposesExternalVFSPath);
15831580

15841581
// directory
@@ -1591,29 +1588,25 @@ TEST_F(VFSFromYAMLTest, MappedFiles) {
15911588
S = O->status("//root/mappeddir");
15921589
ASSERT_FALSE(S.getError());
15931590
EXPECT_TRUE(S->isDirectory());
1594-
EXPECT_TRUE(S->IsVFSMapped);
15951591
EXPECT_TRUE(S->ExposesExternalVFSPath);
15961592
EXPECT_TRUE(S->equivalent(*O->status("//root/foo/bar")));
15971593

15981594
SLower = O->status("//root/foo/bar");
15991595
EXPECT_EQ("//root/foo/bar", SLower->getName());
16001596
EXPECT_TRUE(S->equivalent(*SLower));
1601-
EXPECT_FALSE(SLower->IsVFSMapped);
16021597
EXPECT_FALSE(SLower->ExposesExternalVFSPath);
16031598

16041599
// file in remapped directory
16051600
S = O->status("//root/mappeddir/a");
16061601
ASSERT_FALSE(S.getError());
16071602
EXPECT_FALSE(S->isDirectory());
1608-
EXPECT_TRUE(S->IsVFSMapped);
16091603
EXPECT_TRUE(S->ExposesExternalVFSPath);
16101604
EXPECT_EQ("//root/foo/bar/a", S->getName());
16111605

16121606
// file in remapped directory, with use-external-name=false
16131607
S = O->status("//root/mappeddir2/a");
16141608
ASSERT_FALSE(S.getError());
16151609
EXPECT_FALSE(S->isDirectory());
1616-
EXPECT_TRUE(S->IsVFSMapped);
16171610
EXPECT_FALSE(S->ExposesExternalVFSPath);
16181611
EXPECT_EQ("//root/mappeddir2/a", S->getName());
16191612

@@ -1623,7 +1616,6 @@ TEST_F(VFSFromYAMLTest, MappedFiles) {
16231616
OpenedS = (*OpenedF)->status();
16241617
ASSERT_FALSE(OpenedS.getError());
16251618
EXPECT_EQ("//root/foo/bar/a", OpenedS->getName());
1626-
EXPECT_TRUE(OpenedS->IsVFSMapped);
16271619
EXPECT_TRUE(OpenedS->ExposesExternalVFSPath);
16281620

16291621
// file contents in remapped directory, with use-external-name=false
@@ -1632,7 +1624,6 @@ TEST_F(VFSFromYAMLTest, MappedFiles) {
16321624
OpenedS = (*OpenedF)->status();
16331625
ASSERT_FALSE(OpenedS.getError());
16341626
EXPECT_EQ("//root/mappeddir2/a", OpenedS->getName());
1635-
EXPECT_TRUE(OpenedS->IsVFSMapped);
16361627
EXPECT_FALSE(OpenedS->ExposesExternalVFSPath);
16371628

16381629
// broken mapping
@@ -1665,13 +1656,11 @@ TEST_F(VFSFromYAMLTest, MappedRoot) {
16651656
ErrorOr<vfs::Status> S = O->status("//mappedroot/a");
16661657
ASSERT_FALSE(S.getError());
16671658
EXPECT_EQ("//root/foo/bar/a", S->getName());
1668-
EXPECT_TRUE(S->IsVFSMapped);
16691659
EXPECT_TRUE(S->ExposesExternalVFSPath);
16701660

16711661
ErrorOr<vfs::Status> SLower = O->status("//root/foo/bar/a");
16721662
EXPECT_EQ("//root/foo/bar/a", SLower->getName());
16731663
EXPECT_TRUE(S->equivalent(*SLower));
1674-
EXPECT_FALSE(SLower->IsVFSMapped);
16751664
EXPECT_FALSE(SLower->ExposesExternalVFSPath);
16761665

16771666
// file after opening
@@ -1680,7 +1669,6 @@ TEST_F(VFSFromYAMLTest, MappedRoot) {
16801669
auto OpenedS = (*OpenedF)->status();
16811670
ASSERT_FALSE(OpenedS.getError());
16821671
EXPECT_EQ("//root/foo/bar/a", OpenedS->getName());
1683-
EXPECT_TRUE(OpenedS->IsVFSMapped);
16841672
EXPECT_TRUE(OpenedS->ExposesExternalVFSPath);
16851673

16861674
EXPECT_EQ(0, NumDiagnostics);
@@ -1829,13 +1817,11 @@ TEST_F(VFSFromYAMLTest, ReturnsRequestedPathVFSMiss) {
18291817
auto OpenedS = (*OpenedF)->status();
18301818
ASSERT_FALSE(OpenedS.getError());
18311819
EXPECT_EQ("a", OpenedS->getName());
1832-
EXPECT_FALSE(OpenedS->IsVFSMapped);
18331820
EXPECT_FALSE(OpenedS->ExposesExternalVFSPath);
18341821

18351822
auto DirectS = RemappedFS->status("a");
18361823
ASSERT_FALSE(DirectS.getError());
18371824
EXPECT_EQ("a", DirectS->getName());
1838-
EXPECT_FALSE(DirectS->IsVFSMapped);
18391825
EXPECT_FALSE(DirectS->ExposesExternalVFSPath);
18401826

18411827
EXPECT_EQ(0, NumDiagnostics);
@@ -1871,13 +1857,11 @@ TEST_F(VFSFromYAMLTest, ReturnsExternalPathVFSHit) {
18711857
auto OpenedS = (*OpenedF)->status();
18721858
ASSERT_FALSE(OpenedS.getError());
18731859
EXPECT_EQ("realname", OpenedS->getName());
1874-
EXPECT_TRUE(OpenedS->IsVFSMapped);
18751860
EXPECT_TRUE(OpenedS->ExposesExternalVFSPath);
18761861

18771862
auto DirectS = FS->status("vfsname");
18781863
ASSERT_FALSE(DirectS.getError());
18791864
EXPECT_EQ("realname", DirectS->getName());
1880-
EXPECT_TRUE(DirectS->IsVFSMapped);
18811865
EXPECT_TRUE(DirectS->ExposesExternalVFSPath);
18821866

18831867
EXPECT_EQ(0, NumDiagnostics);
@@ -1976,13 +1960,11 @@ TEST_F(VFSFromYAMLTest, ReturnsInternalPathVFSHit) {
19761960
auto OpenedS = (*OpenedF)->status();
19771961
ASSERT_FALSE(OpenedS.getError());
19781962
EXPECT_EQ("vfsname", OpenedS->getName());
1979-
EXPECT_TRUE(OpenedS->IsVFSMapped);
19801963
EXPECT_FALSE(OpenedS->ExposesExternalVFSPath);
19811964

19821965
auto DirectS = FS->status("vfsname");
19831966
ASSERT_FALSE(DirectS.getError());
19841967
EXPECT_EQ("vfsname", DirectS->getName());
1985-
EXPECT_TRUE(DirectS->IsVFSMapped);
19861968
EXPECT_FALSE(DirectS->ExposesExternalVFSPath);
19871969

19881970
EXPECT_EQ(0, NumDiagnostics);

0 commit comments

Comments
 (0)