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

PUBLIC: [P4-Constraints] Fix reproducibility bug. #146

Merged
merged 1 commit into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions p4_constraints/backend/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ cc_library(
":constraint_info",
":errors",
"//gutils:collections",
"//gutils:ordered_map",
"//gutils:overload",
"//gutils:source_location",
"//gutils:status",
Expand Down
9 changes: 7 additions & 2 deletions p4_constraints/backend/symbolic_interpreter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "absl/strings/string_view.h"
#include "absl/strings/strip.h"
#include "gutils/collections.h"
#include "gutils/ordered_map.h"
#include "gutils/overload.h"
#include "gutils/source_location.h"
#include "gutils/status_builder.h"
Expand Down Expand Up @@ -690,7 +691,9 @@ absl::StatusOr<p4::v1::TableEntry> ConstraintSolver::ConcretizeEntry() {
table_entry.set_table_id(table_info_.id);

// Construct match fields by evaluating their respective entries in the model.
for (const auto& [key_name, key_info] : table_info_.keys_by_name) {
// Ordered for reproducibility.
for (const auto& [key_name, key_info] :
gutils::Ordered(table_info_.keys_by_name)) {
ASSIGN_OR_RETURN(bool key_should_be_skipped, skip_key_named_(key_name));
if (key_should_be_skipped) continue;

Expand Down Expand Up @@ -776,7 +779,9 @@ absl::StatusOr<ConstraintSolver> ConstraintSolver::Create(
// Add keys to solver and map and determine whether the table needs a
// priority.
bool requires_priority = false;
for (const auto& [key_name, key_info] : table.keys_by_name) {
// Ordered for reproducibility.
for (const auto& [key_name, key_info] :
gutils::Ordered(constraint_solver.table_info_.keys_by_name)) {
if (key_info.type.has_ternary() || key_info.type.has_optional_match()) {
// In P4Runtime, all tables with ternaries or optionals require priorities
// for their entries.
Expand Down
Loading