This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Teach clang-format how to handle C++ coroutines
Needs ReviewPublic

Authored by EricWF on Jun 14 2017, 4:42 PM.

Details

Reviewers
djasper
Summary

This patch (1) enable parsing for coroutines by default and (2) teaches clang-format how to properly handle them.

Currently clang-format absolutely mangles any coroutine code. For example:

for co_await (auto x : range()) { ... } // before formatting

// after formatting
for
  co_await(auto x
                 : range() { ... }

This is unacceptable and I would like to fix it before more people begin using coroutines.

Diff Detail

Event Timeline

EricWF created this revision.Jun 14 2017, 4:42 PM
EricWF edited the summary of this revision. (Show Details)Jun 16 2017, 4:54 PM
EricWF added inline comments.Jun 17 2017, 4:20 AM
lib/Format/UnwrappedLineParser.cpp
433

This change is accidental.

alexfh removed a reviewer: alexfh.Jul 11 2017, 6:33 AM
alexfh removed reviewers: mprobst, thakis, klimek.
alexfh added a subscriber: alexfh.Jul 11 2017, 6:35 AM

Leaving only the most likely reviewers for this code.

This looks good overall, btw. But please wait for Krasimir or Daniel, since they actually know this code ;]

krasimir edited edge metadata.Jul 11 2017, 7:56 AM

Looks good to me too, but I actually don't know this code. Leaving to Daniel!

krasimir added a subscriber: krasimir.
djasper added inline comments.Jul 11 2017, 8:13 AM
lib/Format/Format.cpp
1958

Can we change this only if Style.isCpp()? We should probably do that for other things, too, but as we are adding more keywords here, lets not do that for Java/JS/Proto.

lib/Format/TokenAnnotator.cpp
612
if (Style.isCpp() && CurrentToken && ..) 
  next();
2254

Shouldn't this respect Style.SpaceBeforeParens?

2306

I know that the split between spaceRrequiredBefore and spaceRequiredBetween is generally bad. However, here you seem to be testing the exact same thing that is then retested in spaceRequiredBetween. I'd prefer the logic to be in one place only. Which tests break if you remove the changes to spaceRequiredBetween?

2309

Is this tested? Similar for all the other branches?

lib/Format/UnwrappedLineParser.cpp
433

What does that mean? Remove it?

EricWF marked an inline comment as done.Jul 11 2017, 7:04 PM

@alexfh Thanks for correcting the reviewers. I had no idea who to add so I used something like git-suggest-reviewers.

lib/Format/Format.cpp
1958

SGTM. I'll make the change.

lib/Format/TokenAnnotator.cpp
612

The Style.isCpp() should be unneeded now that the Coroutines TS keywords only parse when the style is Cpp.

2306

Which tests break if you remove the changes to spaceRequiredBetween?

Not sure I have a test, I was probably mistaken adding this.

@djasper Assuming only one set of changes is needed, would they be better in spaceRequiredBetween or spaceRequiredBefore?

lib/Format/UnwrappedLineParser.cpp
433

Sorry, I meant to remove it, I just couldn't when I left the comment as a reminder.

EricWF updated this revision to Diff 106135.Jul 11 2017, 7:05 PM
EricWF marked an inline comment as done.
  • Address most review comments except those about spaceBreakBetween and spaceBreakBefore.
djasper added inline comments.Jul 11 2017, 10:10 PM
lib/Format/TokenAnnotator.cpp
2306

I don't know that I have a good answer to that. But I'd leave it here in the C++ language specific part.

MyDeveloperDay added projects: Restricted Project, Restricted Project.