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

Allow concatenation of string literals at compile time #4856

Merged
merged 15 commits into from
Aug 21, 2024

Conversation

vlstill
Copy link
Contributor

@vlstill vlstill commented Aug 7, 2024

Compiler-side support for p4lang/p4-spec#1297, that is support for compile-time string literal concatenation with ++.

The type checker and constant folding changes are rather straight forward. For the annotations, the constant folding will run automatically in the structured annotations (@foo[...]) but not in the unstructured (@foo(...)) unless they are parsed by the compiler explicitly. I've opted to explicitly allow @name, @deprecated and @noWarn to contain expressions, not just strings, which allows using ++ in them. A further catch was that BindTypeVariables can try to re-save expression's type into a type map, but if the expression is part of unstructured annotation (e.g. @deprecated), it was not type checked and therefore it is not in a type map. So I just prohibited BindTypeVariables from descending to unstructured annotations.

@fruffy fruffy added core Topics concerning the core segments of the compiler (frontend, midend, parser) p4-spec Topics related to the P4 specification (https://github.com/p4lang/p4-spec/). and removed core Topics concerning the core segments of the compiler (frontend, midend, parser) labels Aug 7, 2024
@vlstill
Copy link
Contributor Author

vlstill commented Aug 7, 2024

@jonathan-dilorenzo, I would appreciate if you could try this works for your example too. If you annotations are structured it should work out of the box, if not you should be just able to parse them as expressions and then it should work too (similarly as I did for @name etc.).

Also I wonder if we should merge this alongside the spec change, or we can do this one first. The advantage of merging this first would be that it might allow a bit more testing in the backends that might be interested in using this.

frontends/p4/typeChecking/bindVariables.h Outdated Show resolved Hide resolved
frontends/p4/parseAnnotations.cpp Show resolved Hide resolved
@vlstill vlstill force-pushed the vstill/string-concat branch 3 times, most recently from da8b282 to c1fb8dd Compare August 8, 2024 08:49
frontends/p4/validateStringAnnotations.h Outdated Show resolved Hide resolved
frontends/p4/validateStringAnnotations.h Outdated Show resolved Hide resolved
@vlstill vlstill force-pushed the vstill/string-concat branch 2 times, most recently from 1e9e145 to d3a8801 Compare August 14, 2024 16:08
@vlstill vlstill self-assigned this Aug 14, 2024
@vlstill vlstill marked this pull request as ready for review August 14, 2024 16:08
@vlstill
Copy link
Contributor Author

vlstill commented Aug 14, 2024

Since this was green-lit on the August LDWG (p4lang/p4-spec#1297 (comment)) I think we can merge this to main. If any issues arise when finalizing the spec, I will open another PR to remedy them.

In general I think any feature not in spec (e.g. loops) should be considered experimental and backends should use/acknowledge it only when they feel they can handle possible changes e.g. in syntax that may come before the feature is added to spec.

frontends/common/constantFolding.cpp Outdated Show resolved Hide resolved
vlstill and others added 4 commits August 18, 2024 19:19
Signed-off-by: Vladimir Still <[email protected]>
Co-authored-by: Anton Korobeynikov <[email protected]>
Signed-off-by: Vladimír Štill <[email protected]>
Signed-off-by: Vladimir Still <[email protected]>
@vlstill vlstill force-pushed the vstill/string-concat branch from ade2c5e to 0b50647 Compare August 18, 2024 17:19
Signed-off-by: Vladimir Still <[email protected]>
@vlstill vlstill force-pushed the vstill/string-concat branch from 0b50647 to aaf5718 Compare August 18, 2024 17:31
@vlstill vlstill requested review from ChrisDodd, asl and fruffy August 19, 2024 06:39
@vlstill vlstill force-pushed the vstill/string-concat branch from 0f60f70 to 5eb42db Compare August 20, 2024 14:14
@vlstill vlstill requested a review from fruffy August 20, 2024 15:55
@vlstill vlstill added this pull request to the merge queue Aug 21, 2024
Merged via the queue into main with commit c7a2726 Aug 21, 2024
18 checks passed
@vlstill vlstill deleted the vstill/string-concat branch August 21, 2024 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

5 participants