Skip to content

Commit

Permalink
PUBLIC: [P4-Constraints] Fix reproducibility bug. (#146)
Browse files Browse the repository at this point in the history
Use Ordered Maps in symbolic interpreter.

PiperOrigin-RevId: 640586545

Co-authored-by: PINS Team <[email protected]>
  • Loading branch information
jonathan-dilorenzo and PINS Team authored Jun 5, 2024
1 parent bf8162e commit 5712d1e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
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

0 comments on commit 5712d1e

Please sign in to comment.