This fixes the problems described in #8 by making sure we are using qualified table names everywhere in generated rust code.
Any time a table is referenced, it is qualified relative to the control it is being referenced in. For example if a table muffin lives in the control baz, which is instantiated in control bar which is instantiated in control foo. Then
The fully qualified name is foo.bar.baz.muffin.
The qualified name from foo is bar.baz.muffin.
The qualified name from bar is baz.muffin.
The qualified name from baz is `muffin.
This disambiguates tables that have the same name, or control blocks that are instantiated multiple times.
The dot-delimited names above are used for the string-based table identifiers in the Pipeline trait. For Rust code generation purposes, underscore-delimited names are used.
Follow Ups
This fix is primarily necessary because the compiler currently constructs pipeline objects such that all tables are constructed up front and passed into control blocks as parameters. This makes it straightforward to implement a control API that modifies all tables. However, it does lose some of the hierarchical structuring intrinsic to P4 programs. It's possible that generated Rust could benefit from a more hierarchical organization.
Doing table name qualification was rather awkward and feels very bolted on. Most of the complexity was shouldered by the code generation stage, which does not seem right. Seems like we're missing intermediate data structures similar to the HLIR data structures that would make code generation a more straightforward process instead of taking on the role of calculating qualified names by traversing controller chains all over the place.
Fixes #8
The Fix
This fixes the problems described in #8 by making sure we are using qualified table names everywhere in generated rust code.
Any time a table is referenced, it is qualified relative to the control it is being referenced in. For example if a table
muffin
lives in the controlbaz
, which is instantiated in controlbar
which is instantiated in controlfoo
. Thenfoo.bar.baz.muffin
.bar.baz.muffin
.bar
isbaz.muffin
.baz
is `muffin.This disambiguates tables that have the same name, or control blocks that are instantiated multiple times.
The dot-delimited names above are used for the string-based table identifiers in the
Pipeline
trait. For Rust code generation purposes, underscore-delimited names are used.Follow Ups
This fix is primarily necessary because the compiler currently constructs pipeline objects such that all tables are constructed up front and passed into control blocks as parameters. This makes it straightforward to implement a control API that modifies all tables. However, it does lose some of the hierarchical structuring intrinsic to P4 programs. It's possible that generated Rust could benefit from a more hierarchical organization.
Doing table name qualification was rather awkward and feels very bolted on. Most of the complexity was shouldered by the code generation stage, which does not seem right. Seems like we're missing intermediate data structures similar to the HLIR data structures that would make code generation a more straightforward process instead of taking on the role of calculating qualified names by traversing controller chains all over the place.