Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(115)

Issue 748863003: gn format: penalty-based scheme for line breaking (Closed)

Created:
6 years, 1 month ago by scottmg
Modified:
6 years ago
Reviewers:
brettw
CC:
chromium-reviews, tfarina
Base URL:
https://chromium.googlesource.com/chromium/src.git@gn-more-disabled
Project:
chromium
Visibility:
Public.

Description

gn format: penalty-based scheme for line breaking Previously, determining where newlines were inserted for line breaking was primarily top-down. Some parts of the code asked for the length of its subexpressions, and then made a decision on how to split based on how wide those were, but the subexpressions were evaluated without any context. This breaks down in more complicated cases, in particular when the subexpressions are more complicated than the parent one. The new approach is to attempt various layouts and score them based on a penalty scheme. Things like exceeding the column limit have a large penalty, things like causing additional horizontal separation or adding more lines than necessary have lesser penalties. There is also a bias towards splitting higher in the parse tree which balances expressions better. e.g. args = rebase_path(sources, root_build_dir) + rebase_path(outputs, root_build_dir) vs. args = rebase_path(sources, root_build_dir) + rebase_path(outputs, root_build_dir) are both correct and take the same number of lines, but the second is nicer to read. This will be doing a lot more work in deep expressions, which seems like it could be a performance issue in pathological cases. In practice, formatting all of Chrome's BUILD.gn's is still fast so it's OK for now. The work is repetitive, and could be cached if necessary in the future. There are also some other fixes to continuation of indents that were related to this change. It also rolls in a version of https://codereview.chromium.org/731923003/ (making distinguished items multiline per style guide). A sample run of reformatting all of Chrome after this is at: https://codereview.chromium.org/704363002 . (This was a bit of a battle: Nope! https://codereview.chromium.org/742003002/ Nope! https://codereview.chromium.org/750373002/ Nope! https://codereview.chromium.org/750373002/ . This one is less generic, but seems to work well.) R=brettw@chromium.org BUG=348474 Committed: https://crrev.com/fede808424d25f2767f58c01a4cd30f7f053a32d Cr-Commit-Position: refs/heads/master@{#305881}

Patch Set 1 #

Patch Set 2 : . #

Patch Set 3 : . #

Patch Set 4 : . #

Patch Set 5 : integrating penalties #

Patch Set 6 : func call fixes #

Patch Set 7 : higher linebreak penalty for deeper in tree, and for horizontal separation between lhs/rhs of binop #

Patch Set 8 : nice function formatting #

Patch Set 9 : wip on alignment #

Patch Set 10 : wip, mucking with alignment #

Patch Set 11 : . #

Patch Set 12 : . #

Patch Set 13 : . #

Patch Set 14 : fix suffixes not being taken into account in measurement #

Patch Set 15 : propagate penalties #

Patch Set 16 : rebase #

Patch Set 17 : . #

Total comments: 1

Patch Set 18 : x64 #

