This is an archive of the discontinued LLVM Phabricator instance.

[Support] add vfs support for ExpandResponseFiles
ClosedPublic

Authored by lh123 on Nov 27 2019, 12:32 AM.

Diff Detail

Event Timeline

lh123 created this revision.Nov 27 2019, 12:32 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald Transcript

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?

lh123 added a comment.Nov 27 2019, 1:44 AM

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?

This patch is part of D70222.
This is for using InMemoryFileSystem in unit tests.

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?

This patch is part of D70222.
This is for using InMemoryFileSystem in unit tests.

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.

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?

This patch is part of D70222.
This is for using InMemoryFileSystem in unit tests.

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?

It's not just unit-tests, in D70222 we will ultimately use FSes other than getRealFilesystem() in clangd.

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?

lh123 updated this revision to Diff 231213.Nov 27 2019, 4:26 AM

Address comments

lh123 marked an inline comment as done.Nov 27 2019, 4:27 AM
lh123 updated this revision to Diff 231215.Nov 27 2019, 4:37 AM

address comments and delete unused code.

lh123 marked an inline comment as done.Nov 27 2019, 4:37 AM
lh123 set the repository for this revision to rG LLVM Github Monorepo.Nov 27 2019, 4:48 AM

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

lh123 updated this revision to Diff 231234.Nov 27 2019, 5:40 AM

address comments.

Build result: FAILURE -
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
1152

Has this been clang-formatted?

kadircet added inline comments.Nov 27 2019, 5:56 AM
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
1080

you can move this to the beginning of the function, to exit immediately, without checking for anything else.

1081

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.

1149–1162

there are FileSystem::status and Status::equivalent functions to implement llvm::sys::fs:equivalent behaviour

lh123 updated this revision to Diff 231242.Nov 27 2019, 6:40 AM
lh123 marked an inline comment as done.

address comments.

lh123 marked 3 inline comments as done.Nov 27 2019, 6:41 AM
lh123 added inline comments.
llvm/include/llvm/Support/CommandLine.h
47

Yes, we need to include VirtualFileSystem.h, IntrusiveRefCntPtr needs to know the complete definition of FileSystem.

lh123 marked an inline comment as done.Nov 27 2019, 6:41 AM

Build result: pass - 60338 tests passed, 0 failed and 732 were skipped.

Log files: console-log.txt, CMakeCache.txt

kadircet added inline comments.Nov 27 2019, 9:30 AM
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.
1152

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.

lh123 updated this revision to Diff 231349.Nov 27 2019, 10:35 PM
lh123 marked 3 inline comments as done.

address comments.

lh123 updated this revision to Diff 231353.Nov 27 2019, 11:27 PM

address comments.

lh123 updated this revision to Diff 231359.Nov 28 2019, 12:20 AM

Build result: FAILURE -
Log files: console-log.txt, CMakeCache.txt

lh123 updated this revision to Diff 231361.Nov 28 2019, 12:54 AM

Sorry, upload the wrong patch.

jhenderson added inline comments.Nov 28 2019, 1:00 AM
llvm/lib/Support/CommandLine.cpp
1054

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?

1152

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?

lh123 updated this revision to Diff 231377.Nov 28 2019, 2:01 AM

address comments.

lh123 marked 2 inline comments as done.Nov 28 2019, 2:01 AM

Build result: FAILURE -
Log files: console-log.txt, CMakeCache.txt

lh123 updated this revision to Diff 231381.Nov 28 2019, 2:16 AM

address comments.

Build result: FAILURE -
Log files: console-log.txt, CMakeCache.txt

lh123 updated this revision to Diff 231384.Nov 28 2019, 2:24 AM

fixes no matching constructor for initialization of llvm::StringError.

kadircet accepted this revision.Nov 28 2019, 2:36 AM

LGTM, please make sure you've clang-formatted the changes though

llvm/lib/Support/CommandLine.cpp
1054

nit: no need for braces

1059

nit: no need for braces

1070

nit: you can make use of llvm::createStringError instead

1178

clang-format ?

This revision is now accepted and ready to land.Nov 28 2019, 2:36 AM
jhenderson added inline comments.Nov 28 2019, 2:37 AM
llvm/lib/Support/CommandLine.cpp
1071

Not sure, but you might want to use illegal_byte_sequence here instead of llvm::inconvertibleErrorCode().

1178

clang-format please

lh123 updated this revision to Diff 231390.Nov 28 2019, 2:46 AM
lh123 marked 6 inline comments as done.

address comments.

jhenderson added inline comments.Nov 28 2019, 2:56 AM
llvm/lib/Support/CommandLine.cpp
1071

std::make_error_code(std::errc::illegal_byte_sequence) -> errc::illegal_byte_sequence

lh123 updated this revision to Diff 231395.Nov 28 2019, 3:05 AM
lh123 marked an inline comment as done.

address comments.

jhenderson added inline comments.Nov 28 2019, 3:17 AM
llvm/lib/Support/CommandLine.cpp
1071

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).

lh123 marked an inline comment as done.Nov 28 2019, 4:09 AM
lh123 added inline comments.
llvm/lib/Support/CommandLine.cpp
1071

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)
jhenderson added inline comments.Nov 28 2019, 4:42 AM
llvm/lib/Support/CommandLine.cpp
1071

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.

lh123 marked 3 inline comments as done.Nov 29 2019, 1:49 AM
lh123 added inline comments.
llvm/lib/Support/CommandLine.cpp
1071

I think llvm::errc and std::errc are both correct, llvm::errc eventually implicitly converts to std::error_code.

lh123 updated this revision to Diff 231510.Nov 29 2019, 2:54 AM
lh123 marked an inline comment as done.

fix typo:
"Could not convert UTF16 To UTF8" -> "Could not convert UTF16 to UTF8"

@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.

@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.