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

Unifying struct and list expressions fix (#3057) #3122

Merged
merged 1 commit into from
Mar 17, 2022

Conversation

milossyrmia
Copy link
Contributor

@milossyrmia milossyrmia commented Mar 11, 2022

Unifying struct and list expressions fix (#3057)

  • I corrected the code so that the compiler bug does not occur when comparing structures of unknown type, but to report an error

  • I enabled a comparison between the structure/list expression so that the cast can be put on either side. Before this change, if the cast was on the right side of the comparison operator error was reported.

  • Added tests which verify the above

  1. In these three cases mentioned in the corresponding issue, the compiler bug was appearing. I corrected the code so that the compiler bug does not occur when comparing structures of unknown type, but to report an error.
    bool b2 = { a = 8w1, b = 8w2 } == { a = 8w1, b = 8w2 };
    bool b21 = { a = 32w1, b = 32w2 } == { a = 32w1, b = 32w2 };
    bool b3 = { a = 1, b = 2 } == {1, 2};

It is not logical that mockery is possible if we do not put a cast on one of the sides
Because what if we had two structures
struct S {
bit<32> a;
bit<32> b;
}
struct Q {
bit<32> a;
bit<32> b;
}

or in an even worse case, we do not have a single structure defined.

  1. bool b5 = (S) { a = 1, b = 2 } == { a = 1, b = 2 };
    bool b5_ = { a = 1, b = 2 } == (S) { a = 1, b = 2 };
    I enabled a comparison between the structure/list expression so that the cast can be put on either side. Before this change, if the cast was on the right side of the comparison operator error was reported.

frontends/p4/typeChecking/typeChecker.cpp Show resolved Hide resolved
@@ -0,0 +1,6 @@
issue3057-1.p4(11): [--Werror=type-error] error: ==: cannot compare initializers with unknown types
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this message isn't very good. I know you didn't change this, but perhaps you can fix it.
The message should say "cannot compare structure-valued expressions with unknown types".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I expect that you will need to change these reference files now that the error message has changed.

Copy link
Contributor

@mihaibudiu mihaibudiu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good, but I would appreciate the small changes requested.
Ideally you should have first filed an issue for the bug that you are fixing.

@milossyrmia
Copy link
Contributor Author

Hi, @mbudiu-vmw, I implemented the small changes you requested.
I was referring to an issue (#3057) and I'm not sure what kind of an issue should I file.

… and structs p4lang#3057

* I corrected the code so that the compiler bug does not occur when comparing structures of unknown type, but to report an error

* I enabled a comparison between the structure/list expression so that the cast can be put on either side. Before this change, if the cast was on the right side of the comparison operator error was reported.

* Added tests which verify the above
@milossyrmia
Copy link
Contributor Author

Hi @mbudiu-vmw, I implemented the changes you requested, but I forgot to change the output in the test, now I did it too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants