This is an archive of the discontinued LLVM Phabricator instance.

Implement more accurate penalty & trade-offs while breaking protruding tokens.
AbandonedPublic

Authored by klimek on Nov 15 2017, 2:15 AM.

Details

Summary

This is a counter-proposal to D33589.

Event Timeline

klimek created this revision.Nov 15 2017, 2:15 AM
krasimir added inline comments.Nov 15 2017, 3:33 AM
lib/Format/ContinuationIndenter.cpp
1517

I'd rather

DEBUG({
  if (ReflowInProgress)
    llvm::dbgs() << "  Reflowing.\n";
});
unittests/Format/FormatTest.cpp
8007

Why did the string got on a newline here?

unittests/Format/FormatTestComments.cpp
2452

Please also leave the old test case, which is about the */ just going over the column limit if not put on a newline.

2461

Why change 15 to 16? The same for the subsequent cases.

2493

Please also leave the old test case, which is about the */ just going over the column limit if not put on a newline.

2495–2507

Please also leave the old test case, which is about the */ just going over the column limit if not put on a newline.

klimek updated this revision to Diff 123139.Nov 16 2017, 2:08 AM
klimek marked 4 inline comments as done.

Address review comments.

unittests/Format/FormatTest.cpp
8007

Because then we break inside the string less often? That seems clearly better than before?

unittests/Format/FormatTestComments.cpp
2461

Because we're breaking before the comment now (see above), which according to the doc I wrote you agree is better, but changing all the tests seemed to then test something completely different.

krasimir added inline comments.Nov 17 2017, 2:42 AM
lib/Format/ContinuationIndenter.cpp
1616

nit: remove an empty line

unittests/Format/FormatTest.cpp
9951

Why didn't this get reformatted as:

EXPECT_EQ("int a; /* first line\n"
          "        * second line\n"
          "        * third line\n"
          "        */",
klimek updated this revision to Diff 123309.Nov 17 2017, 3:09 AM
klimek marked an inline comment as done.

Address review comments.

unittests/Format/FormatTest.cpp
9951

Added FIXME.

krasimir accepted this revision.Nov 17 2017, 3:14 AM
This revision is now accepted and ready to land.Nov 17 2017, 3:14 AM
klimek updated this revision to Diff 123359.Nov 17 2017, 9:20 AM

Just exporting

Typz edited edge metadata.Nov 21 2017, 7:27 AM

Generally, this indeed improves the situation (though I cannot say much about the code itself, it is still too subtle for my shallow knowledge of clang-format).

But it seems to give some strange looking result with long comments: it seems like the decision is made at each line (e.g. is it better to wrap this line or overflow a bit), so we can get a comment where each line overflows by a few characters, even if the total is worse... For exemple, say we have a 100 lines of comment, with 9 characters overflow on each line, and an excess character penalty of 30 : with this patch nothing will be re-wrapped (9*30 = 270 is less the the 300 penalty for wrapping); but the total penatly would be 900....

(btw, it seems this got merged, but the ticket does not reflect it)

lib/Format/BreakableToken.cpp
289

commented-out code to be removed?

296

unconditional return --> remove the end of the function

560

remove commented-out code

595

BreakableLineCommentSection

krasimir requested changes to this revision.Nov 22 2017, 3:37 AM

looks like there are more changes needed.

This revision now requires changes to proceed.Nov 22 2017, 3:37 AM
In D40068#931679, @Typz wrote:

Generally, this indeed improves the situation (though I cannot say much about the code itself, it is still too subtle for my shallow knowledge of clang-format).

But it seems to give some strange looking result with long comments: it seems like the decision is made at each line (e.g. is it better to wrap this line or overflow a bit), so we can get a comment where each line overflows by a few characters, even if the total is worse... For exemple, say we have a 100 lines of comment, with 9 characters overflow on each line, and an excess character penalty of 30 : with this patch nothing will be re-wrapped (9*30 = 270 is less the the 300 penalty for wrapping); but the total penatly would be 900....

(btw, it seems this got merged, but the ticket does not reflect it)

Ugh, sorry, I think an arc patch I did without --create on a branch that was branched after the original patch was sent out broke phab :( :( This is not actually the state the patch was in when submitted, or the state it was LG'ed in (see https://reviews.llvm.org/rL318515 for the smaller patch)

In D40068#931679, @Typz wrote:

Generally, this indeed improves the situation (though I cannot say much about the code itself, it is still too subtle for my shallow knowledge of clang-format).

But it seems to give some strange looking result with long comments: it seems like the decision is made at each line (e.g. is it better to wrap this line or overflow a bit), so we can get a comment where each line overflows by a few characters, even if the total is worse... For exemple, say we have a 100 lines of comment, with 9 characters overflow on each line, and an excess character penalty of 30 : with this patch nothing will be re-wrapped (9*30 = 270 is less the the 300 penalty for wrapping); but the total penatly would be 900....

(btw, it seems this got merged, but the ticket does not reflect it)

klimek accepted this revision.Nov 27 2017, 2:27 AM

Self-accepting and closing, as the underlying change has landed, and this diff is incorrect now.
I also have an idea to solve the problem Typz has brought up.

klimek abandoned this revision.Nov 27 2017, 7:55 AM