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

Doxygen comments #614

Merged
merged 15 commits into from
May 11, 2017
Merged

Doxygen comments #614

merged 15 commits into from
May 11, 2017

Conversation

hanw
Copy link
Contributor

@hanw hanw commented May 11, 2017

Comment improvements for these four passes:

  • simplifySelectCases
  • simplifyKey
  • removeLeftSlices
  • removeActionParameters

Copy link
Contributor

@jnfoster jnfoster left a comment

Choose a reason for hiding this comment

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

Overall, looks great. Just some minor typesetting and phrasing suggestions.

Also, it'd be nice to have @pre/@post conditions for the passes.

/**
* This pass removes Slices on the lhs of an assignment
*
* a[m:l] = e; -> a = (a & ~mask) | (((cast)e << l) & mask);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice! The example illustrates this transformation perfectly.

Copy link
Contributor

Choose a reason for hiding this comment

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

Will this be typeset as code in Doxygen?


/**
* This is needed because of this case:
* action a(inout x) { x = x + 1 }
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this be typeset as code in Doxygen?

/**
* For each action that is invoked keep the list of arguments that
* it's called with. There must be only one call of each action;
* this is done by LocalizeActions.
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be nice to use @pre and @post

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

/**
Removes parameters of an action which are in/inout/out.

control c(inout bit<32> x) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Doxygen formatting for code?

// Policy which returns 'true' whenever a key is not a left value
// or a call to the isValid().
/**
* Policy which returns 'true' whenever a key is not a left value
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of saying "returns" how about a different verb? For example "Policy that tracks whether a key is..."

@@ -42,7 +46,9 @@ class NonLeftValue : public KeyIsComplex {
bool isTooComplex(const IR::Expression* expression) const;
Copy link
Contributor

Choose a reason for hiding this comment

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

How does "too complex" related to l-value-ness?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The pass applies to non-lvalue expressions. All lvalues are considered not complex and therefore not transformed.

@@ -42,7 +46,9 @@ class NonLeftValue : public KeyIsComplex {
bool isTooComplex(const IR::Expression* expression) const;
};

// Policy that allows masked lvalues as well as simple lvalues or isValid()
/**
* Policy that allows masked lvalues as well as simple lvalues or isValid()
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, reword as something like "Policy that tracks whether an lvalue is masked, simple, ..."

// If some of the fields of a table key are "too complex",
// turn them into simpler expressions.
/**
* If some of the fields of a table key are "too complex",
Copy link
Contributor

Choose a reason for hiding this comment

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

"Transforms complex table keys into..."

@@ -86,7 +116,9 @@ class DoSimplifyKey : public Transform {
const IR::Node* postorder(IR::P4Table* table) override;
};

// Use a policy to decide when a key expression is too complex.
/**
* This pass uses a policy to decide when a key expression is too complex.
Copy link
Contributor

Choose a reason for hiding this comment

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

"Determine whether a key expression is too complex"

Also, "too complex" should be defined above.

/**
* This is needed because of this case:
*
* \code{.cpp}
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment is in the wrong place, it was explaining why MoveDeclarations is required. This is not what this pass is doing. The comment for the pass is in the header file. This is a code comment.

@@ -45,10 +48,10 @@ class ActionInvocation {
}
void bindDefaultAction(const IR::P4Action* action,
const IR::MethodCallExpression* defaultInvocation) {
// We must have a binding for this action already.
/// We must have a binding for this action already.
Copy link
Contributor

Choose a reason for hiding this comment

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

These should not be Doxygen comments, they are commenting code, not APIs.

// table t() { actions = { a; } }
// apply { ... } }
/**
Removes parameters of an action which are in/inout/out.
Copy link
Contributor

Choose a reason for hiding this comment

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

Your commenting style is inconsistent, sometimes you use a star, sometimes you just indent, and sometimes you don't indent.

const IR::Node* postorder(IR::ActionListElement* element) override;
/// Remove arguments from method call
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that these comments are unnecessary.
Moreover, this only does this for method calls that are calling actions, to the comment is inaccurate.

// Policy used to decide whether a key expression is too complex.
/**
* Policy used to decide whether a key expression is too complex.
*/
class KeyIsComplex {
public:
virtual ~KeyIsComplex() {}
virtual bool isTooComplex(const IR::Expression* expression) const = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

The isTooComplex function requires a comment.

@@ -86,7 +120,13 @@ class DoSimplifyKey : public Transform {
const IR::Node* postorder(IR::P4Table* table) override;
};

// Use a policy to decide when a key expression is too complex.
/**
Copy link
Contributor

Choose a reason for hiding this comment

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

This is incorrect, this pass actually simplifies the keys, it does not determine anything.
You deleted the original comment, which indicated what the policy parameter is about; that should become a @param comment.

* If requireConstants is true this pass requires that
* all select labels evaluate to constants.
*
* @pre None
Copy link
Contributor

Choose a reason for hiding this comment

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

Well, at least the typeMap must be correct. But maybe that is implied.
This pass assumes that there are no side-effects in the evaluation of select labels, something which is not yet enforced by the compiler or the spec.

@@ -36,7 +41,7 @@ class ValidateTableProperties : public Inspector {
legalProperties.emplace(l);
}
void postorder(const IR::Property* property) override;
/* don't check properties in externs (Declaration_Instances) */
/// don't check properties in externs (Declaration_Instances)
Copy link
Contributor

Choose a reason for hiding this comment

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

This should probably not be a Doxygen comment.

* Checks to see if there are any unknown properties.
*
* @pre none
* @post no invalid table properties in P4 program.
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually the properties are not removed, but an error is given if such properties are found.

*
* Any non-lvalues, except built-in method invocation (isValid),
* are considered complex expressions.
* This pass considers any non-lvalues, except built-in method invocation (isValid),
Copy link
Contributor

Choose a reason for hiding this comment

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

This is incorrect, whether a key is complex or not is determined by the policy.
This pass does not know whether non l-values are complex or not.

*
* @param policy Use 'policy' to determine whether a key expression is too complex.
* This pass uses 'policy' to determine whether a key expression is too complex.
* Policies are defined in 'NonLeftValue' and 'NonMaskLeftValue', which consider
Copy link
Contributor

Choose a reason for hiding this comment

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

This pass should not list all possible policies; we can't be updating this comment every time we write a new policy.
Each policy has its own comments. This pass also simplifies keys which are complex according to the policy.

* Policies are defined in 'NonLeftValue' and 'NonMaskLeftValue', which consider
* any non-lvalue, except built-in method (isValid) in table key expressions
* as complex expressions.
* and simplifies keys which are complex according to the policy.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you also need to remove the do after 'complex'

@hanw hanw merged commit 58b7136 into p4lang:master May 11, 2017
@hanw hanw deleted the code-review branch May 11, 2017 22:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants