diff options
author | Michael Spencer <bigcheesegs@gmail.com> | 2024-01-30 15:39:18 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-30 15:39:18 -0800 |
commit | 7847e44594aa932c0a5f5d2cd15940d2a815c059 (patch) | |
tree | debc338a0ad7726ec484fab51fcf6504d8f3b357 /llvm/unittests/Support/VirtualFileSystemTest.cpp | |
parent | 16c15b5f84836d81084e9987701ca011da5a864f (diff) | |
download | llvm-7847e44594aa932c0a5f5d2cd15940d2a815c059.zip llvm-7847e44594aa932c0a5f5d2cd15940d2a815c059.tar.gz llvm-7847e44594aa932c0a5f5d2cd15940d2a815c059.tar.bz2 |
[clang][DependencyScanner] Remove unused -ivfsoverlay files (#73734)
`-ivfsoverlay` files are unused when building most modules. Enable
removing them by,
* adding a way to visit the filesystem tree with extensible RTTI to
access each `RedirectingFileSystem`.
* Adding tracking to `RedirectingFileSystem` to record when it
actually redirects a file access.
* Storing this information in each PCM.
Usage tracking is only enabled when iterating over the source manager
and affecting modulemaps. Here each path is stated to cause an access.
During scanning these stats all hit the cache.
Diffstat (limited to 'llvm/unittests/Support/VirtualFileSystemTest.cpp')
-rw-r--r-- | llvm/unittests/Support/VirtualFileSystemTest.cpp | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/llvm/unittests/Support/VirtualFileSystemTest.cpp b/llvm/unittests/Support/VirtualFileSystemTest.cpp index 54a6e0fb..d4abbb4 100644 --- a/llvm/unittests/Support/VirtualFileSystemTest.cpp +++ b/llvm/unittests/Support/VirtualFileSystemTest.cpp @@ -895,6 +895,47 @@ TEST(VirtualFileSystemTest, HiddenInIteration) { } } +TEST(VirtualFileSystemTest, Visit) { + IntrusiveRefCntPtr<DummyFileSystem> Base(new DummyFileSystem()); + IntrusiveRefCntPtr<DummyFileSystem> Middle(new DummyFileSystem()); + IntrusiveRefCntPtr<DummyFileSystem> Top(new DummyFileSystem()); + IntrusiveRefCntPtr<vfs::OverlayFileSystem> O( + new vfs::OverlayFileSystem(Base)); + O->pushOverlay(Middle); + O->pushOverlay(Top); + + auto YAML = + MemoryBuffer::getMemBuffer("{\n" + " 'version': 0,\n" + " 'redirecting-with': 'redirect-only',\n" + " 'roots': [\n" + " {\n" + " 'type': 'file',\n" + " 'name': '/vfile',\n" + " 'external-contents': '/a',\n" + " }," + " ]\n" + "}"); + + IntrusiveRefCntPtr<vfs::RedirectingFileSystem> Redirecting = + vfs::RedirectingFileSystem::create(std::move(YAML), nullptr, "", nullptr, + O) + .release(); + + vfs::ProxyFileSystem PFS(Redirecting); + + std::vector<const vfs::FileSystem *> FSs; + PFS.visit([&](const vfs::FileSystem &FS) { FSs.push_back(&FS); }); + + ASSERT_EQ(size_t(6), FSs.size()); + EXPECT_TRUE(isa<vfs::ProxyFileSystem>(FSs[0])); + EXPECT_TRUE(isa<vfs::RedirectingFileSystem>(FSs[1])); + EXPECT_TRUE(isa<vfs::OverlayFileSystem>(FSs[2])); + EXPECT_TRUE(isa<vfs::FileSystem>(FSs[3])); + EXPECT_TRUE(isa<vfs::FileSystem>(FSs[4])); + EXPECT_TRUE(isa<vfs::FileSystem>(FSs[5])); +} + TEST(OverlayFileSystemTest, PrintOutput) { auto Dummy = makeIntrusiveRefCnt<DummyFileSystem>(); auto Overlay1 = makeIntrusiveRefCnt<vfs::OverlayFileSystem>(Dummy); @@ -3244,3 +3285,48 @@ TEST(RedirectingFileSystemTest, PrintOutput) { " DummyFileSystem (RecursiveContents)\n", Output); } + +TEST(RedirectingFileSystemTest, Used) { + auto Dummy = makeIntrusiveRefCnt<DummyFileSystem>(); + auto YAML1 = + MemoryBuffer::getMemBuffer("{\n" + " 'version': 0,\n" + " 'redirecting-with': 'fallthrough',\n" + " 'roots': [\n" + " {\n" + " 'type': 'file',\n" + " 'name': '/vfile1',\n" + " 'external-contents': '/a',\n" + " }," + " ]\n" + "}"); + auto YAML2 = + MemoryBuffer::getMemBuffer("{\n" + " 'version': 0,\n" + " 'redirecting-with': 'fallthrough',\n" + " 'roots': [\n" + " {\n" + " 'type': 'file',\n" + " 'name': '/vfile2',\n" + " 'external-contents': '/b',\n" + " }," + " ]\n" + "}"); + + Dummy->addRegularFile("/a"); + Dummy->addRegularFile("/b"); + + IntrusiveRefCntPtr<vfs::RedirectingFileSystem> Redirecting1 = + vfs::RedirectingFileSystem::create(std::move(YAML1), nullptr, "", nullptr, + Dummy) + .release(); + auto Redirecting2 = vfs::RedirectingFileSystem::create( + std::move(YAML2), nullptr, "", nullptr, Redirecting1); + + Redirecting1->setUsageTrackingActive(true); + Redirecting2->setUsageTrackingActive(true); + EXPECT_TRUE(Redirecting2->exists("/vfile1")); + EXPECT_TRUE(Redirecting2->exists("/b")); + EXPECT_TRUE(Redirecting1->hasBeenUsed()); + EXPECT_FALSE(Redirecting2->hasBeenUsed()); +} |