Skip to content

Conversation

@aheejin
Copy link
Member

@aheejin aheejin commented Apr 22, 2019

Looking at the current codebase, we mostly don't binpack arguments and
parameters when they don't fit in a single line.

BinPackArguments:

true:
void f() {
  f(aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa,
    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
}

false:
void f() {
  f(aaaaaaaaaaaaaaaaaaaa,
    aaaaaaaaaaaaaaaaaaaa,
    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
}

BinPackParameters:

true:
void f(int aaaaaaaaaaaaaaaaaaaa, int aaaaaaaaaaaaaaaaaaaa,
       int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}

false:
void f(int aaaaaaaaaaaaaaaaaaaa,
       int aaaaaaaaaaaaaaaaaaaa,
       int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}

Looking at the current codebase, we don't mostly binpack arguments and
parameters when they don't fit in a single line.

BinPackArguments:
```
true:
void f() {
  f(aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa,
    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
}

false:
void f() {
  f(aaaaaaaaaaaaaaaaaaaa,
    aaaaaaaaaaaaaaaaaaaa,
    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
}
```

BinPackParameters:
```
true:
void f(int aaaaaaaaaaaaaaaaaaaa, int aaaaaaaaaaaaaaaaaaaa,
       int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}

false:
void f(int aaaaaaaaaaaaaaaaaaaa,
       int aaaaaaaaaaaaaaaaaaaa,
       int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
```
@aheejin aheejin requested a review from kripken April 22, 2019 21:37
@aheejin
Copy link
Member Author

aheejin commented Apr 22, 2019

Looking at the ways to make formatting as much similar as to the current codebase, and this is one thing I saw. The other thing I'm not sure about is AlignAfterOpenBracket. Our current setting is Align, but in many places we do AlwaysBreak.

Align:

someLongFunction(argument1,
                 argument2);

DontAlign:

someLongFunction(argument1,
    argument2);

AlwaysBreak:

someLongFunction(
    argument1, argument2);

Currently we mostly do AlwaysBreak. But this also breaks after if statement if it doesn't fit in a single line, so

if (
  some_condition || very_long_condition....)

is possible. What do you think you prefer?

@aheejin aheejin requested a review from tlively April 22, 2019 21:42
Copy link
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

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

Yeah, I think that's more common here. Also looks better in my opinion.

@aheejin
Copy link
Member Author

aheejin commented Apr 22, 2019

@kripken Thanks. Did you see my comment about AlignAfterOpenBracket?

@kripken
Copy link
Member

kripken commented Apr 22, 2019

Oh, I just saw the AlignAfterOpenBracket comment now, sorry. Hmm, I don't have a preference either way there. Maybe Align?

@aheejin aheejin merged commit 831a774 into WebAssembly:master Apr 22, 2019
@aheejin aheejin deleted the no_binpack branch April 22, 2019 23:18
@aheejin
Copy link
Member Author

aheejin commented Apr 23, 2019

Hmm, after looking at some more code, I found that whether we binpack arguments in function calls or not is like 50:50, and we mostly rather binpack parameters. Should we remove BinPackParameters: false part?

aheejin added a commit to aheejin/binaryen that referenced this pull request Apr 24, 2019
This applies clang-format to the whole codebase. Below are manual tweaks
I had to make:

1. After clang-format changed the order of #includes, the code failed to
compile, so this also adds some missing header guards and more #includes
to make code compile.

2. After applying clang-format to this kind of code,
```
cashew::IString GLOBAL("global"),
                NAN_("NaN"),
                INFINITY_("Infinity"),
                NAN__("nan"),
                INFINITY__("infinity"),
                TOPMOST("topmost"),
                INT8ARRAY("Int8Array"),
                ...
```
This becomes
```
cashew::IString GLOBAL("global"), NAN_("NaN"), INFINITY_("Infinity"),
  NAN__("nan"), INFINITY__("infinity"), TOPMOST("topmost"),
  INT8ARRAY("Int8Array"), INT16ARRAY("Int16Array"),
  ...
```
I fixed the formatting by adding the type to every line as follows:
```
cashew::IString GLOBAL("global");
cashew::IString NAN_("NaN");
cashew::IString INFINITY_("Infinity");
cashew::IString NAN__("nan");
cashew::IString INFINITY__("infinity");
cashew::IString TOPMOST("topmost");
cashew::IString INT8ARRAY("Int8Array");
...
```

3. I fixed many parts of the comments for readability. The most
frequently occurring example was this:
```
SomeClass var = 123; // very very very very very very very very very very very very very very very very long comment
```
clang-format blinds transforms this into:
```
Someclass var
  = 123; // very very very very very very very very very very very very
         // very very very very long comment
```
I fixed these to:
```
// very very very very very very very very very very very very very very
// very very long comment
SomeClass var = 123;
```

4. I ended up using `clang-format off` and `clang-format on` to
explicitly disable clang-format only in one place in
`src/support/safe_integer.cpp`. We couldn't maintain its readability of
the last comment block there.

---

Please let me know if there are any suggestions to this or our current
.clang-format configuration. I tweaked our clang-format setting a bit
more in WebAssembly#1986, WebAssembly#2038, and WebAssembly#2044, but mostly I don't have strong
opinions.

This PR is intended only for code review and should not be merged to the
codebase. After this is reviewed and approved, I ask @kripken to create
a separate PR with the same diff and merge it, not to overwrite the
whole codebase with my username, who is not a very frequent contributor
here.

I also plan to add a hook that checks if the PR is properly
clang-formatted to our Travis CI, but I'm gonna test it in another PR
first.
aheejin added a commit to aheejin/binaryen that referenced this pull request Apr 24, 2019
This applies clang-format to the whole codebase. Below are manual tweaks
I had to make:

1. After clang-format changed the order of #includes, the code failed to
compile, so this also adds some missing header guards and more #includes
to make code compile.

2. After applying clang-format to this kind of code,
```
cashew::IString GLOBAL("global"),
                NAN_("NaN"),
                INFINITY_("Infinity"),
                NAN__("nan"),
                INFINITY__("infinity"),
                TOPMOST("topmost"),
                INT8ARRAY("Int8Array"),
                ...
```
This becomes
```
cashew::IString GLOBAL("global"), NAN_("NaN"), INFINITY_("Infinity"),
  NAN__("nan"), INFINITY__("infinity"), TOPMOST("topmost"),
  INT8ARRAY("Int8Array"), INT16ARRAY("Int16Array"),
  ...
```
I fixed the formatting by adding the type to every line as follows:
```
cashew::IString GLOBAL("global");
cashew::IString NAN_("NaN");
cashew::IString INFINITY_("Infinity");
cashew::IString NAN__("nan");
cashew::IString INFINITY__("infinity");
cashew::IString TOPMOST("topmost");
cashew::IString INT8ARRAY("Int8Array");
...
```

3. I fixed many parts of the comments for readability. The most
frequently occurring example was this:
```
SomeClass var = 123; // very very very very very very very very very very very very very very very very long comment
```
clang-format blinds transforms this into:
```
Someclass var
  = 123; // very very very very very very very very very very very very
         // very very very very long comment
```
I fixed these to:
```
// very very very very very very very very very very very very very very
// very very long comment
SomeClass var = 123;
```

4. I ended up using `clang-format off` and `clang-format on` to
explicitly disable clang-format only in one place in
`src/support/safe_integer.cpp`. We couldn't maintain its readability of
the last comment block there.

---

Please let me know if there are any suggestions to this or our current
.clang-format configuration. I tweaked our clang-format setting a bit
more in WebAssembly#1986, WebAssembly#2038, and WebAssembly#2044, but mostly I don't have strong
opinions.

This PR is intended only for code review and should not be merged to the
codebase. After this is reviewed and approved, I ask @kripken to create
a separate PR with the same diff and merge it, not to overwrite the
whole codebase with my username, who is not a very frequent contributor
here.

I also plan to add a hook that checks if the PR is properly
clang-formatted to our Travis CI, but I'm gonna test it in another PR
first.
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.

2 participants