From f9a3ae74c649e179796fdac441cf4d6b3c6c252c Mon Sep 17 00:00:00 2001 From: Jaehyun Lee <99jaehyunlee@gmail.com> Date: Tue, 3 Dec 2024 11:14:31 +0900 Subject: [PATCH 1/2] Revise general explanation on type casting Signed-off-by: Jaehyun Lee <99jaehyunlee@gmail.com> --- p4-16/spec/P4-16-spec.adoc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/p4-16/spec/P4-16-spec.adoc b/p4-16/spec/P4-16-spec.adoc index 37940fb202..5c39db630f 100644 --- a/p4-16/spec/P4-16-spec.adoc +++ b/p4-16/spec/P4-16-spec.adoc @@ -3842,9 +3842,10 @@ Additionally, the maximum size of a variable-length bit-string can be determined === Casts P4 provides a limited set of casts between types. A cast is written -`(t) e`, where `t` is a type and `e` is an expression. Casts are only -permitted on base types and derived types introduced by `typedef`, `type`, and `enum`. -While this design is arguably more onerous for programmers, it has several benefits: +`(t) e`, where `t` is a type and `e` is an expression. Casts are only permitted in +cases as defined in section <> for explicit casts and +section <> for implicit casts. While this design is arguably +more onerous for programmers, it has several benefits: * It makes user intent unambiguous. * It makes the costs associated with converting numeric values @@ -3853,6 +3854,7 @@ While this design is arguably more onerous for programmers, it has several benef * It reduces the number of cases that have to be considered in the P4 specification. Some targets may not support all casts. +[#sec-explicit-casts] ==== Explicit casts The following casts are legal in P4: From 23d59b632da96a6f7d2a3698af4f78a8a5f13d5f Mon Sep 17 00:00:00 2001 From: Jaehyun Lee <99jaehyunlee@gmail.com> Date: Tue, 21 Jan 2025 17:14:11 +0900 Subject: [PATCH 2/2] Nit pass on cast explainer Signed-off-by: Jaehyun Lee <99jaehyunlee@gmail.com> --- p4-16/spec/P4-16-spec.adoc | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/p4-16/spec/P4-16-spec.adoc b/p4-16/spec/P4-16-spec.adoc index 5c39db630f..c583233aa5 100644 --- a/p4-16/spec/P4-16-spec.adoc +++ b/p4-16/spec/P4-16-spec.adoc @@ -3841,18 +3841,21 @@ Additionally, the maximum size of a variable-length bit-string can be determined [#sec-casts] === Casts -P4 provides a limited set of casts between types. A cast is written -`(t) e`, where `t` is a type and `e` is an expression. Casts are only permitted in -cases as defined in section <> for explicit casts and -section <> for implicit casts. While this design is arguably -more onerous for programmers, it has several benefits: +P4 provides a set of casts between types. A cast is written +`(t) e`, where `t` is a type and `e` is an expression. Casts in P4 are +permitted only under the conditions specified in section <> +for explicit casts and section <> for implicit casts. +By allowing casts only in limited scenarios, this restriction is more +onerous for programmers, but it also provides several benefits. * It makes user intent unambiguous. * It makes the costs associated with converting numeric values explicit. Implementing certain casts involves sign extensions, and thus can require significant computational resources on some targets. * It reduces the number of cases that have to be considered in the P4 - specification. Some targets may not support all casts. + specification. + +Some targets may not support all casts. [#sec-explicit-casts] ==== Explicit casts