Format all the things - #1435
Conversation
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
|
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. |
| case 'd': return f64; | ||
| case 'v': return none; | ||
| default: abort(); | ||
| case 'i': |
There was a problem hiding this comment.
I wonder if we can find a setting to allow this kind of thing?
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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"), |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
This too. I wonder if this could should be done via a "#include .def" thing?
| return | ||
| return builder.makeBinary(OrInt64, builder.makeUnary(ExtendUInt32, low), | ||
| builder.makeBinary( | ||
| OrInt64, |
There was a problem hiding this comment.
Is it OK to looks this structure?
There was a problem hiding this comment.
I'm not happy about this change, yeah.
| 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 |
|
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 |
|
Looks like it was clang-tidy that caused both of those bugs. |
|
Probably doens't make sense to do this. I'll leave the branch though if we want to reconsider this in the future. |
Followup for #1407. This runs clang-format and clang-tidy on everything.
Downsides:
Thoughts on if this is a good idea?