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

Enhancement: Make p4c-bm2-ss's bmv2 JSON config file output consistent across runs #667

Closed
jafingerhut opened this issue May 25, 2017 · 11 comments
Assignees
Labels
enhancement This topic discusses an improvement to existing compiler code.

Comments

@jafingerhut
Copy link
Contributor

Maybe it is something strange in my environment (and if so I would like to change it), but when I run p4c-bm2-ss repeatedly on the same P4-16 program, I get bmv2 JSON config file output that varies, usually in the id's assigned to things, and thus often the order they occur in that file.

This is not incorrect, I understand. That is why this issue title starts with "Enhancement", not "Bug".

However, it seems like it should be straightforward to change this to a consistent order across runs, at least for the same version of the compiler source code and the same P4-16 source program.

Why am I asking? Because sometimes it is useful to 'diff' two bmv2 JSON config files after making a small compiler change, and this would be far more useful and quick if the order of objects in that file was more consistent.

@jafingerhut
Copy link
Contributor Author

At least with Python's default implementation, I know that dict's use a hash function with some kind of randomization in it. This can be disabled with a command line option, or you can write code to sort the keys whenever printing the contents of a dict. I wonder whether something like that is happening here, too.

@ChrisDodd
Copy link
Contributor

ChrisDodd commented May 25, 2017 via email

@jafingerhut
Copy link
Contributor Author

@ChrisDodd Do you see different bmv2 JSON file for any medium-sized P4-16 program across multiple runs? I can put an example program and commands I used here with my results if others do not see this behavior.

@jafingerhut
Copy link
Contributor Author

Example command:

p4c-bm2-ss issue298-bmv2.p4 -o tmp1.json

where the program is this one: https://github.com/p4lang/p4c/blob/master/testdata/p4_16_samples/issue298-bmv2.p4

I run that 5 times with 5 different JSON output file names. 3 of the files are the same. I get 3 different unique output files out of those 5.

It happens less often with smaller programs, so is probably related to the number of some kind of language construct in the programs.

@mihaibudiu
Copy link
Contributor

@hanw : can we assign you this issue, since you seem to have taken ownership of the bmv2 back-end?
As @ChrisDodd says, it is most likely this can be fixed by replacing a set or map with the ordered equivalent. This is only important when you iterate over the object.

@hanw
Copy link
Contributor

hanw commented May 25, 2017

Yes. Please assign the issue to me.

@mihaibudiu mihaibudiu added the enhancement This topic discusses an improvement to existing compiler code. label May 25, 2017
@sethfowler
Copy link
Contributor

See #406.

@mihaibudiu
Copy link
Contributor

Yes, but in this case it may be that this is a set of JSON objects.

hanw pushed a commit to hanw/p4c that referenced this issue May 25, 2017
@hanw
Copy link
Contributor

hanw commented May 26, 2017

Fixed with #669

@sethfowler
Copy link
Contributor

It turns out that the patch in #406 would indeed have caught this.

hanw added a commit that referenced this issue May 26, 2017
@jafingerhut
Copy link
Contributor Author

@hanw Thanks! I've tried out your change on several different programs, and it appears to have nailed it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This topic discusses an improvement to existing compiler code.
Projects
None yet
Development

No branches or pull requests

5 participants