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

extern with different type parameter but the same name? #1585

Open
hanw opened this issue Oct 30, 2018 · 11 comments
Open

extern with different type parameter but the same name? #1585

hanw opened this issue Oct 30, 2018 · 11 comments
Labels
enhancement This topic discusses an improvement to existing compiler code.

Comments

@hanw
Copy link
Contributor

hanw commented Oct 30, 2018

As shown below, is it possible to support externs with different type parameter, but the same name?

meter-extern.p4.txt

Currently frontend returns the following error message.

bug.p4(20):syntax error, unexpected {
extern Meter<I, SE> {
                    ^
error: 1 errors encountered, aborting compilation
@hanw
Copy link
Contributor Author

hanw commented Oct 30, 2018

I guess a related question would be is it possible to specify a default type parameter?

@hanw
Copy link
Contributor Author

hanw commented Oct 30, 2018

Something along this line would be ideal

enum bit<8> MeterColor_t {
   GREEN = 8w0, YELLOW = 8w1, RED = 8w3
}

enum bit<8> CustomMeterColor_t {
   GREEN = 8w0, YELLOW = 8w127, RED = 8w255
}

extern Meter<I, SE=MeterColor_t> {
  Meter();
  SE execute(in I index);
}
control IngressMirror() {
  Meter<bit<1>>() default_meter;
  Meter<bit<1>, CustomMeterColor_t> custom_meter;
  action run_default_meter () {
    MeterColor_t color;
    color = default_meter.execute(0);
  }
  action run_custom_meter() {
     CustomMeterColor_t color;
     color = customer_meter.execute(0);
  }
  table t {
    actions = { NoAction; }
    size = 1024;
  }
  apply { t.apply(); }
}

@mihaibudiu
Copy link
Contributor

the language as it is now does not allow for overloading of types, or for default type arguments.

@hanw
Copy link
Contributor Author

hanw commented Oct 30, 2018

A default type argument would be a very helpful feature for one of our use cases. It can be used to describe an extern that normally returns a system-defined SerEnum type, and can be customized to return a user-defined SerEnum type. As shown in the above example. It helps to evolve architecture without breaking backward compatibility.

@mihaibudiu
Copy link
Contributor

You should bring it to the language design working group.
Of course, we could try to prototype the feature before that too...

For the user there will be no visible change, but the back-end will have to change to handle both these types.

@hanw
Copy link
Contributor Author

hanw commented Oct 30, 2018

Sure. I can bring this up in the language design group. Do you have cycle to prototype the feature?

@mihaibudiu
Copy link
Contributor

I never have enough cycles; the question is what is most important to implement. There are still too many bugs to fix, I tend to prioritize these. If this is very important we can push it up.

@hanw
Copy link
Contributor Author

hanw commented Oct 31, 2018

It would be great if you could give it a higher priority. Thank you!

@mihaibudiu
Copy link
Contributor

I will start as soon as you remove the ugly macros from the bmv2 back-end.

@mihaibudiu mihaibudiu added the enhancement This topic discusses an improvement to existing compiler code. label Nov 2, 2018
@hanw
Copy link
Contributor Author

hanw commented Nov 5, 2018

A write-up on the issue in case we need to discuss the issue today in the language design meeting.
https://docs.google.com/document/d/18tFPVQjUqNoYFq6-CvShyvL_uoy6kwlHM7fVyN_rV6Y/edit?usp=sharing

@hanw
Copy link
Contributor Author

hanw commented Jan 7, 2019

An example PSA program in p4lang/p4c today.
https://github.com/p4lang/p4c/blob/master/testdata/p4_16_samples/psa-fwd-bmv2.p4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This topic discusses an improvement to existing compiler code.
Projects
None yet
Development

No branches or pull requests

2 participants