p4-spec icon indicating copy to clipboard operation
p4-spec copied to clipboard

Support for `typeof` keyword

Open mihaibudiu opened this issue 3 years ago • 4 comments

Personnel

  • [x] Owner: @mbudiu
  • [x] Supporters: @vgurevich

Design

  • [x] Document: this PR

Implementation

  • [x] p4-spec: this PR
  • [x] p4c: https://github.com/p4lang/p4c/pull/3017

Process

  • [ ] LDWG discussed:
  • [ ] LDWG approved:
  • [ ] Merged into p4-spec:
  • [ ] Merged into p4c:

mihaibudiu avatar Jan 13 '22 02:01 mihaibudiu

This would be only really useful in conjunction with #1011. If #1011 is not accepted, a different design should be used for this feature. The reason is that typedef declarations being global confines the use of typeof only for constant expressions, and P4 currently does not have constant expressions of some types, such as header stacks.

mihaibudiu avatar Jan 13 '22 02:01 mihaibudiu

We discussed this feature at the April '22 LDWG meeting.

  • Folks should try this feature out, as well as #1011 and come with feedback for the May meeting.
  • @mbudiu-vmw will also prototype a version that allows typeof anywhere a type can be indicated... if Bison allows it.

jnfoster avatar Apr 04 '22 21:04 jnfoster

@vgurevich especially, please take a look!

jnfoster avatar Apr 04 '22 21:04 jnfoster

@jnfoster -- noted. I'll try to refactor some programs and at least compile them with p4-test backend.

vgurevich avatar Apr 13 '22 12:04 vgurevich