Skip to content

Format all the things - #1435

Closed
kripken wants to merge 7 commits into
masterfrom
formatting
Closed

Format all the things#1435
kripken wants to merge 7 commits into
masterfrom
formatting

Conversation

@kripken

@kripken kripken commented Feb 21, 2018

Copy link
Copy Markdown
Member

Followup for #1407. This runs clang-format and clang-tidy on everything.

Downsides:

  • Long-term loss of git-blame effectiveness.
  • Short-term annoyance in getting this merged and other PRs in progress conflicting with it.
  • This is my first time using these two clang tools. I am somewhat concerned after seeing that I needed to fix these two things up: d5a6ccb#diff-20f762851bbf02620da8d3164ff6dd7bL36 b42b303 - luckily those were also compilation errors, but others might not be. And a full review of all the changes here to look for bugs is impractical due to the size.
  • Also it does fun things to EM_ASMs, but can't blame it there ;) 8b94451

Thoughts on if this is a good idea?

done with

  clang-tidy -checks="-*,readability-braces-around-statements" `find -name "*.cpp"` -fix-errors -- -xc++ -std=c++11 -I. -w
  etc.
  find ./ -name '*.cpp' -or -name '*.h' | xargs ~/Dev/fastcomp/build/bin/clang-format -i
@kripken kripken mentioned this pull request Feb 21, 2018
@sbc100

sbc100 commented Feb 21, 2018

Copy link
Copy Markdown
Member

Do you know it was was clang-tidy or clang-format that introduced the bugs.

My understanding of clang-format at least is that this should be impossible. Not sure thats true of clang-tidy which I guess can do more complex transforms. If it was clang-format that did it, its probably worth filing a bug.

Comment thread src/asmjs/asm_v_wasm.cpp
case 'd': return f64;
case 'v': return none;
default: abort();
case 'i':

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wonder if we can find a setting to allow this kind of thing?

@aheejin aheejin Feb 21, 2018

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Setting AllowShortCaseLabelsOnASingleLine to true allows this, but settings also means converting all two-line case statements into a single line if they fit in 120 cols, the current ColumnLimit. There are several options like this; refer to the bottom of #1407 (comment) for details.

So we have to either convert all

case 'i':
  blahblah;

into

case 'i': blahblah;

or we have to convert all

case 'i': blahblah;

into

case 'i':
  blahblah;

So the point is, even though the option name is AllowShortCaseLabelsOnASingleLine, there is no option that allows something. clang-format, in nature, forces a single style for given code and configurations. The option should read as ForceShortCaseLabelsOnASingleLine.

Merging all two-line case statements (or if statements, ...) into a single line may not sound that bad, but we also have ColumnLimit of 120, which is longer than usual. This will merge a lot of two-line case statements into one. So, I was not able to decide, so I ended up not adding those Allow*** options. We can add them if people prefer that.

@sbc100 sbc100 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is it worth doing the clang-format and clang-tidy separately? (I'm not sure exactly what the distinctions are, but I get the impression clang-format is safer, since its limited to basically whitespace only changes).

WASM_ROTR64("__wasm_rotr_i64"),
WASM_GROW_MEMORY("__wasm_grow_memory"),
WASM_CURRENT_MEMORY("__wasm_current_memory");
cashew::IString GLOBAL("global"), NAN_("NaN"), INFINITY_("Infinity"), NAN__("nan"),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This one seems pretty bad

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

When comparing changes in #1407, I also noticed this, and I couldn't help it. The only option that allows multi-line definition in this case was ColumnLimit = 0, which effectively enforces no limit on the column length. Funnily, this allows multi-line definitions. Don't know why.

WASM_ROTR64,
WASM_GROW_MEMORY,
WASM_CURRENT_MEMORY;
extern cashew::IString GLOBAL, NAN_, INFINITY_, NAN__, INFINITY__, TOPMOST, INT8ARRAY, INT16ARRAY,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This too. I wonder if this could should be done via a "#include .def" thing?

Comment thread src/ir/utils.h
return
return builder.makeBinary(OrInt64, builder.makeUnary(ExtendUInt32, low),
builder.makeBinary(
OrInt64,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is it OK to looks this structure?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm not happy about this change, yeah.

Comment thread src/pass.h
int optimizeLevel = 0; // 0, 1, 2 correspond to -O0, -O1, -O2, etc.
int shrinkLevel = 0; // 0, 1, 2 correspond to -O0, -Os, -Oz
bool ignoreImplicitTraps =
false; // optimize assuming things like div by 0, bad load/store, will not trap

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks a but odd.

@aheejin

aheejin commented Feb 21, 2018

Copy link
Copy Markdown
Member

@sbc100 To my understanding, the reason @kripken wanted clang-tidy was he wanted to ensure there is always enclosing braces for single-line ifs and loops. So, he wanted to convert

if (condition)
  statement;

to

if (condition) {
  statement;
}

@aheejin

aheejin commented Feb 21, 2018

Copy link
Copy Markdown
Member

I haven't checked all the code changes yet, but I also wonder if the bugs are caused by clang-format or clang-tidy. IIUC clang-format cannot change characters in code except whitespaces.

I also agree that this might be hard to test. Applying the style incrementally, by recommending people to apply clang-format on the part of the code they modify using git clang-format, might be a better option.

@kripken

kripken commented Feb 21, 2018

Copy link
Copy Markdown
Member Author

Looks like it was clang-tidy that caused both of those bugs.

@kripken

kripken commented Apr 3, 2018

Copy link
Copy Markdown
Member Author

Probably doens't make sense to do this. I'll leave the branch though if we want to reconsider this in the future.

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.

3 participants