-
Notifications
You must be signed in to change notification settings - Fork 446
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
Combo of duplication action name check and LocalizeAllActions fix #4975
Open
jafingerhut
wants to merge
62
commits into
p4lang:main
Choose a base branch
from
jafingerhut:combo-of-duplication-action-name-check-and-localizeallactions-fix
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
62 commits
Select commit
Hold shift + click to select a range
e429c8a
Add pass to give error if duplicate hierarchical names are present
jafingerhut 39538bf
Add new source files to CMakeLists.txt
jafingerhut 98940fb
Skip new checks when compiling certain source files including: + Sour…
jafingerhut a2792ce
Skip new checks for P4-14 source files in run-bmv2-test.py
jafingerhut a553fe1
Fix lint error
jafingerhut 26f0501
Fix lint problems.
jafingerhut da456fe
Do not give errors for variable declarations with identical names
jafingerhut b683571
Limit search for duplicate names to actions, tables, or "other objects"
jafingerhut ad40fe9
Update test programs that had errors in their name annotations
jafingerhut 91166c8
Update expected output files for modified test programs
jafingerhut 9acb7e0
Move new test program with error into p4_16_errors directory
jafingerhut b133b28
Add expected output files for new test programs
jafingerhut 76bf24f
More fine-tuning to enable tests to pass
jafingerhut f7ec2fe
Fix lint error
jafingerhut 1cc8224
Fix lint error
jafingerhut 4b03eb5
Merge branch 'master' into add-duplicate-hierarchical-name-check-pass
jafingerhut 93daba5
Address some review comments
jafingerhut 66a0a0a
Rewording documentation of new pass for clarity.
jafingerhut 083db34
Merge remote-tracking branch 'upstream/main' into add-duplicate-hiera…
jafingerhut 99beb30
Enable the new pass only if P4Runtime control plane API gen is enabled
jafingerhut 2b7c58a
Merge branch 'add-duplicate-hierarchical-name-check-pass' of github.c…
jafingerhut 54007df
Merge remote-tracking branch 'upstream/main' into add-duplicate-hiera…
jafingerhut d89f214
Undo changes to Python test scripts
jafingerhut 7424db3
Undo changes to gtestp4c source
jafingerhut 55ad18f
Merge remote-tracking branch 'upstream/main' into add-duplicate-hiera…
jafingerhut 799448a
Use abseil StrCat and StrAppend instead of loop
jafingerhut 377f41a
Fix formatting with clang-format
jafingerhut 682564b
Fix #4969 by modifying pass LocalizeActions
jafingerhut bb88b7d
Fix clang-format error
jafingerhut d265e1c
Also catch duplicates involving top-level actions without @name annot…
jafingerhut 606300e
Merge remote-tracking branch 'upstream/main' into add-duplicate-hiera…
jafingerhut 6bcb614
Add new test program to exercise latest code changes
jafingerhut 55da2c3
Change pass name to reflect only checking action control plane names
jafingerhut d67df83
Fix lint warning, and add one more successful test program
jafingerhut 42c1dee
Merge remote-tracking branch 'origin/fix-localizeallactions-bug' into…
jafingerhut 95dc4e2
A few more fixes and test cases for duplicate action name checks
jafingerhut efd0d52
Fix code formatting to pass lint check
jafingerhut 4540f2a
Fix lint warning for Python code
jafingerhut 39a9251
Update old file name in CMakeLists.txt
jafingerhut 62fe180
Merge remote-tracking branch 'upstream/main' into combo-of-duplicatio…
jafingerhut b614ff9
Add another case of conflicting action names between control and sub-…
jafingerhut 968af1f
Merge remote-tracking branch 'upstream/main' into combo-of-duplicatio…
jafingerhut a2e913b
Add another correct case of not-conflicting @name annotations involvi…
jafingerhut 72827dd
Fix comment, and remove unnecessary comment in P4 test program
jafingerhut b9a0ee9
Merge remote-tracking branch 'upstream/main' into combo-of-duplicatio…
jafingerhut 019f3c6
Merge remote-tracking branch 'upstream/main' into combo-of-duplicatio…
jafingerhut bb50cc6
Put method controlPlaneAPIGenEnabled in class CompilerOptions
jafingerhut a840163
Fixes for incorrect previous commit.
jafingerhut 19956fc
Fix cpplint warning from clang-format
jafingerhut e563b90
Merge remote-tracking branch 'upstream/main' into combo-of-duplicatio…
jafingerhut 62ee2c1
Updates due to recent changes in annotation APIs
jafingerhut c3feb19
More modifications required to make the code work with ...
jafingerhut 31f0b10
Simplify string manipulation code using latest abseil changes
jafingerhut bd31e6b
Fix clang-format warning
jafingerhut a853313
Merge branch 'master' into combo-of-duplication-action-name-check-and…
jafingerhut c111ab1
Updates required to work with recent changes to annotation implementa…
jafingerhut b542540
Address review comments
jafingerhut beb87b0
Removed an old line of commented-out code.
jafingerhut 87feba6
Reword some comments for clarity.
jafingerhut e586849
Fix lint warning
jafingerhut 381ec48
Address review comment
jafingerhut 2f861cf
Merge remote-tracking branch 'upstream/main' into combo-of-duplicatio…
jafingerhut File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
Copyright 2024 Cisco Systems, Inc. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
#include "duplicateActionControlPlaneNameCheck.h" | ||
|
||
#include "lib/log.h" | ||
|
||
namespace P4 { | ||
|
||
cstring DuplicateActionControlPlaneNameCheck::getName(const IR::IDeclaration *decl) { | ||
return decl->getName(); | ||
} | ||
|
||
void DuplicateActionControlPlaneNameCheck::checkForDuplicateName(cstring name, | ||
const IR::Node *node) { | ||
auto *otherNode = node; | ||
auto [it, inserted] = actions.emplace(name, node); | ||
if (!inserted) { | ||
otherNode = it->second; | ||
error(ErrorType::ERR_DUPLICATE, "%1%: conflicting control plane name: %2%", node, | ||
otherNode); | ||
} | ||
} | ||
|
||
const IR::Node *DuplicateActionControlPlaneNameCheck::postorder(IR::P4Action *action) { | ||
bool topLevel = stack.empty(); | ||
auto nameAnno = action->getAnnotation(IR::Annotation::nameAnnotation); | ||
if (!nameAnno && topLevel) { | ||
// Actions declared at the top level that the developer did not | ||
// write a @name annotation for it, should be included in the | ||
// duplicate name check. They do not yet have a @name annotation | ||
// by the time this pass executes, so this case will handle | ||
// such actions. | ||
// | ||
// name is what this top-level action's @name annotation | ||
// will be, after LocalizeAllActions pass adds one. | ||
cstring name = absl::StrCat(".", action->name); | ||
checkForDuplicateName(name, action); | ||
} else { | ||
const auto *e0 = nameAnno->getExpr(0); | ||
cstring name = e0->to<IR::StringLiteral>()->value; | ||
if (!name.startsWith(".")) { | ||
// Create an absolute hierarchical name (one beginning | ||
// with a "."), so we can compare it against any other | ||
// @name annotation value that begins with "." and is | ||
// equal. | ||
if (topLevel) { | ||
name = absl::StrCat(".", name); | ||
} else { | ||
name = absl::StrCat(".", absl::StrJoin(stack, "."), ".", name); | ||
} | ||
} | ||
checkForDuplicateName(name, action); | ||
} | ||
return action; | ||
} | ||
|
||
} // namespace P4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
Copyright 2024 Cisco Systems, Inc. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
#ifndef FRONTENDS_P4_DUPLICATEACTIONCONTROLPLANENAMECHECK_H_ | ||
#define FRONTENDS_P4_DUPLICATEACTIONCONTROLPLANENAMECHECK_H_ | ||
|
||
#include <vector> | ||
|
||
#include "ir/ir.h" | ||
#include "ir/visitor.h" | ||
Comment on lines
+22
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added in commit 57 |
||
|
||
namespace P4 { | ||
|
||
/** | ||
* This pass does not change anything in the IR. It only gives an | ||
* error if it finds two actions with the same hierarchical name. I | ||
* am not certain, but it might be that at this point in the front | ||
* end, the only way such a duplicate can happen is due to @name | ||
* annotations. @name annotations are definitely taken into account | ||
* in this duplicate check. | ||
* | ||
* See also the pass HierarchicalNames, on which the implementation of | ||
* this pass was based. | ||
* | ||
* This pass should be run before pass LocalizeAllActions, because | ||
* LocalizeAllActions can create actions with duplicate names, by | ||
* design, that were not created by the P4 developer. We should not | ||
* issue an error if that pass creates duplicate hierarchical names. | ||
*/ | ||
class DuplicateActionControlPlaneNameCheck : public Transform { | ||
std::vector<cstring> stack; | ||
/// Used for detection of conflicting control plane names among actions. | ||
absl::flat_hash_map<cstring, const IR::Node *> actions; | ||
|
||
public: | ||
cstring getName(const IR::IDeclaration *decl); | ||
|
||
DuplicateActionControlPlaneNameCheck() { | ||
setName("DuplicateActionControlPlaneNameCheck"); | ||
visitDagOnce = false; | ||
} | ||
const IR::Node *preorder(IR::P4Parser *parser) override { | ||
// There cannot be any action definitions inside a parser, so | ||
// do not traverse through its nodes. | ||
prune(); | ||
return parser; | ||
} | ||
|
||
const IR::Node *preorder(IR::P4Control *control) override { | ||
stack.push_back(getName(control)); | ||
return control; | ||
} | ||
const IR::Node *postorder(IR::P4Control *control) override { | ||
stack.pop_back(); | ||
return control; | ||
} | ||
kfcripps marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const IR::Node *preorder(IR::P4Table *table) override { | ||
// There cannot be any action definitions inside a table, so | ||
// do not traverse through its nodes. | ||
prune(); | ||
return table; | ||
} | ||
|
||
void checkForDuplicateName(cstring name, const IR::Node *node); | ||
|
||
const IR::Node *postorder(IR::P4Action *action) override; | ||
}; | ||
|
||
} // namespace P4 | ||
|
||
#endif /* FRONTENDS_P4_DUPLICATEACTIONCONTROLPLANENAMECHECK_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@asl @oleg-ran-amd I think that
DuplicateActionControlPlaneNameCheck
should run for our backend even when P4Info files are not generated. So we should probably override this function to unconditionally returntrue
.