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

'int' type #331

Closed
ChrisDodd opened this issue Jun 27, 2017 · 7 comments
Closed

'int' type #331

ChrisDodd opened this issue Jun 27, 2017 · 7 comments
Labels

Comments

@ChrisDodd
Copy link
Contributor

Section 7.1.6.5 talks about the type int

7.1.6.5. Infinite-precision integers

The infinite-precision data type describes integers with an unlimited precision. This type is written as int.

This type is reserved for integer literals and expressions that involve only literals. No P4 runtime value > can have an int type; at compile time the compiler will convert all int values that have a runtime > component to fixed-width types, according to the rules described below.

However, the grammar in the appendix does not recognize int as a type (only int< integer >). P4_14 (v1.1) used int in declarations of extern functions where the argument needed to be a constant and had no particular bitsize. Should something similar be allowed in P4_16? What exactly does it mean -- an argument that must be a compile time constant (generally a literal or expression involving only literals?)

@jnfoster
Copy link
Collaborator

@mbudiu-vmw should weigh in, but I believe this is intentional. int is not a type the programmer can write down, just an internal type used by the compiler. If that understanding is correct, the text should be tweaked to clarify.

We define compile-time known values precisely at the start of Section 16. Would it help to add a link or would that just add clutter?

@ChrisDodd
Copy link
Contributor Author

In that case, we should probably remove "This type is written as int", as that suggests int can be used to denote the type. Its not clear what, if any, connection there is to section 16 compile-time known values.

@ChrisDodd
Copy link
Contributor Author

The place this comes up is things the 'index' arguments to counter/meter methods. In v1model.p4, these are generally defined as bit<32>, which generally means that the user needs to explicitly cast the argument they use to bit<32> if it is of some other type (which it often is if it comes from an action parameter). It would be nice if there was a way to define an extern that "just worked" without the need for extra casts and type specifiers.

@tomrodeheffer
Copy link

And then there are constant declarations.

A constant declaration does not construct a P4 runtime value, but rather a P4 compile time value. So there is no reason why you should not be able to write a constant declaration of type int, for example:

const int threshold = 150 + (6 / 2);

which would then permit the programmer to use threshold everywhere in the P4 program where formerly there occurred the magic constant 153.

Except that the grammar does not permit it, since you cannot actually write int for a baseType.

@jnfoster
Copy link
Collaborator

jnfoster commented Jun 27, 2017 via email

@mihaibudiu
Copy link
Contributor

Internally the compiler uses InfInt for this type. The problem is that bit is an abbreviation of bit<1>, but int is not an abbreviation of int<1>.

We can add int to the grammar; it would make sense indeed for writing some constant values, as @tomrodeheffer proposes, and also for constructor argument types. But it is not clear that the value provided is worthwhile.

@jnfoster
Copy link
Collaborator

@mbudiu-vmw proposes that we change the name of this type due to the confusing asymmetry with int types.

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

No branches or pull requests

4 participants