Skip to content

[llvm] format and terminate namespaces with closing comment #94917

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 21, 2024

Conversation

VoltrexKeyva
Copy link
Member

@VoltrexKeyva VoltrexKeyva commented Jun 9, 2024

Namespaces are terminated with a closing comment in the majority of the codebase so do the same here for consistency. Also format code within some namespaces to make clang-format happy.

@llvmbot llvmbot added the llvm:analysis Includes value tracking, cost tables and constant folding label Jun 9, 2024
@llvmbot
Copy link
Member

llvmbot commented Jun 9, 2024

@llvm/pr-subscribers-mlgo

@llvm/pr-subscribers-llvm-analysis

Author: Mohammed Keyvanzadeh (VoltrexKeyva)

Changes

Namespaces are terminated with a closing comment in the majority of the codebase so do the same here for consistency.


Full diff: https://github.com/llvm/llvm-project/pull/94917.diff

1 Files Affected:

  • (modified) llvm/lib/Analysis/CallGraphSCCPass.cpp (+1-1)
diff --git a/llvm/lib/Analysis/CallGraphSCCPass.cpp b/llvm/lib/Analysis/CallGraphSCCPass.cpp
index 307dddd51ece0..ccba8b3831c8f 100644
--- a/llvm/lib/Analysis/CallGraphSCCPass.cpp
+++ b/llvm/lib/Analysis/CallGraphSCCPass.cpp
@@ -46,7 +46,7 @@ using namespace llvm;
 namespace llvm {
 cl::opt<unsigned> MaxDevirtIterations("max-devirt-iterations", cl::ReallyHidden,
                                       cl::init(4));
-}
+} // namespace llvm
 
 STATISTIC(MaxSCCIterations, "Maximum CGSCCPassMgr iterations on one SCC");
 

@VoltrexKeyva VoltrexKeyva requested a review from nikic as a code owner June 9, 2024 22:13
@llvmbot llvmbot added the mlgo label Jun 9, 2024
Copy link

github-actions bot commented Jun 9, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@VoltrexKeyva
Copy link
Member Author

I don't think the formatting comment is correct here, is this a bug?

@VoltrexKeyva
Copy link
Member Author

VoltrexKeyva commented Jun 12, 2024

Can someone verify if the Clang-Format check failure is a bug?

CC @llvm/issue-subscribers-clang-format

@owenca
Copy link
Contributor

owenca commented Jun 13, 2024

This is a limitation of clang-format:

$ cat .clang-format
BasedOnStyle: LLVM
$ cat test.cpp
namespace {
  int i;
  int j;
}
$ clang-format -version
clang-format version 18.1.7
$ clang-format test.cpp | diff test.cpp -
2,4c2,4
<   int i;
<   int j;
< }
---
> int i;
> int j;
> } // namespace
$ clang-format -lines=4:4 test.cpp | diff test.cpp -
4c4
< }
---
>   } // namespace
$ 

You can work around this by fixing the indentation of the lines within the namespace in the same patch:

$ clang-format -lines=2:3 -i test.cpp
$ cat test.cpp
namespace {
int i;
int j;
}
$ clang-format -lines=4:4 test.cpp | diff test.cpp -
4c4
< }
---
> } // namespace
$ 

@VoltrexKeyva VoltrexKeyva force-pushed the add-namespace-comment branch from 0db673b to 2f88bf0 Compare June 14, 2024 22:48
Namespaces are terminated with a closing comment in the majority of
the codebase so do the same here for consistency.
@VoltrexKeyva VoltrexKeyva force-pushed the add-namespace-comment branch from 36f5d6a to 2fffc28 Compare June 14, 2024 22:52
@VoltrexKeyva
Copy link
Member Author

@owenca done.

@boomanaiden154
Copy link
Contributor

@VoltrexKeyva it seems like you pushed a bunch of changes that shouldn't have ended up in this PR?

Also, please don't force push. It doesn't really matter in this case, but it breaks the location association for comments.

@VoltrexKeyva
Copy link
Member Author

@VoltrexKeyva it seems like you pushed a bunch of changes that shouldn't have ended up in this PR?

