-
Notifications
You must be signed in to change notification settings - Fork 451
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
Conversation
@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 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. |
da8b282
to
c1fb8dd
Compare
1e9e145
to
d3a8801
Compare
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. |
Signed-off-by: Vladimir Still <[email protected]>
Signed-off-by: Vladimir Still <[email protected]>
Signed-off-by: Vladimir Still <[email protected]>
fail on missing type in typeMap Signed-off-by: Vladimir Still <[email protected]>
Signed-off-by: Vladimir Still <[email protected]>
Signed-off-by: Vladimir Still <[email protected]>
Signed-off-by: Vladimir Still <[email protected]>
Signed-off-by: Vladimir Still <[email protected]>
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]>
Signed-off-by: Vladimir Still <[email protected]>
Signed-off-by: Vladimir Still <[email protected]>
ade2c5e
to
0b50647
Compare
Signed-off-by: Vladimir Still <[email protected]>
0b50647
to
aaf5718
Compare
testdata/p4_16_errors_outputs/spec-issue1297-string-cat-err-1.p4-stderr
Outdated
Show resolved
Hide resolved
Signed-off-by: Vladimir Still <[email protected]>
Signed-off-by: Vladimir Still <[email protected]>
0f60f70
to
5eb42db
Compare
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 thatBindTypeVariables
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 prohibitedBindTypeVariables
from descending to unstructured annotations.