-
Notifications
You must be signed in to change notification settings - Fork 37.7k
clang-format: make formatting deterministic for different formatter versions #32813
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
base: master
Are you sure you want to change the base?
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code Coverage & BenchmarksFor details see: https://corecheck.dev/bitcoin/bitcoin/pulls/32813. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
last commit seems fine, but the others i am not sure. at a minimum you'll have to drop the scripted diffs from executing, because they can't be reproduced anyway with different clang-format versions
🚧 At least one of the CI tasks failed. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |
c3ef744
to
5a48369
Compare
5a48369
to
94364a7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't checked if this fixes the issues with your IDE, but I guess it makes sense either way to get the clang-format config up to date. clang-16 is the minimum required for about a year now, so every developer should have access to clang-format-16 in some way or another.
I've recreated the commits on Ubuntu and reviewed the diff:
review ACK 94364a7 🥙
Show signature
Signature:
untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
trusted comment: review ACK 94364a7d5403d9d480ebc065f8709c6dd21e543f 🥙
xsnBRKa1+85+2JOjTRQ1kZgSlBHhVZxj7LlQpMQNkd5vPsoJ/6a84fiaWp9pAnna9VGz0/DA4J3jNoByA1TuCg==
Feeds the file name string directly into the hasher instead of pre-hashing it first. The resuoting hash changes of course, but that doesn't affect us since it's only stored in-memory. Fixes: bitcoin#32604 (comment) A few other related nits were also addressed here: * Comment was redundant, `CSipHasher` is used in other hashers all over the codebase * `static_cast<size_t>` skewed the whole line, changed to shorter functional-style cast * struct formatting is aligned with class formatting - see bitcoin#32813
Feeds the file name string directly into the hasher instead of pre-hashing it first. The resulting hash changes of course, but that doesn't affect us since it's only stored in-memory. Fixes: bitcoin#32604 (comment) A few other related nits were also addressed here: * Comment was redundant, `CSipHasher` is used in other hashers all over the codebase * `static_cast<size_t>` skewed the whole line, changed to shorter functional-style cast * struct formatting is aligned with class formatting - see bitcoin#32813
Feeds the file name string directly into the hasher instead of pre-hashing it first. The resulting hash changes of course, but that doesn't affect us since it's only stored in-memory. Fixes: bitcoin#32604 (comment) A few other related nits were also addressed here: * Comment was redundant, `CSipHasher` is used in other hashers all over the codebase * `static_cast<size_t>` skewed the whole method, changed to shorter functional-style cast * struct formatting is aligned with class formatting - see bitcoin#32813
IncludeBlocks: Preserve | ||
IncludeCategories: | ||
- Regex: '^"(llvm|llvm-c|clang|clang-c)/' | ||
Priority: 2 | ||
SortPriority: 0 | ||
CaseSensitive: false | ||
- Regex: '^(<|"(gtest|gmock|isl|json)/)' | ||
Priority: 3 | ||
SortPriority: 0 | ||
CaseSensitive: false | ||
- Regex: '.*' | ||
Priority: 1 | ||
SortPriority: 0 | ||
CaseSensitive: false | ||
IncludeIsMainRegex: '(Test)?$' | ||
IncludeIsMainSourceRegex: '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unrelated note: I understand the setting IncludeBlocks
is set to Preserve
(and it should probably stay this way by default, but it would be nice to update the other Include* settings (in another pull request) to properly sort the includes: (1) the main include, (2) everything else (Bitcoin Core includes) (3) third-party library includes (boost, Qt), (4) stdlib includes (those that do not end in .h
). This way, one could toggle the IncludeBlocks
to get the desired behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 7c9b3e1 (first commit)
Ran clang-format -dump-config -style=file:src/.clang-format > foo
on that commit and diffed foo against src/.clang-format. Only differences where added/elaborated settings from me running Clang-format 19. Makes sense to keep the format at the minimum version we support.
94364a7
to
55aba02
Compare
Kept the formatter config only without the class/struct brace unification, it's ready for re-review, thanks for the comments. |
Regenerated `.clang-format` from current configs to replace deprecated keys with up-to-date equivalents. Also added all current formatter default values to guard against version differences. The configs were updated with the following command (using v16 for maximal compatibility): $(brew --prefix llvm@16)/bin/clang-format -dump-config -style=file:src/.clang-format The new config was tested with: $(brew --prefix llvm@16)/bin/clang-format -i src/deploymentinfo.h Co-authored-by: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Co-authored-by: Hodlinator <172445034+hodlinator@users.noreply.github.com>
55aba02
to
13f36c0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re-ACK 13f36c0
struct
brace style was made to explicitly differ from class
in developer-notes.md after some back & forth (#32813 (comment)).
PPIndentWidth: -1 | ||
QualifierAlignment: Leave | ||
ReferenceAlignment: Pointer | ||
ReflowComments: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
https://clang.llvm.org/docs/ClangFormatStyleOptions.html#reflowcomments
We might want to set IndentOnly
, so we don't unnecessarily touch lines. But probably better to follow up on this in another PR, similar to initializer lists (#32740 (comment)).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similar to initializer lists (#32740 (comment)).
When formatting initializer lists, one can manually put the :
on the next line. This should give a stable clang-format output. (With the current line limit, clang-format won't split or merge lines by itself)
re-ACK 13f36c0 🖼 Show signatureSignature:
|
Updates
.clang-format
file to reflect latest supported Clang-Format standards while preserving most of the existing formatting behavior.Note that
AfterStruct
brace placement was originally aligned here withAfterClass
, but was reverted by reviewer demand.