Also, please don't force push. It doesn't really matter in this case, but it breaks the location association for comments.

All changes are intentional, the formatting changes are to make the clang-format check happy due to its limitation as pointed out in #94917 (comment)

The force push is to update the branch with the latest commits in main using rebasing as there doesn't seem to be any other viable way without creating a merge commit. I haven't force pushed the relevant changes. Shall I do something else when trying to pull the latest changes?

@boomanaiden154
Copy link
Contributor

All changes are intentional, the formatting changes are to make the clang-format check happy due to its limitation as pointed out in #94917 (comment)

Formatting changes should probably be done in a separate commit.

The force push is to update the branch with the latest commits in main using rebasing as there doesn't seem to be any other viable way without creating a merge commit. I haven't force pushed the relevant changes. Shall I do something else when trying to pull the latest changes?

You should merge main into your branch. The PR will be squashed into one commit when it gets landed.

@VoltrexKeyva
Copy link
Member Author

Formatting changes should probably be done in a separate commit.

You mean in a separate PR? Because it is in a separate commit: 2fffc28

You should merge main into your branch. The PR will be squashed into one commit when it gets landed.

Got it.

@boomanaiden154
Copy link
Contributor

You mean in a separate PR? Because it is in a separate commit: 2fffc28

Sorry, yes. Commits within an individual PR don't really matter as they will all get squashed when landing.

@owenca
Copy link
Contributor

owenca commented Jun 15, 2024

Adding namespace end comments is also a formatting change.

@boomanaiden154
Copy link
Contributor

Makes sense. Keeping it in this patch would be fine too then, but the title/description needs to be adjusted.

@VoltrexKeyva
Copy link
Member Author

Makes sense. Keeping it in this patch would be fine too then, but the title/description needs to be adjusted.

What do you suggest?

@boomanaiden154
Copy link
Contributor

What do you suggest?

Whatever is easiest for you. I think that would be reusing this PR, but either way should be fine.

@VoltrexKeyva
Copy link
Member Author

What do you suggest?

Whatever is easiest for you. I think that would be reusing this PR, but either way should be fine.

Sorry I don't follow, the title/description seems descriptive enough unless you want me to mention the formatting changes as well.

Also what do you mean by "I think that would be reusing this PR"?

@boomanaiden154
Copy link
Contributor

Sorry I don't follow, the title/description seems descriptive enough unless you want me to mention the formatting changes as well.

If you're making formatting changes too, those should be mentioned in the commit title/description.

Also what do you mean by "I think that would be reusing this PR"?

It would be easiest in my workflow to add the formatting changes to this PR. I would assume that is the case for you too, but do whatever is easiest for you.

@VoltrexKeyva
Copy link
Member Author

Oh okay, wouldn't I need to force push to update the commit message? Is that okay?

@boomanaiden154
Copy link
Contributor

Oh okay, wouldn't I need to force push to update the commit message? Is that okay?

You can just edit the PR description through the Github Web UI. The PR description is what is used for the commit description that actually lands. The messages of the individual commits don't matter other than at PR creation time.

@VoltrexKeyva VoltrexKeyva changed the title [llvm] terminate namespace with closing comment [llvm] format and terminate namespaces with closing comment Jun 21, 2024
@VoltrexKeyva
Copy link
Member Author

Done.

Copy link
Contributor

@boomanaiden154 boomanaiden154 left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

Sorry for taking up so much of your time in discussion on this. I'll try and make things more clear in the future.

@VoltrexKeyva VoltrexKeyva merged commit 7b57a1b into llvm:main Jun 21, 2024
5 of 7 checks passed
@VoltrexKeyva VoltrexKeyva deleted the add-namespace-comment branch June 21, 2024 20:21
AlexisPerry pushed a commit to llvm-project-tlp/llvm-project that referenced this pull request Jul 9, 2024
Namespaces are terminated with a closing comment in the majority of the
codebase so do the same here for consistency. Also format code within
some namespaces to make clang-format happy.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
llvm:analysis Includes value tracking, cost tables and constant folding mlgo
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants