aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/Basic/VirtualFileSystemTest.cpp
diff options
context:
space:
mode:
authorBruno Cardoso Lopes <bruno.cardoso@gmail.com>2016-05-12 03:23:36 +0000
committerBruno Cardoso Lopes <bruno.cardoso@gmail.com>2016-05-12 03:23:36 +0000
commitab83dc646d3eaa4f17a188b8a91c7d271ebf062e (patch)
tree981308d6fd105647a537ac8cb066611bec9e7b13 /clang/unittests/Basic/VirtualFileSystemTest.cpp
parent96f0d383a7adf48d643fbcd85a8595042ff8e84e (diff)
downloadllvm-ab83dc646d3eaa4f17a188b8a91c7d271ebf062e.zip
llvm-ab83dc646d3eaa4f17a188b8a91c7d271ebf062e.tar.gz
llvm-ab83dc646d3eaa4f17a188b8a91c7d271ebf062e.tar.bz2
[VFS] Reapply r269100: Reconstruct the VFS overlay tree for more accurate lookup
The way we currently build the internal VFS overlay representation leads to inefficient path search and might yield wrong answers when asked for recursive or regular directory iteration. Currently, when reading an YAML file, each YAML root entry is placed inside a new root in the filesystem overlay. In the crash reproducer, a simple "@import Foundation" currently maps to 43 roots, and when looking up paths, we traverse a directory tree for each of these different roots, until we find a match (or don't). This has two consequences: - It's slow. - Directory iteration gives incomplete results since it only return results within one root - since contents of the same directory can be declared inside different roots, the result isn't accurate. This is in part fault of the way we currently write out the YAML file when emitting the crash reproducer - we could generate only one root and that would make it fast and correct again. However, we should not rely on how the client writes the YAML, but provide a good internal representation regardless. This patch builds a proper virtual directory tree out of the YAML representation, allowing faster search and proper iteration. Besides the crash reproducer, this potentially benefits other VFS clients. llvm-svn: 269270
Diffstat (limited to 'clang/unittests/Basic/VirtualFileSystemTest.cpp')
-rw-r--r--clang/unittests/Basic/VirtualFileSystemTest.cpp30
1 files changed, 29 insertions, 1 deletions
diff --git a/clang/unittests/Basic/VirtualFileSystemTest.cpp b/clang/unittests/Basic/VirtualFileSystemTest.cpp
index b8e675e..f4a01ea 100644
--- a/clang/unittests/Basic/VirtualFileSystemTest.cpp
+++ b/clang/unittests/Basic/VirtualFileSystemTest.cpp
@@ -1029,9 +1029,13 @@ TEST_F(VFSFromYAMLTest, DirectoryIteration) {
Lower->addDirectory("//root/");
Lower->addDirectory("//root/foo");
Lower->addDirectory("//root/foo/bar");
+ Lower->addDirectory("//root/zab");
+ Lower->addDirectory("//root/baz");
Lower->addRegularFile("//root/foo/bar/a");
Lower->addRegularFile("//root/foo/bar/b");
Lower->addRegularFile("//root/file3");
+ Lower->addRegularFile("//root/zab/a");
+ Lower->addRegularFile("//root/zab/b");
IntrusiveRefCntPtr<vfs::FileSystem> FS =
getFromYAMLString("{ 'use-external-names': false,\n"
" 'roots': [\n"
@@ -1049,6 +1053,26 @@ TEST_F(VFSFromYAMLTest, DirectoryIteration) {
" 'external-contents': '//root/foo/bar/b'\n"
" }\n"
" ]\n"
+ "},\n"
+ "{\n"
+ " 'type': 'directory',\n"
+ " 'name': '//root/baz/',\n"
+ " 'contents': [ {\n"
+ " 'type': 'file',\n"
+ " 'name': 'x',\n"
+ " 'external-contents': '//root/zab/a'\n"
+ " }\n"
+ " ]\n"
+ "},\n"
+ "{\n"
+ " 'type': 'directory',\n"
+ " 'name': '//root/baz/',\n"
+ " 'contents': [ {\n"
+ " 'type': 'file',\n"
+ " 'name': 'y',\n"
+ " 'external-contents': '//root/zab/b'\n"
+ " }\n"
+ " ]\n"
"}\n"
"]\n"
"}",
@@ -1061,8 +1085,12 @@ TEST_F(VFSFromYAMLTest, DirectoryIteration) {
std::error_code EC;
checkContents(O->dir_begin("//root/", EC),
- {"//root/file1", "//root/file2", "//root/file3", "//root/foo"});
+ {"//root/file1", "//root/file2", "//root/baz", "//root/file3",
+ "//root/foo", "//root/zab"});
checkContents(O->dir_begin("//root/foo/bar", EC),
{"//root/foo/bar/a", "//root/foo/bar/b"});
+
+ checkContents(O->dir_begin("//root/baz/", EC),
+ {"//root/baz/x", "//root/baz/y"});
}