git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v3 00/15] run-command API: pass functions & opts via struct

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Oct 14, 2022, 14:50 UTC
Message-ID
<221014.86y1tijv3b.gmgdl@evledraar.gmail.com>
In-Reply-To
<06bc6ffe-3f64-481e-5c54-156a39865e25@dunelm.org.uk>
On Fri, Oct 14 2022, Phillip Wood wrote:
> Hi Ævar
Hi, thanks for taking a look again.
Show 11 quoted lines
> On 12/10/2022 22:02, Ævar Arnfjörð Bjarmason wrote:
>> For a general overview see the v2 CL:
>> https://lore.kernel.org/git/cover-v2-00.22-00000000000-20221012T084850Z-avarab@gmail.com/
>> Changes since v2:
>>   * Ejected various not-to-the-point of converting to the "opts
>> struct"
>>     per feedback about attempting to make this leaner.
>
> We're back to the same number of patches as v1 but you've removed
> three test cleanups and squashed three patches together which means
> there are five new patches in this version - what are they doing?

There's nothing *new* in this version, but per the range-diff of v2 some of the new ones in that version were kept here. I think that's what you're taling about.

Mainly it's the 'Only the "ungroup" was here in v1[...]' part of the v2 CL:

1. https://lore.kernel.org/git/cover-v2-00.22-00000000000-20221012T084850Z-avarab@gmail.com/
Show 12 quoted lines
>>   * I kept the size_t change & the online_cpus() fallback, and updated
>>     a commit message for the latter. For "int" v.s. "size_t" once we're
>>     not handling "-1" to mean "use the default" it makes sense to be
>>     unsigned, and if we're re-doing that at this point we'd need
>>     rewrites for "!processes" assumptions.
>
> I left some comments about this, I think the size_t change is taking
> us in the wrong direction as it is introducing a number of new
> implicit signed->unsigned conversions. I'm still not sure why you need
> the online_cups() changes c.f. 
> https://lore.kernel.org/git/8f95fbdb-b211-56af-8693-0e5a84afebac@gmail.com/
> which has never had a reply

Sorry about the non-reply there, between that & later discussion I tried to address that in the "Keeping this default behavior just for[...]" commit message update in this v3 (see range-diff).

But no, those changes are not strictly needed. But it's a trade-off I decided to take.

In the v1 (linked above) you pointed out that we could simply copy this field to the "struct pp" (a shorthand for "struct parallel_processes", I assume).

That's true, but for maintaining & understanding this API I think it's much easier to reason about it when all of our user options are "const", and we don't second guess any of those, and the "struct parallel_processes"

For the v1 I can see what that was easy to miss, as we still kept the copy of the number of processes in the "struct parallel_processes". In the v2 and this v3 we get to the point where we can remove that, and "ungroup", the copies of the callbacks etc.

So, leaving out the "provide a default" seemed worth it in the end, it's just 4 additional lines in the callers per the 05/15 (most of them had those already).

You also had a related concern in 04/05 (which I'm taking the liberty of replying ot here):

	https://lore.kernel.org/git/a7463bc5-9a92-8f0f-c0ee-e72fbbeedc09@dunelm.org.uk/

So, first I disagree with it "going in the wrong direction". We've been converting more things to size_t. For e.g. an "int nr_processes" we can expect that we'll want to e.g. have a corresponding "struct string_list" whose "nr" is a "size_t" (or similar aggregate types).

By mixing the two we're mixing types forever with associated warnings (& suppressions). We've been changing these sort of things to a "size_t" elsewhere, e.g. dd38e9e510c (trace2: use size_t alloc,nr_open_regions in tr2tls_thread_ctx, 2022-10-12) is one recent example..

But yes, we do incur warnings under DEVOPTS=extra-all now because things outside of the API are still "int" in some cases, just as we do with e.g. "struct string_list" and its users.

As to your:
	Before this patch we could have caught a negative value of n
	with an assertion. After this patch a negative value passed will
	become a large positive value (you have audited the current
	callers but that does not protect us from future mistakes).

I that's a good point. In this case I thought the likelihood that anyone would accidentally pass ".processes = -1" or whatever wasn't worth worrying about. If you think it's worth worrying about I think that concern would be easily addressed e.g. with:

	if (n == SIZE_MAX)
        	BUG("overflow?");
Or whatever.

A much likelier edge case IMO is that you'd have some pattern where you init a "processes" with "{ 0 }" or whatever, so it's zero, and then we'd interpret that zero as online_cpus(), which e.g. for the in-flight paralellizing of certain "git submodule" operations is probably too high a number.

Since we don't interpret !n or n < 1 as online_cpus() anymore we can BUG() out on it, which I think is an improvement. The 4 lines of additions to the relevant callers to call online_cpus() themselves are better than having those or a new caller potentially have this DWYMery from the low-level API.

>>   * Squashed the multi-step introduction of the "opts" struct, per
>>     Phillip's suggestion.
> That's most welcome, thanks
Glad you like it!
Previous: Phillip WoodNext: Junio C Hamano
Message 78 of 79 in “run-command API: pass functions & opts via struct”
  1. 00/15 run-command API: pass functions & opts via structÆvar Arnfjörð Bjarmason, Sep 30, 2022
  2. 01/15 hook tests: fix redirection logic error in 96e7225b310Ævar Arnfjörð Bjarmason, Sep 30, 2022
  3. 02/15 submodule tests: reset "trace.out" between "grep" invocationsÆvar Arnfjörð Bjarmason, Sep 30, 2022
  4. 03/15 run-command tests: test stdout of run_command_parallel()Ævar Arnfjörð Bjarmason, Sep 30, 2022
  5. 06/15 run-command API: have "run_processes_parallel{,_tr2}()" return voidÆvar Arnfjörð Bjarmason, Sep 30, 2022
  6. Phillip WoodOct 7, 2022
  7. 05/15 run-command tests: use "return", not "exit"Ævar Arnfjörð Bjarmason, Sep 30, 2022
  8. Phillip WoodOct 7, 2022
  9. 04/15 run-command test helper: use "else if" patternÆvar Arnfjörð Bjarmason, Sep 30, 2022
  10. 09/15 run-command.c: add an initializer for "struct parallel_processes"Ævar Arnfjörð Bjarmason, Sep 30, 2022
  11. 07/15 run-command API: make "jobs" parameter an "unsigned int"Ævar Arnfjörð Bjarmason, Sep 30, 2022
  12. Calvin WanOct 4, 2022
  13. Phillip WoodOct 7, 2022
  14. 13/15 run-command API: move *_tr2() users to "run_processes_parallel()"Ævar Arnfjörð Bjarmason, Sep 30, 2022
  15. 10/15 run-command API: add nascent "struct run_process_parallel_opts"Ævar Arnfjörð Bjarmason, Sep 30, 2022
  16. Phillip WoodOct 7, 2022
  17. 08/15 run-command API: don't fall back on online_cpus()Ævar Arnfjörð Bjarmason, Sep 30, 2022
  18. Phillip WoodOct 7, 2022
  19. 11/15 run-command API: make run_process_parallel{,_tr2}() thin wrappersÆvar Arnfjörð Bjarmason, Sep 30, 2022
  20. 14/15 run-command.c: don't copy *_fn to "struct parallel_processes"Ævar Arnfjörð Bjarmason, Sep 30, 2022
  21. 12/15 run-command API: have run_process_parallel() take an "opts" structÆvar Arnfjörð Bjarmason, Sep 30, 2022
  22. 15/15 run-command.c: don't copy "ungroup" to "struct parallel_processes"Ævar Arnfjörð Bjarmason, Sep 30, 2022
  23. Calvin WanOct 4, 2022
  24. Phillip WoodOct 7, 2022
  25. Junio C HamanoOct 7, 2022
  26. 00/22 run-command API: pass functions & opts via structÆvar Arnfjörð Bjarmason, Oct 12, 2022
  27. 01/22 hook tests: fix redirection logic error in 96e7225b310Ævar Arnfjörð Bjarmason, Oct 12, 2022
  28. 02/22 submodule tests: reset "trace.out" between "grep" invocationsÆvar Arnfjörð Bjarmason, Oct 12, 2022
  29. 04/22 run-command test helper: use "else if" patternÆvar Arnfjörð Bjarmason, Oct 12, 2022
  30. 03/22 run-command tests: test stdout of run_command_parallel()Ævar Arnfjörð Bjarmason, Oct 12, 2022
  31. 05/22 run-command API: have "run_processes_parallel{,_tr2}()" return voidÆvar Arnfjörð Bjarmason, Oct 12, 2022
  32. 06/22 run-command tests: use "return", not "exit"Ævar Arnfjörð Bjarmason, Oct 12, 2022
  33. 07/22 run-command.c: remove dead assignment in while-loopÆvar Arnfjörð Bjarmason, Oct 12, 2022
  34. 08/22 run-command.c: use C99 "for (TYPE VAR = ..." syntax where usefulÆvar Arnfjörð Bjarmason, Oct 12, 2022
  35. Phillip WoodOct 12, 2022
  36. Junio C HamanoOct 12, 2022
  37. 10/22 run-command API: don't fall back on online_cpus()Ævar Arnfjörð Bjarmason, Oct 12, 2022
  38. Phillip WoodOct 12, 2022
  39. 11/22 run-command.c: use designated init for pp_init(), add "const"Ævar Arnfjörð Bjarmason, Oct 12, 2022
  40. 09/22 run-command API: make "n" parameter a "size_t"Ævar Arnfjörð Bjarmason, Oct 12, 2022
  41. Phillip WoodOct 12, 2022
  42. 13/22 run-command API: make run_process_parallel{,_tr2}() thin wrappersÆvar Arnfjörð Bjarmason, Oct 12, 2022
  43. Phillip WoodOct 12, 2022
  44. 12/22 run-command API: add nascent "struct run_process_parallel_opts"Ævar Arnfjörð Bjarmason, Oct 12, 2022
  45. 14/22 run-command API: have run_process_parallel() take an "opts" structÆvar Arnfjörð Bjarmason, Oct 12, 2022
  46. 15/22 run-command API: move *_tr2() users to "run_processes_parallel()"Ævar Arnfjörð Bjarmason, Oct 12, 2022
  47. 16/22 run-command.c: make "struct parallel_processes" const if possibleÆvar Arnfjörð Bjarmason, Oct 12, 2022
  48. 17/22 run-command.c: don't copy *_fn to "struct parallel_processes"Ævar Arnfjörð Bjarmason, Oct 12, 2022
  49. 18/22 run-command.c: don't copy "ungroup" to "struct parallel_processes"Ævar Arnfjörð Bjarmason, Oct 12, 2022
  50. 19/22 run-command.c: don't copy "data" to "struct parallel_processes"Ævar Arnfjörð Bjarmason, Oct 12, 2022
  51. 21/22 run-command.c: pass "opts" further down, and use "opts->processes"Ævar Arnfjörð Bjarmason, Oct 12, 2022
  52. 20/22 run-command.c: use "opts->processes", not "pp->max_processes"Ævar Arnfjörð Bjarmason, Oct 12, 2022
  53. 22/22 run-command.c: remove "pp->max_processes", add "const" to signal() handlerÆvar Arnfjörð Bjarmason, Oct 12, 2022
  54. Ævar Arnfjörð BjarmasonOct 12, 2022
  55. Phillip WoodOct 12, 2022
  56. 00/15 run-command API: pass functions & opts via structÆvar Arnfjörð Bjarmason, Oct 12, 2022
  57. 01/15 run-command test helper: use "else if" patternÆvar Arnfjörð Bjarmason, Oct 12, 2022
  58. 02/15 run-command API: have "run_processes_parallel{,_tr2}()" return voidÆvar Arnfjörð Bjarmason, Oct 12, 2022
  59. 03/15 run-command tests: use "return", not "exit"Ævar Arnfjörð Bjarmason, Oct 12, 2022
  60. 04/15 run-command API: make "n" parameter a "size_t"Ævar Arnfjörð Bjarmason, Oct 12, 2022
  61. Phillip WoodOct 14, 2022
  62. 05/15 run-command API: don't fall back on online_cpus()Ævar Arnfjörð Bjarmason, Oct 12, 2022
  63. 06/15 run-command.c: use designated init for pp_init(), add "const"Ævar Arnfjörð Bjarmason, Oct 12, 2022
  64. 08/15 run-command API: move *_tr2() users to "run_processes_parallel()"Ævar Arnfjörð Bjarmason, Oct 12, 2022
  65. 07/15 run-command API: have run_process_parallel() take an "opts" structÆvar Arnfjörð Bjarmason, Oct 12, 2022
  66. Phillip WoodOct 14, 2022
  67. 09/15 run-command.c: make "struct parallel_processes" const if possibleÆvar Arnfjörð Bjarmason, Oct 12, 2022
  68. 13/15 run-command.c: use "opts->processes", not "pp->max_processes"Ævar Arnfjörð Bjarmason, Oct 12, 2022
  69. 11/15 run-command.c: don't copy "ungroup" to "struct parallel_processes"Ævar Arnfjörð Bjarmason, Oct 12, 2022
  70. 10/15 run-command.c: don't copy *_fn to "struct parallel_processes"Ævar Arnfjörð Bjarmason, Oct 12, 2022
  71. 14/15 run-command.c: pass "opts" further down, and use "opts->processes"Ævar Arnfjörð Bjarmason, Oct 12, 2022
  72. 15/15 run-command.c: remove "max_processes", add "const" to signal() handlerÆvar Arnfjörð Bjarmason, Oct 12, 2022
  73. Glen ChooOct 13, 2022
  74. 12/15 run-command.c: don't copy "data" to "struct parallel_processes"Ævar Arnfjörð Bjarmason, Oct 12, 2022
  75. Calvin WanOct 13, 2022
  76. Junio C HamanoOct 13, 2022
  77. Phillip WoodOct 14, 2022
  78. Ævar Arnfjörð BjarmasonOct 14, 2022
  79. Junio C HamanoOct 14, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.