<div class="gmail_quote">2011/12/6 Daniel Dunbar <span dir="ltr"><<a href="mailto:daniel@zuster.org">daniel@zuster.org</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="HOEnZb"><div class="h5">On Tue, Dec 6, 2011 at 2:27 AM, Manuel Klimek <<a href="mailto:klimek@google.com">klimek@google.com</a>> wrote:<br>
> On Tue, Dec 6, 2011 at 2:11 AM, Michael Spencer <<a href="mailto:bigcheesegs@gmail.com">bigcheesegs@gmail.com</a>> wrote:<br>
>> On Sun, Dec 4, 2011 at 9:06 AM, Manuel Klimek <<a href="mailto:klimek@google.com">klimek@google.com</a>> wrote:<br>
>>> On Sat, Dec 3, 2011 at 10:33 PM, Douglas Gregor <<a href="mailto:dgregor@apple.com">dgregor@apple.com</a>> wrote:<br>
>>>> Hi Manuel,<br>
>>>><br>
>>>> On Nov 28, 2011, at 2:49 AM, Manuel Klimek wrote:<br>
>>>><br>
>>>>> Hi,<br>
>>>>><br>
>>>>> while working on tooling on top of clang/llvm we found the file system<br>
>>>>> abstractions in clang/llvm to be one of the points that could be nicer<br>
>>>>> to integrate with. I’m writing this mail to propose a strawman and get<br>
>>>>> some feedback on what you guys think the right way forward is (or<br>
>>>>> whether we should just leave things as they are).<br>
>>>>><br>
>>>>> First, the FileManager we have in clang has helped us a lot for our<br>
>>>>> tooling - when we run clang in a mapreduce we don’t need to lay out<br>
>>>>> files on a disk, we can just map files into memory and happily clang<br>
>>>>> over them. We’re also using the same mechanism to map builtin<br>
>>>>> includes; in short, the FileManager has made it possible to do clang<br>
>>>>> at scale.<br>
>>>>><br>
>>>>> Now we’re aware that it was not really the intention of the<br>
>>>>> FileManager to allow doing the things we do with it: not every module<br>
>>>>> in clang uses the FileManager, and the moment we hit llvm there is no<br>
>>>>> FileManager at all. For example, in case of the Driver we hack around<br>
>>>>> the fact that the header search tries to access the file system<br>
>>>>> driectly in rather brittle ways, relying on implementation details and<br>
>>>>> #ifdefs.<br>
>>>>><br>
>>>>> So why not make FileManager a more principled (and still blazing fast)<br>
>>>>> file system abstraction?<br>
>>>><br>
>>>> Yes, please!<br>
>>><br>
>>> Great :) /me jumps right into the design discussion then.<br>
>>><br>
>>>> Having a proper virtual file system across Clang and LLVM would be a huge boon, especially for pushing Clang into more applications that aren't simply "grab stuff from the local file system." The current FileManager/SourceManager dance used to provide in-memory content for a (virtual or old) file is quite the mess.<br>
>>>><br>
>>>>> Pro:<br>
>>>>> - only one interface for developers to learn on the project (no more<br>
>>>>> PathV1 vs PathV2 vs FileManager)<br>
>>>>> - only one implementation (per-platform) for easier maintenance of the<br>
>>>>> file system platform abstraction<br>
>>>>> - one point to insert synchronization guarantees for tools / IDE<br>
>>>>> integration that wants to run clang in multiple threads at once (for<br>
>>>>> example when re-indexing on 12-ht-core machines)<br>
>>>>> - being able to replay compilations by injecting a virtual file system<br>
>>>>> that exactly “copies” the original file system’s content, which allows<br>
>>>>> easy scaling of replays, running tools against dirty edit buffers on a<br>
>>>>> lower level than the SourceManager and unit testing<br>
>>>><br>
>>>> … and making sure that all of the various stages of compilation see the same view of the file system.<br>
>>>><br>
>>>>> Con:<br>
>>>>> - there would be yet another try at unifying the APIs which would be<br>
>>>>> in an intermediate state while being worked on (and PathV1 vs PathV2<br>
>>>>> is already bad enough)<br>
>>>><br>
>>>> I'm fine with intermediate states so long as the direction and benefits are clear. The former we can certainly discuss, and the latter is obvious already.<br>
>>>><br>
>>>>> - making it the canonical file system interface is a lot of effort<br>
>>>>> that requires touching a lot of systems (while we’re volunteering to<br>
>>>>> do the work, it will probably eat up other people’s time, too)<br>
>>>><br>
>>>> I doubt I'll have much time to directly hack on this, but I'll be happy to review / discuss / help with adoption. libclang is one of the huge beneficiaries of such a change, so I care a lot about getting that to work well.<br>
>>>><br>
>>>>> What parts (if any) of this type of transition makes sense?<br>
>>>>> 1. Figure out the “correct” interface we’d want for FileManager to be<br>
>>>>> more generally useful<br>
>>>>> 2. Change FileManager to that interface<br>
>>>>> 4. Sink FileManager into llvm, so it can be used by other projects<br>
>>>>> 4. Use it throughout clang<br>
>>>>> 5. Use it throughout llvm<br>
>>>>> We don’t need to do all of them at once, and should be able to<br>
>>>>> evaluate the results along the way.<br>
>>>><br>
>>>> I share some of Daniel's concern about re-using FileManager, because the interface is very narrowly designed for Clang's usage and some of the functionality intended for the VFS is split out into SourceManager. My advice would be to start building a new VFS down in LLVM, and make FileManager an increasingly-shrinking interface on top of the new VFS. At some point, FileManager will be thin enough that its clients can just switch directly over to using the VFS, and FileManager can eventually go away.<br>
>>>><br>
>>>> I do realize that this could end up like PathV1 vs. PathV2, where both exist for a while, but the benefits of the VFS should outweigh our collective laziness.<br>
>>><br>
>>> So, as I noted in my replay to Daniel, after working through<br>
>>> llvm/Support (and bringing FileManager back to my mind) I think I'm<br>
>>> actually seeing a way forward, tell me if I'm crazy:<br>
>>> 1. morph FileSystem (I don't know whether that would include PathV2,<br>
>>> but I currently don't think so) into a class that exports a nice<br>
>>> interface for all FileSystem functions that we can override; to be<br>
>>> able to do that step-by-step, we could for example introduce a static<br>
>>> FileSystem pointer that is initialized with the default system file<br>
>>> system on startup (I like being able to do baby-steps)<br>
>>> 2. add methods to FileSystem to support opening MemoryBuffers; the<br>
>>> path forward will be to move all calls to MemofyBuffer::get*File<br>
>>> through the FileSystem interface, but again that can be handled<br>
>>> incrementally<br>
>>> 3. at that point we'd have enough stuff in FileSystem to rebase<br>
>>> FileManager on top of it; once 1 and 2 are finished for clang/.* we'll<br>
>>> be able to completely move the virtual file support over into a nice<br>
>>> OverlayFileSystem implementation (argh, I've coded too many of those<br>
>>> in my life);<br>
>>> 4. add methods to FileSystem to support opening raw_fd_ostreams; this<br>
>>> is basically the process for reading mirrored<br>
>>><br>
>>> Thoughts? Completely broken approach? Broken order?<br>
>>><br>
>>> On a different note, switching to the SourceManager topic - I know<br>
>>> enough about SourceManager to be dangerous but not enough to ever<br>
>>> claim I would have understood the crazy buffer management that's going<br>
>>> on in ContentCache :) So I'd need a lot of help to pry that box open<br>
>>> eventually. Currently I'd think that this can be done in a subsequent<br>
>>> step after the file system is sorted out, but I might be wrong...<br>
>>><br>
>>> Cheers,<br>
>>> /Manuel<br>
>><br>
>> Just for some background about why we have PathV2.<br>
>><br>
>> In my quest to improve Windows support across LLVM and Clang I ran<br>
>> into many issues with the way PathV1 worked. A few were:<br>
>> * PathV1, and most of LLVM, use std::string to handle errors. This<br>
>> makes code more verbose than needed, and loses os level error<br>
>> information.<br>
>> * PathV1 makes it difficult to handle Unicode on Windows. Although<br>
>> apparently I didn't solve the problem correctly either :P.<br>
><br>
> Are there open bugs? A quick search for unicode on <a href="http://llvm.org/bugs" target="_blank">llvm.org/bugs</a><br>
> didn't show anything windows specific.<br>
><br>
>> * PathV1 requires constructing a Path object before calling any<br>
>> functions. This is inefficient when most of the time you have<br>
>> something StringRef'able.<br>
>><br>
>> Thus when I designed PathV2 I made it stateless, utf-8 only, and used<br>
>> error_code.<br>
>><br>
>> The reason I bring this up is because I support a VFS, however, I want<br>
>> to make sure that we keep in mind the reasons PathV2 was created while<br>
>> writing it.<br>
><br>
> Yep, that's an important point. As I said, I've looked into PathV2 and<br>
> I really like the distinction between path manipulation and file<br>
> system access, and the general design of both PathV2 and<br>
> Support/FileSystem.<br>
><br>
>> PathV1 -> PathV2 transition stopped because I ran out of time to do<br>
>> it. There's so much code that uses it, and some of the changes are non<br>
>> trivial in the cases where the Path class is stored and accessed many<br>
>> places instead of just used to access the path functions.<br>
>><br>
>> The approach and order seems good to me. The llvm::sys::path parts can<br>
>> stay separate, only the llvm::sys::fs parts need to be virtualized.<br>
><br>
> Yep, that was exactly my thought. Thanks for confirming and providing<br>
> all the background information! :)<br>
<br>
</div></div>Not sure if I follow here, but we will need to do some amount of work<br>
on sys::path (not virtualization per se).<br>
<br>
The current PathV2 API has embedded into it an assumption of working<br>
with the native path type.<br>
<br>
In the system I was originally imagining, we would have something like:<br>
(1) sys::path::unix and sys::path::windows. So client code can use a<br>
windows specific version if it wanted to for some reason. These would<br>
have the same functions in them.<br></blockquote><div><br></div><div>Worst. Idea. Ever. Sorry to be blunt, but how does that help higher-level code at all? The underlying implementation (type) of the path objects could be different, but the API itself should really be platform-independent. No use for a Windows path in a Unix app, and if so, it's not LLVM's place to provide that unneeded functionality.</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
(2) sys::path, which would just be the same as one of the two<br>
previous namespaces, selected to match the host.<br></blockquote><div><br></div><div>This is better. LLVM/Clang shouldn't know what a sys::path is (UTF8 Unix path or UTF16 Windows path), they just need a "path".</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
(3) some other path variants, which would take a FileSystem object,<br>
and then call the appropriate path functions for the FileSystem type.<br>
<br>
Eventually, any code which we want to be virtualizable would need to<br>
move to not using the sys::path functions that don't take a FileSystem<br>
object.<br></blockquote><div><br></div><div>You guys probably know more than I do about LLVM/Clang's needs wrt a file system cache, but apart from that, why not model according to the Boost implementation? Futureproof and *proven useful*.</div>
<div><br></div><div>Ruben</div></div>