Skip to content

Conversation

@emily-howell
Copy link
Member

Can be played around with locally by calling:

find ./src/libs/ascent/ -regex '.*\.\(c\|cpp\|h\|hpp\)' -exec clang-format -i {} +

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

@emily-howell emily-howell self-assigned this Apr 15, 2025
@emily-howell
Copy link
Member Author

emily-howell commented Apr 15, 2025

@cyrush @nicolemarsaglia this is a first pass a what formatting could look like. My changes are the .clang-format file. Everything else is the result of running the formatter on Ascent code. The goal here is not to merge this in but rather show what changes would occur if this was added.

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.


#include <ascent_config.h>
#include <ascent_exports.h>
# define ASCENT_HOLA_HPP
Copy link
Member

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.

Copy link
Member Author

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)
Copy link
Member

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)
Copy link
Member

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

Copy link
Member

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?

Copy link
Member

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.

Copy link
Member

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

Copy link
Member

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); }
Copy link
Member

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

Copy link
Member Author

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);
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

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

Copy link
Member

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

Copy link
Member Author

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.

Copy link
Member

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.

Comment on lines +14 to +15
AlignConsecutiveAssignments: false # Don't bother lining up `=` symbols in consecutive lines
AlignConsecutiveDeclarations: false # Don't bother lining up `=` symbols in consecutive lines
Copy link
Member

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;

Copy link
Member Author

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

Copy link
Member Author

@emily-howell emily-howell Apr 22, 2025

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
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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.

Copy link
Member Author

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

Copy link
Member

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?

Copy link
Member Author

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
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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.

Copy link
Member Author

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.

Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
AccessModifierOffset: -4 # Access modifiers (public:, private:, protected:) should be inset
AccessModifierOffset: 0 # Access modifiers (public:, private:, protected:) should be inset

🙃

Copy link
Member Author

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();

Copy link
Member

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.

Copy link
Member Author

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 :(.

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