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 #1299

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

vlstill
Copy link
Contributor

@vlstill vlstill commented Aug 7, 2024

This gives wording to #1297, the compile-time concatenation of strings. The P4C part of this is p4lang/p4c#4856. The changes are relatively small, I hope I have not missed any more parts that mention that there are no string operations. Note that as stated here, it also allows string concatenation in @name, @deprecated and @noWarn pragmas. The last one has probably no use for it, but I think it is better to be consistent there.

Resolves #1297.

@vlstill vlstill changed the title Add support for string concatenation Allow concatenation of string literals at compile time Aug 7, 2024
@vlstill
Copy link
Contributor Author

vlstill commented Aug 14, 2024

Resulting PDF spec P4-16-spec.pdf.

@vlstill vlstill marked this pull request as ready for review August 14, 2024 16:05
p4-16/spec/P4-16-spec.mdk Outdated Show resolved Hide resolved
@vlstill
Copy link
Contributor Author

vlstill commented Sep 15, 2024

@jafingerhut, @jonathan-dilorenzo, @rcgoodfellow, any comments? I'd love for this one to get in before the next spec revision goes out.

Copy link
Collaborator

@rcgoodfellow rcgoodfellow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly LGTM. Just a few nits.

deprecated construct. This is mostly useful for annotating library
constructs, such as externs.
deprecated construct. This is mostly useful for annotating library
constructs, such as externs. The parameter needs to be local
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: needs to be local -> needs to be a local

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would also go with 'must be' over 'needs to be' imo.

@@ -8602,7 8627,8 @@ extern Checker {
The `noWarn` annotation has a required string argument that indicates
a compiler warning that will be inhibited. For example
`@noWarn("unused")` on a declaration will prevent a compiler warning
if that declaration is not used.
if that declaration is not used. The parameter needs to be local
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: needs to be local -> needs to be a local

The type `string` represents strings. There are no operations on
string values; one cannot declare variables with a `string` type.
Parameters with type `string` can be only directionless (see Section
The type `string` represents strings. The values are either string
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit strange to think of concatenations as being values... Maybe "string-typed expressions are either string literals or concatenations of multiple string-typed expressions."?

@@ -1304,8 1304,8 @@ number of backslash characters (ASCII code 92). P4 does not make any
validity checks on strings (i.e., it does not check that strings
represent legal UTF-8 encodings).

Since P4 does not provide any operations on strings,
string literals are generally passed unchanged through the P4 compiler to
Since P4 does not allow strings to exist at runtime, string literals
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this isn't really true anymore? Now we also concatenate them e.g.? And I'm guessing we plan to turn that into a single string literal before passing it along to backends (though maybe not?).

I think the point of this paragraph is to say that the P4 compiler won't interpret string literals. What does that mean in the new world with concatenation?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably terminating quotes are no longer left as-is?


The only operation allowed on strings is concatenation, denoted by
` `. For string concatenation, both operands must be strings and
the result is also a string. String concatenation can be only
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can only be* performed

body. In the
following example, the fully-qualified name of the table is `c_inst.t1`.
language element from the control plane. This annotation takes a local
compile-time know value of type `string` (typically a string literal).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: know -> known*

deprecated construct. This is mostly useful for annotating library
constructs, such as externs.
deprecated construct. This is mostly useful for annotating library
constructs, such as externs. The parameter needs to be local
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would also go with 'must be' over 'needs to be' imo.

Signed-off-by: Vladimir Still <[email protected]>
@vlstill
Copy link
Contributor Author

vlstill commented Sep 22, 2024

Thanks for the comments and sorry for the delayed response. I think I've fixed all the issues now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow compile-time concatenation of strings
3 participants