Unified diffs Side-by-side diffs Delta from patch set Stats (+731 lines, -191 lines) Patch
M tools/gn/command_format.cc View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 24 chunks +271 lines, -150 lines 0 comments Download
M tools/gn/command_format_unittest.cc View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 1 chunk +15 lines, -3 lines 0 comments Download
M tools/gn/format_test_data/003.golden View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 chunk +3 lines, -1 line 0 comments Download
M tools/gn/format_test_data/004.golden View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 chunk +3 lines, -1 line 0 comments Download
M tools/gn/format_test_data/007.golden View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 chunk +3 lines, -1 line 0 comments Download
M tools/gn/format_test_data/008.golden View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 chunk +3 lines, -1 line 0 comments Download
M tools/gn/format_test_data/009.golden View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 chunk +6 lines, -2 lines 0 comments Download
M tools/gn/format_test_data/010.golden View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 chunk +6 lines, -2 lines 0 comments Download
M tools/gn/format_test_data/011.golden View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 chunk +9 lines, -3 lines 0 comments Download
M tools/gn/format_test_data/012.golden View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 chunk +9 lines, -3 lines 0 comments Download
M tools/gn/format_test_data/015.golden View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 chunk +3 lines, -1 line 0 comments Download
M tools/gn/format_test_data/021.golden View 1 2 3 4 5 6 7 1 chunk +4 lines, -5 lines 0 comments Download
M tools/gn/format_test_data/023.golden View 1 2 3 4 5 6 7 8 1 chunk +4 lines, -5 lines 0 comments Download
M tools/gn/format_test_data/032.gn View 1 2 1 chunk +1 line, -0 lines 0 comments Download
M tools/gn/format_test_data/032.golden View 1 2 3 1 chunk +1 line, -0 lines 0 comments Download
A tools/gn/format_test_data/037.golden View 1 2 1 chunk +6 lines, -0 lines 0 comments Download
A tools/gn/format_test_data/039.golden View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 1 chunk +4 lines, -0 lines 0 comments Download
M tools/gn/format_test_data/042.gn View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 chunk +36 lines, -11 lines 0 comments Download
A tools/gn/format_test_data/042.golden View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 chunk +101 lines, -0 lines 0 comments Download
A tools/gn/format_test_data/043.gn View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 chunk +7 lines, -0 lines 0 comments Download
A tools/gn/format_test_data/043.golden View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 chunk +8 lines, -0 lines 0 comments Download
A tools/gn/format_test_data/044.gn View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 chunk +10 lines, -0 lines 0 comments Download
A tools/gn/format_test_data/044.golden View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 chunk +11 lines, -0 lines 0 comments Download
A tools/gn/format_test_data/045.gn View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 chunk +10 lines, -0 lines 0 comments Download
A tools/gn/format_test_data/045.golden View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 chunk +14 lines, -0 lines 0 comments Download
A tools/gn/format_test_data/046.gn View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 chunk +22 lines, -0 lines 0 comments Download
A tools/gn/format_test_data/046.golden View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 chunk +19 lines, -0 lines 0 comments Download
A tools/gn/format_test_data/047.gn View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 chunk +7 lines, -0 lines 0 comments Download
A tools/gn/format_test_data/047.golden View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 chunk +10 lines, -0 lines 0 comments Download
A tools/gn/format_test_data/048.gn View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 chunk +19 lines, -0 lines 0 comments Download
A tools/gn/format_test_data/048.golden View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 chunk +19 lines, -0 lines 0 comments Download
A tools/gn/format_test_data/049.gn View 1 2 3 4 5 6 7 8 9 1 chunk +14 lines, -0 lines 0 comments Download
A tools/gn/format_test_data/050.gn View 1 2 3 4 5 6 7 8 9 1 chunk +10 lines, -0 lines 0 comments Download
A tools/gn/format_test_data/050.golden View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 chunk +27 lines, -0 lines 0 comments Download
A tools/gn/format_test_data/051.gn View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 chunk +6 lines, -0 lines 0 comments Download
A tools/gn/format_test_data/051.golden View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 chunk +7 lines, -0 lines 0 comments Download
A tools/gn/format_test_data/052.gn View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 1 chunk +11 lines, -0 lines 0 comments Download
M tools/gn/parse_tree.h View 1 2 3 4 5 6 7 8 9 10 11 12 1 chunk +9 lines, -0 lines 0 comments Download
M tools/gn/parse_tree.cc View 1 2 3 4 5 6 7 8 9 10 11 12 2 chunks +3 lines, -2 lines 0 comments Download

Messages

Total messages: 10 (2 generated)
scottmg
6 years ago (2014-11-24 22:38:51 UTC) #1
brettw
lgtm https://codereview.chromium.org/748863003/diff/320001/tools/gn/format_test_data/039.golden File tools/gn/format_test_data/039.golden (right): https://codereview.chromium.org/748863003/diff/320001/tools/gn/format_test_data/039.golden#newcode3 tools/gn/format_test_data/039.golden:3: arm_float_abi == "soft" || arm_float_abi == "softfp") This ...
6 years ago (2014-11-26 18:28:34 UTC) #2
scottmg
On 2014/11/26 18:28:34, brettw wrote: > lgtm > > https://codereview.chromium.org/748863003/diff/320001/tools/gn/format_test_data/039.golden > File tools/gn/format_test_data/039.golden (right): > ...
6 years ago (2014-11-26 19:01:06 UTC) #3
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/748863003/320001
6 years ago (2014-11-26 19:01:58 UTC) #5
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/748863003/340001
6 years ago (2014-11-26 20:03:51 UTC) #7
scottmg
On 2014/11/26 19:01:06, scottmg wrote: > On 2014/11/26 18:28:34, brettw wrote: > > lgtm > ...
6 years ago (2014-11-26 20:34:16 UTC) #8
commit-bot: I haz the power
Committed patchset #18 (id:340001)
6 years ago (2014-11-26 20:47:00 UTC) #9
commit-bot: I haz the power
6 years ago (2014-11-26 20:47:43 UTC) #10
Message was sent while issue was closed.
Patchset 18 (id:??) landed as
https://crrev.com/fede808424d25f2767f58c01a4cd30f7f053a32d
Cr-Commit-Position: refs/heads/master@{#305881}

Powered by Google App Engine
This is Rietveld 408576698