-
Notifications
You must be signed in to change notification settings - Fork 71
DRAFT: First pass at a clang formatter #1500
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: develop
Are you sure you want to change the base?
Conversation
|
@cyrush @nicolemarsaglia this is a first pass a what formatting could look like. My changes are the Please criticize and tear this apart!! The goal here is to spur discussion if it is needed. Eventually, this would need to be built into the CI and also be run on the tests and other files. |
src/libs/ascent/hola/ascent_hola.hpp
Outdated
|
|
||
| #include <ascent_config.h> | ||
| #include <ascent_exports.h> | ||
| # define ASCENT_HOLA_HPP |
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.
In general I like intended defs, however for the header file case there is always a indef / define that wraps the whole file to avoid multiple definitions.
It would be good to not indent the normal includes for this case.
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.
Unfortunately, there isn't a ton of knobs to turn with respect to the preprocessor directives. The only thing I really found was to indent or not to indent. I personally really like the indentation as it greatly improves readability but I do agree that having a blanket policy for it means that some things have slightly wonky indentation.
| # else | ||
| # define ASCENT_PYTHON_API __declspec(dllimport) | ||
| # endif | ||
| # if defined(_MSC_VER) |
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.
indents do improve readability here
| //----------------------------------------------------------------------------- | ||
| // forward declare | ||
| #if defined(ASCENT_DRAY_ENABLED) | ||
| # if defined(ASCENT_DRAY_ENABLED) |
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.
def indent nesting doesn't work well for this case
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.
The setting Emily has now indents after the hash. There is another setting to indent the hash too. Is that what you didn't like, or you just didn't want it indented at all?
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.
All our header files look like:
#ifndef HDR_FILE_NAME
#define HDR_FILE_NAME
...
#include <myheader1>
#include <myheader2>
#include <myheader3>
#include <myheader4>
...
#endif
The current setup transforms them all to:
#ifndef HDR_FILE_NAME
# define HDR_FILE_NAME
# include <myheader1>
# include <myheader2>
# include <myheader3>
...
#endif
Not a fan of this, I don't think it is an improvement.
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.
in this case HDR_FILE_NAME is to avoid duplicate defs, but its not otherwise important to the structure or semantics of the header file
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 see
| { | ||
| out.set(m_info); | ||
| } | ||
| void EmptyRuntime::Info(conduit::Node &out) { out.set(m_info); } |
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 prefer multi line even for these simple guys
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.
Updated to only allow single line for empty functions
| conduit::relay::mpi::sum_all_reduce(n_src, | ||
| n_reduce, | ||
| mpi_comm); | ||
| conduit::relay::mpi::sum_all_reduce(n_src, n_reduce, mpi_comm); |
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 also like multi line in these cases, not sure if it is possible to retain them.
For longer functions multi line allows you to add comments after each of the arguments.
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.
If you add comments it won't put them on the same line anymore.
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.
Yikes! I rely on that many places in Conduit: https://github.com/LLNL/conduit/blob/8f5a32ae6540eaead82d287f231fe84d0cd8540a/src/libs/relay/conduit_relay_io_silo.cpp#L4854
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.
^ It would support that case Justin
The comments make it wrap, even on short lines
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.
If you add comments it won't put them on the same line anymore.
I'm confused. So comments will be on the same line?
Oh I get it! When you said "them" you meant the arguments, not the comments for those arguments. 🙃
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.
Yes, sorry, that wasn't clear
It will absolutely respect that comments are placed next to the arguments and it will wrap all of the arguments onto their own lines.
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.
No worries. I was reading too fast.
| AlignConsecutiveAssignments: false # Don't bother lining up `=` symbols in consecutive lines | ||
| AlignConsecutiveDeclarations: false # Don't bother lining up `=` symbols in consecutive lines |
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.
does this enforce this
int a = 1;
float b = 2.0;
double c = 3.0;
versus this?
int a = 1;
float b = 2.0;
double c = 3.0;
or does it just relax the restriction so users can do whatever?
Also, as far as I know, AlignConsecutiveDeclarations is not for lining up = symbols, it is aligning declarations like this:
int a;
float b;
double c;
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.
AlignConsecutiveDeclarations will turn
int a = 1;
float bbb = 2.0;
double c = 3.0;
into
int a = 1;
float bbb = 2.0;
double c = 3.0;
And AlignConsecutiveAssignments applies to assignments both in declarations and not
a = 1;
bbb = 2.0;
c = 3.0;
into
a = 1;
bbb = 2.0;
c = 3.0;
It does not relax the requirement.
I personally don't want these to be set to true. You end up with a lot of changes like:
T identity = std::numeric_limits<T>::lowest();
const int size = accessor.m_size;
using for_policy = typename Exec::for_policy;
using reduce_policy = typename Exec::reduce_policy;
becoming
T identity = std::numeric_limits<T>::lowest();
const int size = accessor.m_size;
using for_policy_thing = typename Exec::for_policy;
using reduce_policy_thing = typename Exec::reduce_policy;
Which looks wonky to me personally
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.
It does look like the default behavior is to not align things
| BinPackParameters: false # One param per line if wrapped | ||
| BinPackArguments: false # One argument per line if wrapped | ||
| AlignAfterOpenBracket: Align # Align wrapped args/params under the first | ||
| AllowAllParametersOfDeclarationOnNextLine: false |
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.
| AllowAllParametersOfDeclarationOnNextLine: false | |
| AllowAllParametersOfDeclarationOnNextLine: true |
I think this should be true. Sometimes namespace::method() names get so long that it is useful to put parameter declarations on the following lines.
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.
What I don't like is that when you make that change you get:
conduit::Node ASCENT_API field_reduction_max(
const conduit::Node &field, const std::string &component = "");
rather than when it is false it gives:
conduit::Node ASCENT_API
history_gradient_range(const conduit::Node &y_values,
const conduit::Node &dx_values);
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.
Does it let you put the arguments on multiple lines when set to 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.
It does, but it seems to prioritize grouping things in a way I don't love. When there are enough arguments or the named are long enough both true and false will wrap the arguments onto their own lines
.clang-format
Outdated
| # Indentation | ||
| IndentWidth: 4 | ||
| UseTab: Never | ||
| IndentPPDirectives: AfterHash # don't indent things like `#ifdef` and `#define` unless nested |
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.
| IndentPPDirectives: AfterHash # don't indent things like `#ifdef` and `#define` unless nested | |
| IndentPPDirectives: Always # don't indent things like `#ifdef` and `#define` unless nested |
I prefer Always if we have to do this at all. With extreme nesting this can potentially be burdensome.
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.
Always isn't an option but I can change it to BeforeHash which will also indent the hash.
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.
Hah! Thanks Livchat. BeforeHash is the right answer then :)
| ################## | ||
| ### Namespaces ### | ||
| ################## | ||
| AccessModifierOffset: -4 # Access modifiers (public:, private:, protected:) should be inset |
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.
| AccessModifierOffset: -4 # Access modifiers (public:, private:, protected:) should be inset | |
| AccessModifierOffset: 0 # Access modifiers (public:, private:, protected:) should be inset |
🙃
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.
Hmm. I don't know that I agree with this. That change would make header files significantly harder to read.
AccessModifierOffset: -4
class ASCENT_API ExpressionEval
{
protected:
DataObject m_data_object;
flow::Workspace w;
static Cache m_cache;
void jit_root(conduit::Node &root, const std::string &expr_name);
public:
ExpressionEval(DataObject &dataset);
ExpressionEval(conduit::Node *dataset);
DataObject &data_object();
}
AccessModifierOffset: 0
class ASCENT_API ExpressionEval
{
protected:
DataObject m_data_object;
flow::Workspace w;
static Cache m_cache;
void jit_root(conduit::Node &root, const std::string &expr_name);
public:
ExpressionEval(DataObject &dataset);
ExpressionEval(conduit::Node *dataset);
DataObject &data_object();
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 blame Livchat again. I like the -4. I (mistakenly) thought -4 and 0 would have the opposite effect of what they actually have.
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.
LivChat really does hallucinate a lot on this topic unfortunately. It is especially disappointing when I ask for a setting to change something and it makes up something only for that setting to not really exist :(.
Can be played around with locally by calling:
I don't know that I want all of the formatting to go in in one big MR like this. This is more a vessel to visualize the types of changes it will make