This is an archive of the discontinued LLVM Phabricator instance.

Remove all of LLDB's custom filesystem statting code.
ClosedPublic

Authored by zturner on Mar 5 2017, 9:26 AM.

Details

Summary

LLVM provides this functionality, so there is no point duplicating it. This is a pretty large patch because we call functions like FileSpec::IsRegularFile(), or FileSpec::GetFileType() all over the place, and all of these are replaced with calls to llvm now. Also deleted is LLDB's entire FileType enumeration.

I don't think it's a very important optimization, but one nice functional change is that we now stat only once when previously we would stat many times on the same file (for example calling Exists() followed by IsDirectory() followed by IsRegularFile() is 3 stats, whereas in this patch we're down to 1.

In addition to all of this, I think this is an important change because it removes an assumption previously baked into the FileSpec API that this was always a valid operation. But it is pretty common to have a FileSpec that refers to a file on a remote platform, perhaps even with an incomptible PathSyntax, and in this case it doesn't make sense to be calling these functions on it.

In any case, it's a necessary pre-requisite to getting FileSpec not be dependent on Host.

Diff Detail

Repository
rL LLVM

Event Timeline

zturner created this revision.Mar 5 2017, 9:26 AM

Can you make the usage of "using namespace llvm::sys::fs;" a bit more consistent? Sometime you write fully qualified name, sometime you add it to the top of the file while sometime only to the function where it is used.

llvm/include/llvm/Support/FileSystem.h
482–486 ↗(On Diff #90619)

Please fix the comment

labath accepted this revision.Mar 6 2017, 8:38 AM

Cool.

I would find using fs = llvm::sys::fs (or whatever is the correct namespace alias syntax) more readable, as you then still have fs:: in the references, but maybe that's just my preference...

This revision is now accepted and ready to land.Mar 6 2017, 8:38 AM
This revision was automatically updated to reflect the committed changes.
labath added a comment.Mar 7 2017, 5:41 AM

Zachary, unfortunately I had to revert this -- while investigating the breakages I've found a problem I don't think any of us realised -- llvm's statting code is based on stat(2), while lldb uses lstat(2). I think we need to go back and re-audit each case to see whether the behavior difference is a problem. In most of the cases, I think using stat would make things simpler (no need to special case symlink as a file type), but at least one case (SymbolFileDWARF) really depends on the lstat behavior (not resolving symlinks), so we need to figure out how to handle that.