Skip to content

[P4Smith] Initialize arrays using tuple expressions#5546

Open
eyg1331 wants to merge 1 commit intop4lang:mainfrom
eyg1331:p4smith-initialize-type-arrays
Open

[P4Smith] Initialize arrays using tuple expressions#5546
eyg1331 wants to merge 1 commit intop4lang:mainfrom
eyg1331:p4smith-initialize-type-arrays

Conversation

@eyg1331
Copy link
Contributor

@eyg1331 eyg1331 commented Mar 18, 2026

When P4Smith's variable declaration generator was written, P4C didn't have an initializer for arrays (then header stacks). Support has since been added for initializing arrays using tuple expressions, and this PR allows P4Smith to generate such code (instead of leaving the arrays uninitialized).

Signed-off-by: Enrico Green <Enrico.Green@amd.com>
@github-actions github-actions bot added the p4tools Topics related to the P4Tools back end label Mar 18, 2026
@kfcripps kfcripps requested a review from fruffy March 18, 2026 02:23
@eyg1331
Copy link
Contributor Author

eyg1331 commented Mar 18, 2026

Test failure seems to be some sort of compiler bug related to inlining. I'll take a closer look and open an issue once I've got a smaller reproducer.

Edit: Opened #5549

@kfcripps
Copy link
Contributor

@eyg1331 Do you happen to know how the changes in this PR caused the program you shared in #5549 to start being generated? I was expecting the reproducer to contain a header stack initialization, but I don't see that.

@eyg1331
Copy link
Contributor Author

eyg1331 commented Mar 18, 2026

@kfcripps As far as I can tell, Smith should have already been able to generate programs exhibiting this bug.

Because Smith uses a pseudorandom number generator to generate programs, small changes to how the IR is generated (in particular, the number of IR nodes generated -- this header stack initialization change causes Smith to generate new nodes for each array entry) can have a large impact on other parts of the program. Due to these perturbations, one of the seeds tested by the CI now exhibits the bug, which is why we caught it now.

The failing program does have a header stack initialization in it (otherwise the program wouldn't have changed), but it wasn't related to the bug so I removed it when minimizing the reproducer.

@kfcripps
Copy link
Contributor

@eyg1331 Makes sense, thanks for the explanation!

@kfcripps
Copy link
Contributor

kfcripps commented Mar 18, 2026

@fruffy Is there currently any mechanism for easily disabling specific seeds in the P4Smith tests? It seems that the changes in this PR are just exposing an existing bug that is not actually caused by this PR. I'm wondering if we actually need to resolve #5549 first or if there is some other way to proceed.

@fruffy
Copy link
Collaborator

fruffy commented Mar 19, 2026

Because Smith uses a pseudorandom number generator to generate programs, small changes to how the IR is generated (in particular, the number of IR nodes generated -- this header stack initialization change causes Smith to generate new nodes for each array entry) can have a large impact on other parts of the program. Due to these perturbations, one of the seeds tested by the CI now exhibits the bug, which is why we caught it now.

Yes, that it is correct. There is a mechanism to adjust the likelihood of a particular generated node using the configurations here https://github.com/p4lang/p4c/blob/main/backends/p4tools/modules/smith/common/probabilities.h

But it is a bit finnicky. Would be nice to override this per command line.

@fruffy Is there currently any mechanism for easily disabling specific seeds in the P4Smith tests? It seems that the changes in this PR are just exposing an existing bug that is not actually caused by this PR. I'm wondering if we actually need to resolve #5549 first or if there is some other way to proceed.

iirc you should be able to add a known bug here https://github.com/p4lang/p4c/blob/main/backends/p4tools/modules/smith/scripts/compilation-test.sh#L7 and it continue generating.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p4tools Topics related to the P4Tools back end

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants