-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
add clang-format #4790
add clang-format #4790
Conversation
I might add that there have been previous pull requests with the same aim. This one aims to do it properly now, including a Makefile target. The clang-format file is taken from my latest comment here, #3608. I think this is a step in the right direction, though I think we need to
|
I'm not a big fan of doing this on the Stockfish code, to me the formatter is still not smart enough to understand some intended formatting made by hand. |
Personally, I'd be in favor of automatic formatting, removes some of the human burden to maintain it, and guarantees consistency. Sure, it looks different, but very readable, IMO. |
I'm unsure this is readable it looks very inconsistent to have if (
!PvNode && depth > 3 &&
abs(beta) < VALUE_TB_WIN_IN_MAX_PLY
// If value from transposition table is lower than probCutBeta, don't attempt probCut
// there and in further interactions with transposition table cutoff depth is set to depth - 3
// because probCut search has depth set to depth - 4 but we also do a move before it
// So effective depth is equal to depth - 3
&& !(tte->depth() >= depth - 3 && ttValue != VALUE_NONE && ttValue < probCutBeta)) { This also simply removes the emphasis of the importance of every condition and is just trying to fit as much is possible in one line // Step 9. Null move search with verification search (~35 Elo)
if (!PvNode && (ss - 1)->currentMove != MOVE_NULL && (ss - 1)->statScore < 17329 &&
eval >= beta && eval >= ss->staticEval &&
ss->staticEval >= beta - 21 * depth + 258 && !excludedMove &&
pos.non_pawn_material(us) && ss->ply >= thisThread->nmpMinPly &&
beta > VALUE_TB_LOSS_IN_MAX_PLY) { |
rightful punishment for writing lines of comments between terms in a condition in an if statement ? ;-) |
I dont think it is, developers now have to worry about much less when writing code. One could consider moving this also into the build stage so that the github diff on fishtest is also (almost) always formatted.
I think the main big conditional alignments that we have, are in |
Moving it in the build phase is not a good idea, it should be an explicit dev action to reformat (otherwise editors will see changing file after a compile, etc). |
TBH it should be done here if (capture || givesCheck) {
// Futility pruning for captures (~2 Elo)
if (!givesCheck && lmrDepth < 7 && !ss->inCheck &&
ss->staticEval + 197 + 248 * lmrDepth +
PieceValue[pos.piece_on(to_sq(move))] +
captureHistory[movedPiece][to_sq(move)]
[type_of(pos.piece_on(to_sq(move)))] /
7 <
alpha)
continue; IMO if the format could be avoided on very long conditions in search.cpp that would be great! besides that I would assume that doing this inside search.cpp is the way to go then (I didn't know it could be disabled) with this:
|
Looks fine, certainly better than no automatic formatting. However, I'd suggest the following additions that should make it closer to the current formatting: https://clang.llvm.org/docs/ClangFormatStyleOptions.html#allowallparametersofdeclarationonnextline
https://clang.llvm.org/docs/ClangFormatStyleOptions.html#breakbeforebinaryoperators (should help with the case above)
https://clang.llvm.org/docs/ClangFormatStyleOptions.html#breakbeforeternaryoperators
https://clang.llvm.org/docs/ClangFormatStyleOptions.html#namespaceindentation
https://clang.llvm.org/docs/ClangFormatStyleOptions.html#packconstructorinitializers
I also suggest increasing the column limit to 120. It may help with some heavily nested stuff that we do need. |
d989898
to
2a3a295
Compare
d5ce2f6
to
3abc9da
Compare
- AllowShortIfStatementsOnASingleLine: WithoutElse
+ AllowShortIfStatementsOnASingleLine: false |
LGTM |
|
Sorry, but this pull request breaks the code readability in so many ways that I consider it a huge regression |
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.
while it's pretty good overall, it needs to be less agressive. Especially in places like search. 99% is fine, but the 1% is way too annoying.
|
||
// Optimal PRNG seeds to pick the correct magics in the shortest time | ||
int seeds[][RANK_NB] = { { 8977, 44560, 54343, 38998, 5731, 95205, 104912, 17020 }, | ||
{ 728, 10316, 55013, 32803, 12281, 15100, 16645, 255 } }; | ||
int seeds[][RANK_NB] = {{8977, 44560, 54343, 38998, 5731, 95205, 104912, 17020}, |
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.
we lost spaces before/after braces in initlializer lists
src/search.cpp
Outdated
&& ttValue >= probCutBeta | ||
&& abs(ttValue) <= VALUE_KNOWN_WIN | ||
&& abs(beta) <= VALUE_KNOWN_WIN) | ||
if (ss->inCheck && !PvNode && ttCapture && (tte->bound() & BOUND_LOWER) && tte->depth() >= depth - 4 |
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.
yeaaaa I think do need to somehow force old formatting for these, this will get pretty bad quickly
on mac you might need to install |
We can have breaking before braces specifically for control statements with the - BreakBeforeBraces: Attach
+ BreakBeforeBraces: Custom
+ BraceWrapping:
+ AfterFunction: false
+ AfterClass: true
+ AfterControlStatement: true |
So trying to be constructive:
That is, we can use the following style of coding:
|
I have tried out the branch and in principal the formatting seems good enough. But i have two points:
EDIT: Most stuff is more or less idention. Some are good like no big space before one-line comment after statement, but at some points it seems to indent consecutive statements not so that their alligned. |
3abc9da
to
3237177
Compare
@Disservin |
so are you using a development branch of clang? The newest release is https://github.com/llvm/llvm-project/releases 17.0.3 |
@Disservin |
@vondele |
I was on 16.0.6, the diff should have only been small though, some macro fixes from clang and some fixed comments. The make target was also assuming that the clang format file is in the parent/root directory, if you instead had one in your local dir you would end up with different formatting, though I dont think that was the case for you ;) |
I think this is getting in shape for merging. Most comments that could be integrated in clang-format have been integrated, and I believe the resulting code is pretty easy to read in almost all cases. The CI integration will also help to keep the format consistent in the future. |
as it can be seen here Disservin#20 |
Nice! Is there a reason why the bot message recommends |
In principle the minor version numbers (17.0.2 and 17.0.3 should give the same format), and I expect any release from the 17 series to give the same result, except when regressions are fixed (i.e. 16.0.2 and 16.0.3 give slightly different results). It just happens that 17.0.3 is the last released version, and will be what one downloads either here: https://github.com/llvm/llvm-project/releases or it is the one that is obtained if the repo is added in ubuntu, for example for ubuntu 22, see
The make file quite easily allow to use the proper version available after unpacking one of the release tarbals, without changing the default compiler on the system, for example:
|
Ok, fine. It just seems overly specific too me to "require/recommend" developers to use 17.0.3. As you mentioned, clang-format seems to follow semantic versioning, so everything with major version 17 should be fine and "not break things" (i.e. result in different formatting). Just anticipating a potential 17.0.4 or 17.1.0 release, when the message would become outdated/pedantic. |
Maybe the bot could automatically extract (clang-format --version) its version. I think the precise version should be provided somewhere as part of the message, but maybe not in the way it is formulated right now. |
cb8e2af
to
c1719da
Compare
This introduces clang-format to enforce a consistent code style for Stockfish. The lack of an automated code formatter has been a long standing issue official-stockfish#3608. This PR includes a Makefile target to format the code accordingly and write a comment on the PR on GitHub if any formatting changes are required. closes official-stockfish#3608 Co-Authored-By: Joost VandeVondele <[email protected]>
c1719da
to
920e16f
Compare
Add a `.git-blame-ignore-revs` file which can be used to skip specified commits when blaming, this is useful to ignore formatting commits, like clang-format #4790. Github blame automatically supports this file format, as well as other third party tools. Git itself needs to be told about the file name to work, the following command will add it to the current git repo. `git config blame.ignoreRevsFile .git-blame-ignore-revs`, alternatively one has to specify it with every blame. `git blame --ignore-revs-file .git-blame-ignore-revs search.cpp` Supported since git 2.23. closes #4969 No functional change
Add a `.git-blame-ignore-revs` file which can be used to skip specified commits when blaming, this is useful to ignore formatting commits, like clang-format official-stockfish#4790. Github blame automatically supports this file format, as well as other third party tools. Git itself needs to be told about the file name to work, the following command will add it to the current git repo. `git config blame.ignoreRevsFile .git-blame-ignore-revs`, alternatively one has to specify it with every blame. `git blame --ignore-revs-file .git-blame-ignore-revs search.cpp` Supported since git 2.23. closes official-stockfish#4969 No functional change
Add a `.git-blame-ignore-revs` file which can be used to skip specified commits when blaming, this is useful to ignore formatting commits, like clang-format official-stockfish#4790. Github blame automatically supports this file format, as well as other third party tools. Git itself needs to be told about the file name to work, the following command will add it to the current git repo. `git config blame.ignoreRevsFile .git-blame-ignore-revs`, alternatively one has to specify it with every blame. `git blame --ignore-revs-file .git-blame-ignore-revs search.cpp` Supported since git 2.23. closes official-stockfish#4969 No functional change
Add a `.git-blame-ignore-revs` file which can be used to skip specified commits when blaming, this is useful to ignore formatting commits, like clang-format official-stockfish#4790. Github blame automatically supports this file format, as well as other third party tools. Git itself needs to be told about the file name to work, the following command will add it to the current git repo. `git config blame.ignoreRevsFile .git-blame-ignore-revs`, alternatively one has to specify it with every blame. `git blame --ignore-revs-file .git-blame-ignore-revs search.cpp` Supported since git 2.23. closes official-stockfish#4969 No functional change
Introduce clang-format to enforce a code style for Stockfish.
The lack of an automated code formatter has been a long standing issue #3608.
This PR includes a Makefile target to format the code accordingly.
closes #3608