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

Type constraints for right-hand operand of shift operators #1158

Open
blp opened this issue Jul 18, 2022 · 3 comments
Open

Type constraints for right-hand operand of shift operators #1158

blp opened this issue Jul 18, 2022 · 3 comments

Comments

@blp
Copy link
Contributor

blp commented Jul 18, 2022

The following program:

input relation X(x: bit<16>, y: bit<16>)
output relation Y(x: bit<16>, y: bit<16>, z: bit<16>)
Y(x, y, x << y) :- X(x, y).

yields the following compiler error that I don't expect (with release v1.2.3 and earlier releases):

error: /home/blp/nerpa/nerpa/ofp4/test.dl:3.6-3.7: Unsatisfiable bit-width constraint '16 = 0' in
expected type: bit<16>
actual type: bit<32>
in
expression 'y'
Y(x, y, x << y) :- X(x, y).
     ^

I can fix it by casting y to u32 in the shift expression, like this:

Y(x, y, x << (y as u32)) :- X(x, y).

I would prefer that << (and presumably >>) accept any integer type as its right-hand operand.

@mihaibudiu
Copy link

Probably any unsigned integer type only could work. Signed values introduce additional complications.

@blp
Copy link
Contributor Author

blp commented Jul 18, 2022

That's reasonable.

@blp
Copy link
Contributor Author

blp commented Jul 19, 2022

If #1159 gets merged, and this bug gets fixed, then the documentation added by the PR should be updated as well.

ryzhyk pushed a commit that referenced this issue Jul 19, 2022
This documents the current requirement that the right-hand operand of
<< and >> have type bit<32>.  I tend to consider that a bug (see
#1158), so I
hope that it will be relaxed in the future (and the documentation
updated).

Signed-off-by: Ben Pfaff <[email protected]>
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

No branches or pull requests

2 participants