Skip to content

Conversation

l0rinc
Copy link
Contributor

@l0rinc l0rinc commented Jun 25, 2025

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 with AfterClass, but was reverted by reviewer demand.

@DrahtBot
Copy link
Contributor

DrahtBot commented Jun 25, 2025

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage & Benchmarks

For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/32813.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK hodlinator, maflcko

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Copy link
Member

@maflcko maflcko left a 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

@DrahtBot
Copy link
Contributor

🚧 At least one of the CI tasks failed.
Task lint: https://github.com/bitcoin/bitcoin/runs/44780552247
LLM reason (✨ experimental): The CI failure is caused by errors in the lint check, related to code style or formatting issues.

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

Leave a comment here, if you need help tracking down a confusing failure.

@l0rinc l0rinc force-pushed the l0rinc/clang-format branch 2 times, most recently from c3ef744 to 5a48369 Compare June 25, 2025 22:03
@l0rinc l0rinc force-pushed the l0rinc/clang-format branch from 5a48369 to 94364a7 Compare June 27, 2025 09:33
@l0rinc l0rinc marked this pull request as ready for review June 29, 2025 08:11
@l0rinc l0rinc changed the title clang-format: modernize and realign clang-format configuration clang-format: align brace-after-struct and *-class formatting Jun 29, 2025
Copy link
Member

@maflcko maflcko left a 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==

l0rinc added a commit to l0rinc/bitcoin that referenced this pull request Jul 10, 2025
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
l0rinc added a commit to l0rinc/bitcoin that referenced this pull request Jul 10, 2025
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
l0rinc added a commit to l0rinc/bitcoin that referenced this pull request Jul 10, 2025
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
@maflcko maflcko requested a review from hebasto July 11, 2025 09:12
Comment on lines +100 to +115
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: ''
Copy link
Member

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.

Copy link
Contributor

@hodlinator hodlinator left a 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.

@DrahtBot DrahtBot requested a review from hodlinator August 27, 2025 19:47
@l0rinc l0rinc changed the title clang-format: align brace-after-struct and *-class formatting clang-format: make formatting deterministic for different formatter versions Sep 1, 2025
@l0rinc l0rinc force-pushed the l0rinc/clang-format branch from 94364a7 to 55aba02 Compare September 1, 2025 21:17
@l0rinc
Copy link
Contributor Author

l0rinc commented Sep 1, 2025

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>
@l0rinc l0rinc force-pushed the l0rinc/clang-format branch from 55aba02 to 13f36c0 Compare September 1, 2025 22:10
Copy link
Contributor

@hodlinator hodlinator left a 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
Copy link
Contributor

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)).

Copy link
Member

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)

@DrahtBot DrahtBot requested a review from maflcko September 2, 2025 08:17
@maflcko
Copy link
Member

maflcko commented Sep 2, 2025

re-ACK 13f36c0 🖼

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: re-ACK 13f36c020f0329b5e975282b45292fdf2a495e31 🖼
gVHv+GHN3tcL9TjuYLc/42PdtTtoJTNhIIFWKWk6RVQ/h7A3PizxMW48bbhzO4bbFkEQlpnI+nyNIkwIbsKHCg==

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.

4 participants