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

feature: Add make style target and refactor RAJA with clang-format #1767

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from

Conversation

johnbowen42
Copy link
Contributor

This PR applies clang-format to the include and src directories of develop

@johnbowen42
Copy link
Contributor Author

johnbowen42 commented Nov 13, 2024

@rhornung67 and I worked on the settings this morning. Here is what we settled on:

  • RAJA/.clang-format

    Lines 12 to 16 in c5bee85

    # Alignment of consecutive declarations, assignments etc
    AlignConsecutiveAssignments : true
    AlignConsecutiveDeclarations : false
    AlignConsecutiveMacros : true
    AlignTrailingComments : true
    • example:
    • RAJA_INLINE constexpr IndexValue() = default;
      constexpr RAJA_INLINE IndexValue(IndexValue const&) = default;
      constexpr RAJA_INLINE IndexValue(IndexValue&&) = default;
      RAJA_INLINE IndexValue& operator=(IndexValue const&) = default;
      RAJA_INLINE IndexValue& operator=(IndexValue&&) = default;
  • RAJA/.clang-format

    Lines 20 to 37 in c5bee85

    BraceWrapping:
    AfterCaseLabel: true
    AfterClass: true
    AfterControlStatement: true
    AfterEnum: true
    AfterFunction: true
    AfterNamespace: true
    AfterObjCDeclaration: false
    AfterStruct: true
    AfterUnion: true
    AfterExternBlock: false
    BeforeCatch: true
    BeforeElse: true
    BeforeLambdaBody: false
    IndentBraces: false
    SplitEmptyFunction: false
    SplitEmptyRecord: false
    SplitEmptyNamespace: false
    • This transparently controls whether a curly brace will occur on the next line following anything requiring a curly brace. Basically the only time we don't enforce curly brace on next line is for lambda body definitions and empty function definitions. Another notable exception is single line lambdas:
      AllowShortLambdasOnASingleLine : None
  • BinPackArguments : true
  • BinPackParameters : false
    • This doesn't enforce the same packing for parameters in function declarations
  • AlignAfterOpenBracket: Align
  • LambdaBodyIndentation : Signature
    • disallow single line lambdas, and indent the body one indent level relative to the indent level of the signature, e.g.
      {
      CONTAINER_T tcon;
      forall<seq_exec>(seg, [&](typename CONTAINER_T::value_type idx) {
      if (conditional(idx)) tcon.push_back(idx);
      });
      con = tcon;
  • SeparateDefinitionBlocks : Always
    • enforce spacing between functions and other blocks, e.g.
      {
      return (value >= x.value);
      }
      RAJA_HOST_DEVICE RAJA_INLINE bool operator==(value_type x) const
      {
      return (value == x);
      }
      RAJA_HOST_DEVICE RAJA_INLINE bool operator==(TYPE x) const

@johnbowen42 johnbowen42 force-pushed the feature/bowen/add-clang-format-v2 branch from c11bf7c to 9a33df6 Compare November 14, 2024 23:33
}
);
forall<seq_exec>(seg, [&](typename CONTAINER_T::value_type idx) {
if (conditional(idx)) tcon.push_back(idx);
Copy link
Member

Choose a reason for hiding this comment

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

We're allowing no-curly braces in single line conditionals?

Copy link
Member

@rhornung67 rhornung67 Dec 18, 2024

Choose a reason for hiding this comment

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

I think we may have to move to clang-format 15 according to this: llvm/llvm-project@77e60bc

Note that we also get things like this currently: https://github.com/LLNL/RAJA/pull/1767/files#diff-e97c4ae7afcd5abc30afbee9cca754dcab6a4b2415e6396be367fd2d93103e22R54

Comment on lines 519 to 522
static constexpr bool use_host_invoke = dispatcher_use_host_invoke(platform);
using dispatch_policy = ::RAJA::direct_dispatch<T>;
using void_ptr_wrapper = DispatcherVoidPtrWrapper<DispatcherID>;
using dispatch_policy = ::RAJA::direct_dispatch<T>;
using void_ptr_wrapper = DispatcherVoidPtrWrapper<DispatcherID>;
using void_cptr_wrapper = DispatcherVoidConstPtrWrapper<DispatcherID>;
Copy link
Member

Choose a reason for hiding this comment

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

Interesting indentation matching choice.

Comment on lines +289 to +290
: m_vec(0, aloc),
m_aloc(aloc)
Copy link
Member

Choose a reason for hiding this comment

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

I guess my way of placing commas was not normal. Hopefully clang format understands that it can't pull commas out of ifdefs.

Comment on lines +670 to +671
if (loop_storage_size > storage_capacity())
{
Copy link
Member

Choose a reason for hiding this comment

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

Looks like we decided to put the curly on the line after conditionals.

Copy link
Member

Choose a reason for hiding this comment

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

Yes. John discussed this in a recent meeting.

Comment on lines +36 to +38
using Base = reduce::detail::BaseMultiReduce##OP_NAME< \
DATA<T, RAJA::reduce::OP<T>, tuning>>; \
using Base::Base; \
Copy link
Member

Choose a reason for hiding this comment

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

I guess something confused its indentation alignment.

Copy link
Member

Choose a reason for hiding this comment

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

I think clang-format has problems with making nested templates look pretty and readable, in general. That's why we won't be running it in the examples, exercises, and test directories.

@johnbowen42 johnbowen42 force-pushed the feature/bowen/add-clang-format-v2 branch from 3a680ce to 11ccdbc Compare December 12, 2024 19:39



#. The CMake build target `style`
Copy link
Contributor Author

@johnbowen42 johnbowen42 Dec 13, 2024

Choose a reason for hiding this comment

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

@rhornung67 I added docs to this PR if you'd like to review

Copy link
Member

@rhornung67 rhornung67 left a comment

Choose a reason for hiding this comment

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

I'm good with most of the formatting choices. There is still some weirdness involving nested templates, and it's not entirely clear to me when opening curly braces should appear on a new line or at the end of the current line. Hopefully, we can make adjustments as we get used to this.

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