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 test program in which string comparison operators are folded. #4867

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

fruffy
Copy link
Collaborator

@fruffy fruffy commented Aug 13, 2024

Caused by #4837.

Should this be permitted?

@fruffy fruffy added the infrastructure Topics related to code style and build and test infrastructure. label Aug 13, 2024
@vlstill
Copy link
Contributor

vlstill commented Aug 14, 2024

Frankly I don't see much motivation to have this allowed, but if there is some I'd guess it would not harm anything to add this to spec.

@fruffy fruffy force-pushed the fruffy/cstring_program branch from 8ef288e to 40b6945 Compare August 15, 2024 08:12
@vlstill
Copy link
Contributor

vlstill commented Aug 26, 2024

One use case could be on the interface of P4 and CPP -- i.e. this gives the programmer ability to compare (at compile time) a string coming from preprocessor with some pre-defined values and have the result be a valid P4 value. While this can always be done using ifdefs or by changing the macro defines, using this on strings may be a little cleaner.

const bool isFoo = DEVICE == "foo";

instead of

#if DEVICE == "foo"
const bool isFoo = true;
#else
const bool isFoo = false;
#endif

or

#if DEVICE_FOO
const bool isFoo = true;
#else
const bool isFoo = false;
#endif

So this might be useful, although I'm not sure still. On the other hand I would tend towards allowing it (with spec change) as it would make string more like a regular primitive type (there is already match_kind and int that can be compared at compile time, can have variables, and int even has a lot of other operations, so I don't really see why string can't be allowed similar levels of compile-time existence). I'll think about it a bit more and then I guess we will discuss it in P4 LDWG in September.

@fruffy
Copy link
Collaborator Author

fruffy commented Sep 30, 2024

p4lang/p4-spec#1306 is the related specification issue.

@fruffy fruffy added the p4-spec Topics related to the P4 specification (https://github.com/p4lang/p4-spec/). label Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
infrastructure Topics related to code style and build and test infrastructure. p4-spec Topics related to the P4 specification (https://github.com/p4lang/p4-spec/).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants