This is an archive of the discontinued LLVM Phabricator instance.

Support: Make Wait's SecondsToWait be Optional [NFC]
ClosedPublic

Authored by arsenm on Nov 29 2022, 12:38 PM.

Details

Summary

I found the interaction between SecondsToWait and
WaitUntilChildTerminates confusing. Rather than have a boolean to
ignore the value of SecondsToWait, combine these into one Optional
parameter

No idea if the Windows part builds

Diff Detail

Event Timeline

arsenm created this revision.Nov 29 2022, 12:38 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 29 2022, 12:38 PM
arsenm requested review of this revision.Nov 29 2022, 12:38 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 29 2022, 12:38 PM
Herald added a subscriber: wdng. · View Herald Transcript
aganea added inline comments.Nov 30 2022, 3:23 PM
llvm/include/llvm/Support/Program.h
210

I think the idea is to switch to using std::optional. You can do it now, or someone will do it later.

llvm/unittests/Support/ProgramTest.cpp
282–283

/*SecondsToWait*/ like above?

428

Perhaps /*SecondsToWait*/ here too?

sepavloff added inline comments.Nov 30 2022, 10:04 PM
llvm/lib/Support/Windows/Program.inc
423

You should put here *SecondsToWait > 0.

sepavloff added inline comments.Nov 30 2022, 10:55 PM
llvm/lib/Support/Windows/Program.inc
416

if here is excessive.

arsenm updated this revision to Diff 479436.Dec 1 2022, 2:39 PM
arsenm marked 4 inline comments as done.

Rebase on move to std::optional, address comments

aganea added inline comments.Dec 1 2022, 3:40 PM
llvm/lib/Support/Program.cpp
35

SecondsToWait here is not completely symmetric with Wait() (value 0 here has the meaning of std::nullopt in Wait), but maybe it's ok. Do you think it's worth changing this to std::optional as well?

llvm/lib/Support/Unix/Program.inc
408

nit: I would add braces here, after else, please see: https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements
"Use braces for the if block to keep it uniform with the else block." (and vice-versa)

alexfh added inline comments.Dec 1 2022, 4:46 PM
llvm/unittests/Support/ProgramTest.cpp
428

Or rather /*SecondsToWait=*/, since this format is more common and supported by clang-tidy (https://clang.llvm.org/extra/clang-tidy/checks/bugprone/argument-comment.html). Same for other argument comments.

arsenm updated this revision to Diff 479653.Dec 2 2022, 8:55 AM
arsenm marked 2 inline comments as done.

Rename test and address comments

llvm/lib/Support/Program.cpp
35

That would expose both the std::nullopt and SecondsToWait == 0 possibilities, which I'm not sure makes any sense here. If you pass a 0, you're expecting to launch a process and have it immediately complete?

aganea accepted this revision.Dec 2 2022, 1:32 PM

LGTM.

llvm/lib/Support/Program.cpp
35

The annoying thing is that 0 here means the exact opposite as in Wait().
ExecuteAndWait -> 0 means wait forever.
Wait() -> 0 means don't wait at all.

In that sense, yes if we had std::option here and passed 0, that would be (almost) like calling ExecuteNoWait().

Right now we have 6 calling site for ExecuteNoWait() across the monorepo, and 47 for ExecuteAndWait(). Maybe we should merge them into one Execute(). But let's go ahead with your change and we'll do that as a second step? WDYT?

llvm/unittests/Support/ProgramTest.cpp
245

/*Redirects=*/ and /*MemoryLimit=*/

283

/*MemoryLimit=*/

This revision is now accepted and ready to land.Dec 2 2022, 1:32 PM
alexfh accepted this revision.Dec 3 2022, 2:28 PM

LGTM modulo open comments.

llvm/unittests/Support/ProgramTest.cpp
428

nit: No space between /*SecondsToWait=*/ and 5. Or better clang-format all changed lines (e.g. using clang-format-diff - see https://clang.llvm.org/docs/ClangFormat.html#script-for-patch-reformatting).

arsenm closed this revision.Dec 14 2022, 6:56 AM
arsenm marked an inline comment as done.
llvm/lib/Support/Program.cpp
35

They could be merged, though it removes the "simple" option