add vfs support for ExpandResponseFiles.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Build result: pass - 60330 tests passed, 0 failed and 732 were skipped.
Log files: console-log.txt, CMakeCache.txt
Are there any instances where we DON'T want to get the real file system? If not, could the *llvm::vfs::getRealFileSystem() call be put inside cl::ExpandResponseFiles?
llvm/include/llvm/Support/CommandLine.h | ||
---|---|---|
32 | Can llvm::vfs::FileSystem be forward declared and this moved into the .cpp? |
Okay, that makes sense. Perhaps we should introduce a new overload of ExpandResponseFiles that allows specifying a different file system then, and having the current version call into that one, specifying the getRealFileSystem call? I'm not overly keen on having yet another apparently boiler-plate piece of functionality required in every single call of ExpandResponseFiles.
It's not just unit-tests, in D70222 we will ultimately use FSes other than getRealFilesystem() in clangd.
Having non-VFS-clean versions of functions around that silently use the real FS is a bit of a scourge for users that need to be VFS-clean, honestly. Parsing argv is exactly the sort of place where FS access isn't obvious and exposing a function that doesn't accept a VFS encourages callers to miss this aspect. At the same time this is mostly called from a bunch of drivers that (presumably) don't need VFS support. Maybe allowing nullptr = real FS, or a default argument, would be an OK compromise?
I see, thank you.
Having non-VFS-clean versions of functions around that silently use the real FS is a bit of a scourge for users that need to be VFS-clean, honestly. Parsing argv is exactly the sort of place where FS access isn't obvious and exposing a function that doesn't accept a VFS encourages callers to miss this aspect. At the same time this is mostly called from a bunch of drivers that (presumably) don't need VFS support. Maybe allowing nullptr = real FS, or a default argument, would be an OK compromise?
A default argument would be my preference there. It looks like we have some already.
llvm/include/llvm/Support/CommandLine.h | ||
---|---|---|
1963 | Does VFS make sense here, given that it could be a real filesystem? |
Build result: fail - 60341 tests passed, 3 failed and 732 were skipped.
failed: Clang.CodeGen/catch-implicit-integer-sign-changes-incdec.c failed: Clang.CodeGen/catch-implicit-signed-integer-truncations-incdec.c failed: libc++.std/thread/futures/futures_async/async.pass.cpp
Log files: console-log.txt, CMakeCache.txt
Aside from one nit, this looks okay to me. I'd like someone else to look at it though too. I'm not at all familiar with the file system stuff to be confident to say everything there is good.
llvm/lib/Support/CommandLine.cpp | ||
---|---|---|
1148 | Has this been clang-formatted? |
llvm/include/llvm/Support/CommandLine.h | ||
---|---|---|
47 | now that we are also pulling the the function, I think it is OK to include the header instead. | |
llvm/lib/Support/CommandLine.cpp | ||
1076 | you can move this to the beginning of the function, to exit immediately, without checking for anything else. | |
1077 | it is sad that, ExpandResponseFile returns a bool, but that's a battle for another day. unfortunately, it is not enough return false in this case you need to consume the error with llvm::consumeError before exiting the scope. | |
1145–1151 | there are FileSystem::status and Status::equivalent functions to implement llvm::sys::fs:equivalent behaviour |
llvm/include/llvm/Support/CommandLine.h | ||
---|---|---|
47 | Yes, we need to include VirtualFileSystem.h, IntrusiveRefCntPtr needs to know the complete definition of FileSystem. |
Build result: pass - 60338 tests passed, 0 failed and 732 were skipped.
Log files: console-log.txt, CMakeCache.txt
llvm/lib/Support/CommandLine.cpp | ||
---|---|---|
1053 | this comment has moved into a irrelevant line and wasn't addressed, so re-stating it here: it is sad that, ExpandResponseFile returns a bool, but that's a battle for another day. unfortunately, it is not enough return false in this case you need to consume the error with llvm::consumeError before exiting the scope. | |
1148 | again you need to consumeErrors before returning. I would first get LHS, consume and bail out if it was an error, then do the same for RHS and only after that return equivalent. |
llvm/lib/Support/CommandLine.cpp | ||
---|---|---|
1061 | I'd ultimately like to see the public interface return llvm::Expected/llvm::Error so that a potentially useful error with information isn't just thrown away. However, I agree that that's probably a separate change. On the other hand, it should be simple to return it here, since this is only used locally, for consumption in ExpandResponseFiles below. Could you make that change, please? | |
1148 | Could you add a TODO comment here and at the other consumeError() call to say that the error should be propagated up the stack, please? |
llvm/lib/Support/CommandLine.cpp | ||
---|---|---|
1068 | std::make_error_code(std::errc::illegal_byte_sequence) -> errc::illegal_byte_sequence |
llvm/lib/Support/CommandLine.cpp | ||
---|---|---|
1068 | LLVM has its own errc error_code set. Please use that, i.e. delete the std:: (note that I didn't add std:: in my previous comment). |
llvm/lib/Support/CommandLine.cpp | ||
---|---|---|
1068 | I think we should use std::errc::illegal_byte_sequence, because it's sigature is: template <typename... Ts> inline Error createStringError(std::errc EC, char const *Fmt, const Ts &... Vals) |
llvm/lib/Support/CommandLine.cpp | ||
---|---|---|
1068 | I'm not sure if that's a mistake in the function interface or not, and it looks like our usage is very inconsistent, but the comments in Errc.h imply that we really should use llvm::errc values and not std::errc, or there may be problems. |
llvm/lib/Support/CommandLine.cpp | ||
---|---|---|
1068 | I think llvm::errc and std::errc are both correct, llvm::errc eventually implicitly converts to std::error_code. |
@jhenderson I am planning to commit this if the discussion around std::errc vs llvm::errc is resolved, I don't have any preference towards one or the other both seems to get the work done.
I'm not going to block this being committed. I do think llvm::errc exists for a reason, and those reasons are documented in the associated file, giving me the impression we should use it and not std::errc. However, I don't know how applicable those reasons really are nowadays - I'm certainly no authority on them.
Can llvm::vfs::FileSystem be forward declared and this moved into the .cpp?