Skip to content
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

Implement Consistent Commenting Style in backend #4568

Closed
wants to merge 4 commits into from

Conversation

sumit7754
Copy link
Contributor

Fixes #4567

This pull request addresses the issue #4567, which discusses the need for a consistent commenting style in the core parts of the compiler. Following the discussions in the issue, I have made the following changes:

Used triple slashes (///) for commenting functions and classes.
Used double slashes (//) for comments within the code.

@sumit7754 sumit7754 changed the title Update readme Implement Consistent Commenting Style in backend Mar 27, 2024
@fruffy fruffy added the documentation Topics related to compiler documentation. label Mar 27, 2024
Copy link
Collaborator

@fruffy fruffy left a comment

Choose a reason for hiding this comment

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

Thank you for your effort, this is a great start! Some initial comments.

/// @param max_length maximum length for a header with varbit fields;
/// if 0 header does not contain varbit fields
/// @param fields a JsonArray for the fields in the header

Copy link
Collaborator

Choose a reason for hiding this comment

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

You added an additional space here between the comment and the C++ code. Please remove it for all instances.

@@ -166,7 +165,7 @@ bool CFG::checkImplementable() const {
namespace {
class CFGBuilder : public Inspector {
CFG *cfg;
/// predecessors of current CFG node
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is not correct. Members in header files also will have triple slashes. We only use double slashes for "internal" comments within functions, for example.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please fix this for all instances.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

/// Create a header type in json.
/// @param name header name
/// @param type header type
/// @param max_length maximum length for a header with varbit fields;
/// if 0 header does not contain varbit fields
/// @param fields a JsonArray for the fields in the header

Are you referring to a gap in these comments?

Copy link
Collaborator

Choose a reason for hiding this comment

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

You can format Github comments using triple '`', it will make your comment more readable: https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks

Yes, in all the comments where there is a newline between the comments and the actual function.

@@ -213,4 +212,4 @@ void ActionConverter::postorder(const IR::P4Action *action) {
ctxt->structure->ids.emplace(action, id);
}

} // namespace BMV2
Copy link
Contributor Author

Choose a reason for hiding this comment

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

for the namespace should I use /// or // ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

They are internal, use two slashes here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually, another helpful contribution is to write this all down. Very good to have! We should have done this much earlier.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure we can do this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you elaborate more then that will be helpful

Copy link
Collaborator

Choose a reason for hiding this comment

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

Basically, all these details we have discussed (comment style for namespaces, triple slashes vs star comments, newlines before functions) should be written down in text. This way we can refer to our "style document" whenever these questions come up.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

/**
* Convert an expression into JSON
* @param e expression to convert
* @param doFixup Insert masking operations for operands to ensure that the result
* matches the specification. BMv2 does arithmetic using unbounded
* precision, but the spec requires fixed precision, specified by the types.
* @param wrap Wrap the result into an additiona JSON expression block.
* See the BMv2 JSON spec.
* @param convertBool Wrap the result into a cast from boolean to data (b2d JSON).
*/ For this type of comments, what kind of formatting should we use?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Triple slashes.

@AdarshRawat1 AdarshRawat1 mentioned this pull request Mar 28, 2024
2 tasks
@fruffy
Copy link
Collaborator

fruffy commented Apr 2, 2024

Closing this in favor of smaller pull requests per back end folder. Like #4586.

@fruffy fruffy closed this Apr 2, 2024
@sumit7754 sumit7754 deleted the update-readme branch April 7, 2024 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Topics related to compiler documentation.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Format Comments Consistently in P4C.
2 participants