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

ci: add clang-format to pre-commit configuration #2902

Closed
wants to merge 8 commits into from

Conversation

lobis
Copy link
Contributor

@lobis lobis commented Dec 14, 2023

No description provided.

@lobis lobis mentioned this pull request Dec 14, 2023
@lobis
Copy link
Contributor Author

lobis commented Dec 14, 2023

Wow the pre-commit bot did a really big diff, is the clang-format being ran correctly and it wasn't formatted before or what is going on? I'm having troubles running this .clang-format file myself so can't really tell.

@lobis lobis force-pushed the pre-commit-clang-format branch from 673ee43 to 604d252 Compare December 20, 2023 13:40
@lobis lobis marked this pull request as ready for review December 20, 2023 13:58
@lobis
Copy link
Contributor Author

lobis commented Dec 20, 2023

Not sure why this is such a big diff @agoose77 , perhaps you want to make some changes?

@agoose77
Copy link
Collaborator

This was something that @ianna and @jpivarski were discussing a while ago. I don't recall if we ever reached a conclusion on the style and went as far as enforcing it. Perhaps they can chime in?

Comment on lines -59 to +68
const int8_t kMaxInt8 = 127; // 2**7 - 1
const uint8_t kMaxUInt8 = 255; // 2**8 - 1
const int32_t kMaxInt32 = 2147483647; // 2**31 - 1
const uint32_t kMaxUInt32 = 4294967295; // 2**32 - 1
const int64_t kMaxInt64 = 9223372036854775806; // 2**63 - 2: see below
const int64_t kSliceNone = kMaxInt64 + 1; // for Slice::none()
const int64_t kMaxLevels = 48;
const int8_t kMaxInt8 = 127; // 2**7 - 1
const uint8_t kMaxUInt8 = 255; // 2**8 - 1
const int32_t kMaxInt32 = 2147483647; // 2**31 - 1
const uint32_t kMaxUInt32 = 4294967295; // 2**32 - 1
const int64_t kMaxInt64 = 9223372036854775806; // 2**63 - 2: see below
const int64_t kSliceNone = kMaxInt64 + 1; // for Slice::none()
const int64_t kMaxLevels = 48;
Copy link
Member

Choose a reason for hiding this comment

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

I liked the right-formatting of these numbers, but it's impressive that it exactly maintained the alignment of the comments (which is more important, anyway).

Comment on lines -8 to +16
ERROR awkward_BitMaskedArray_to_IndexedOptionArray(
T* toindex,
const uint8_t* frombitmask,
int64_t bitmasklength,
bool validwhen,
bool lsb_order) {
ERROR
awkward_BitMaskedArray_to_IndexedOptionArray(T* toindex,
const uint8_t* frombitmask,
int64_t bitmasklength,
bool validwhen,
bool lsb_order) {
Copy link
Member

Choose a reason for hiding this comment

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

This kind of indentation is bad for limited horizontal space. Also, there's a reason black chose to put all of the arguments on a different line from the function name: with this formatting, changing the length of the name would change the indentation of all of the arguments, which is a bigger, more noisy change.

If it's possible to ask for black-style indentation here, that would be an improvement.

Comment on lines 20 to +23
if ((byte & ((uint8_t)1)) == validwhen) {
toindex[i*8 + 0] = i*8 + 0;
}
else {
toindex[i*8 + 0] = -1;
toindex[i * 8 + 0] = i * 8 + 0;
} else {
toindex[i * 8 + 0] = -1;
Copy link
Member

Choose a reason for hiding this comment

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

I disagree with } else {, but not strongly.

Comment on lines -3 to +7
#define FILENAME(line) FILENAME_FOR_EXCEPTIONS_C("src/cpu-kernels/awkward_ByteMaskedArray_getitem_nextcarry_outindex.cpp", line)
#define FILENAME(line) \
FILENAME_FOR_EXCEPTIONS_C( \
"src/cpu-kernels/" \
"awkward_ByteMaskedArray_getitem_nextcarry_outindex.cpp", \
line)
Copy link
Member

@jpivarski jpivarski Dec 21, 2023

Choose a reason for hiding this comment

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

These lines were easier to edit and check in bulk when they were one-liners, but it could be hard to explain to the formatter that only macros are allowed to violate the line width rule.

Before this PR, awkward-cpp/src/cpu-kernels/awkward_ListOffsetArray_reduce_nonlocal_outstartsstops_64.cpp already had a multi-line implementation. That was the only file, so the pattern was already broken (automated scans that assumed that it's one line would have failed to catch that kernel).

So I guess this is fine. At least it's enforced.

@jpivarski
Copy link
Member

@ianna and I had discussed it in #1842, #1865, #34, and #35.

This does have a lot of diffs, mostly in whitespace. We can merge a PR like this, but only once, after conclusively deciding on a set of style options.

Clang-format/clang-tidy doesn't come with a set of opinions, the way that black does, but there must be some de facto standards, like LLVM Style. Which is the most popular one?

@jpivarski
Copy link
Member

The issue, #1842, is still open, and we should try again someday. This (closed) PR will be helpful for whoever tries to do it in the future.

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.

3 participants