Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update clang-format and format some files as test #4694

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

trws
Copy link
Member

@trws trws commented Oct 17, 2022

Update clang-format using some options from versions up to 11, and format some files with version 12 so we can see what they look like. This is not really meant to be merged, but to pick a few large-ish files with various code patterns so we can figure out if this is what we want.

The only thing that really stood out to me in here is the ok () and similar functions/macros seem like they are almost always formatted in a non-standard way. Should those go in with the pack/unpack functions so they're left alone?

@trws trws requested a review from chu11 October 17, 2022 23:09
Comment on lines 155 to 158
if (flux_respond_pack (rex->s->h, rex->msg, "{s:s s:i}",
"type", "complete",
"rank", rex->s->rank) < 0)
"rank", rex->s->rank)
< 0)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking back at this now, I'm wondering what was left to adjust to make this good enough. The thing I remember trying to work around is the break before trailing < 0 in if statements, which is why this is a comment on these lines as an example. Oddly though, looking back at it I kinda don't hate it. It makes it visually obvious what's being compared here, it can be avoided by wrapping in parentheses, and if we're happy with the rest I'm not sure it's worth blocking on. @garlick, @grondo, @chu11, thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really don't like the break before < 0 which is why I suppose we don't do it in our existing formatting.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Odd as it seems, we might also be able to address it with a bit of scripting. It's a very specific spot, and a vim script of %g/^\s+\(\!=|==|<|>\) \d.{0,5}$/normal kJ seems to fix it 100% of the time. The only downside is that it would mean in a few cases (less than a dozen total I think) we'll end up with lines up to 5 chars longer than the limit set in the clang-format file. I'm going to throw that into a wrapper script, maybe convert it to sed, and throw up the update.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated versions of the test files pushed, I made a small mistake so there's a blank line at the beginning of the files, but the trailing comparison operator is taken care of. Need to figure out how to make it reasonably nice to use this, awk makes the process a bit slow, but does that otherwise take care of it?

@codecov
Copy link

codecov bot commented Jul 27, 2023

Codecov Report

Merging #4694 (508cab8) into master (d6a7251) will increase coverage by 0.00%.
Report is 1807 commits behind head on master.
The diff coverage is 83.96%.

❗ Current head 508cab8 differs from pull request most recent head ff36834. Consider uploading reports for the commit ff36834 to get more accurate results

@@           Coverage Diff           @@
##           master    #4694   +/-   ##
=======================================
  Coverage   83.38%   83.38%           
=======================================
  Files         413      413           
  Lines       69430    69408   -22     
=======================================
- Hits        57892    57877   -15     
+ Misses      11538    11531    -7     
Files Changed Coverage Δ
src/common/libsubprocess/server.c 60.27% <65.21%> (-0.28%) ⬇️
src/modules/kvs/kvs.c 70.32% <76.76%> (-0.15%) ⬇️
src/broker/broker.c 78.41% <95.31%> (-0.16%) ⬇️
src/common/libkvs/treeobj.c 85.13% <100.00%> (-0.36%) ⬇️

... and 5 files with indirect coverage changes

@trws
Copy link
Member Author

trws commented Jul 27, 2023

Huh, one other option I didn't know existed (not sure it did last I checked), but that makes things more consistent and actually works a lot like the black format for arguments would be to switch AlignAfterOpenBracket from Align to BlockIndent. That would mean that instead of aligning all function arguments to the indent of the open parentheses, they would all get the continuation indent, which looks like this:

 if ((port1 = get_port (triple->range)) < 0 || (port2 = get_port (triple->range)) < 0|| !(arr = json_pack ("[I, I]", port1, port2))
 ┆   || flux_jobtap_event_post_pack (
 ┆   ┆   ┆  triple->plugin,
 ┆   ┆   ┆  triple->jobid,
 ┆   ┆   ┆  "cray_port_distribution",
 ┆   ┆   ┆  "{s:O, s:I}",
 ┆   ┆   ┆  "ports",
 ┆   ┆   ┆  arr,
 ┆   ┆   ┆  "random_integer",
 ┆   ┆   ┆  random
 ┆   ┆  ) < 0|| flux_jobtap_job_aux_set (
 ┆   ┆   ┆  triple->plugin,
 ┆   ┆   ┆  triple->jobid,
 ┆   ┆   ┆  CRAY_PALS_AUX_NAME,
 ┆   ┆   ┆  arr,
 ┆   ┆   ┆  (flux_free_f)json_decref
 ┆   ┆  ) < 0) {
 ┆   if (arr)
 ┆   ┆   json_decref (arr);
 ┆   prolog_status = 1;
 ┆   flux_log_error (
 ┆   ┆   h,
 ┆   ┆   PLUGIN_NAME
 ┆   ┆   ": "
 ┆   ┆   "Failed to post ports to job"
 ┆   );
 ┆   goto cleanup;
 }

I'm oddly fond of this and interested in what everyone else thinks. Having gotten used to it with black (and how it avoids extra diff gak in argument lists, literals and so-forth) it works for me more than it once would have, and it naturally keeps the < 0 attached to the close-peren for some reason.

With the current value it looks like this (with the fixup script):

 if ((port1 = get_port (triple->range)) < 0 || (port2 = get_port (triple->range)) < 0|| !(arr = json_pack ("[I, I]", port1, port2))
 ┆   || flux_jobtap_event_post_pack (triple->plugin,
 ┆   ┆   ┆   ┆   ┆   ┆   ┆   ┆   ┆   triple->jobid,
 ┆   ┆   ┆   ┆   ┆   ┆   ┆   ┆   ┆   "cray_port_distribution",
 ┆   ┆   ┆   ┆   ┆   ┆   ┆   ┆   ┆   "{s:O, s:I}",
 ┆   ┆   ┆   ┆   ┆   ┆   ┆   ┆   ┆   "ports",
 ┆   ┆   ┆   ┆   ┆   ┆   ┆   ┆   ┆   arr,
 ┆   ┆   ┆   ┆   ┆   ┆   ┆   ┆   ┆   "random_integer",
 ┆   ┆   ┆   ┆   ┆   ┆   ┆   ┆   ┆   random) < 0|| flux_jobtap_job_aux_set (triple->plugin,
 ┆   ┆   ┆   ┆   ┆   ┆   ┆   ┆   triple->jobid,
 ┆   ┆   ┆   ┆   ┆   ┆   ┆   ┆   CRAY_PALS_AUX_NAME,
 ┆   ┆   ┆   ┆   ┆   ┆   ┆   ┆   arr,
 ┆   ┆   ┆   ┆   ┆   ┆   ┆   ┆   (flux_free_f)json_decref) < 0) {
 ┆   if (arr)
 ┆   ┆   json_decref (arr);
 ┆   prolog_status = 1;
 ┆   flux_log_error (h,
 ┆   ┆   ┆   ┆   ┆   PLUGIN_NAME
 ┆   ┆   ┆   ┆   ┆   ": "
 ┆   ┆   ┆   ┆   ┆   "Failed to post ports to job");
 ┆   goto cleanup;
 }

@trws trws self-assigned this Jan 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants