DRAFT: First pass at a clang formatter#1500
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.
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.
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.
indents do improve readability here
| //----------------------------------------------------------------------------- | ||
| // forward declare | ||
| #if defined(ASCENT_DRAY_ENABLED) | ||
| # if defined(ASCENT_DRAY_ENABLED) |
There was a problem hiding this comment.
def indent nesting doesn't work well for this case
There was a problem hiding this comment.
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.
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.
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
| { | ||
| out.set(m_info); | ||
| } | ||
| void EmptyRuntime::Info(conduit::Node &out) { out.set(m_info); } |
There was a problem hiding this comment.
I prefer multi line even for these simple guys
There was a problem hiding this comment.
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.
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.
If you add comments it won't put them on the same line anymore.
There was a problem hiding this comment.
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.
^ It would support that case Justin
The comments make it wrap, even on short lines
There was a problem hiding this comment.
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.
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.
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.
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.
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.
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.
| 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.
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.
Does it let you put the arguments on multiple lines when set to true?
There was a problem hiding this comment.
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.
| 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.
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.
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.
| 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.
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.
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.
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