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

Add minWidthBits for Type_Error #2967

Merged
merged 3 commits into from
Dec 2, 2021
Merged

Conversation

usha1830
Copy link
Contributor

No description provided.

@mihaibudiu
Copy link
Contributor

mihaibudiu commented Nov 29, 2021

I am afraid this does not conform to the spec

@usha1830
Copy link
Contributor Author

I am afraid this does not conform to the spec

If we do not handle Type_Error here, it leads to an error "width not well-defined" while generating P4Info in certain cases.
Any suggestion on how we can fix this? Should we avoid calling this function minWidthBits() when the type is Type_Error?

@mihaibudiu
Copy link
Contributor

That is my point, I belive that the spec days that it is an error to call this function on values of type error.

@mihaibudiu
Copy link
Contributor

Why does the compiler call width on an error type?

@usha1830
Copy link
Contributor Author

usha1830 commented Dec 1, 2021

Why does the compiler call width on an error type?

In P4info, each table match key has a field for bitwidth. When an error type variable is used as match key field of a table, this function is called.

table parser_error {
    key = {
        istd.parser_error : exact;
    }
   // rest of the table properties
}

P4info:

match_fields {              
     id: 1                     
     name: "istd.parser_error" 
     bitwidth : 0
     match_type: EXACT         
   }   

From the P4Runtime spec (section 8.5.5),
"For enum types with no underlying type — as well as error — there is no integer value associated with each symbolic member entry (whether assigned automatically by the compiler or directly in the P4 source). We therefore use a human-readable string in P4Data to represent enum and error values."

As an error type does not have any underlying bitwidth (which is what the error is), I think we can treat the error type as a string.

@mihaibudiu mihaibudiu merged commit b958226 into p4lang:main Dec 2, 2021
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