p4lang / p4-spec

Apache License 2.0
178 stars 80 forks source link

Are field/index accesses compile-time known? #1323

Open jaehyun1ee opened 2 weeks ago

jaehyun1ee commented 2 weeks ago

Section 18.1 lists compile-time known and local compile-time known values.

The list does not include field access with . and index access with [ ]. But there are use cases in the p4c test suite that expects such.

// struct.p4, struct1.p4
const T t = { 32s10, 32s20 };
const int<32> x = t.t1;
// tuple3.p4
const tuple<bit<32>, bit<32>> t = { 0, 1 };
const bit<32> f = t[0];

How about adding the following cases to the list in 18.1?

For a field access, accessing a field of a local compile-time known / compile-time known expression results in a local-compile time known / compile-time known value, respectively.

For indexing a tuple-type expression, index \ tuple local compile-time known compile-time known
local compile-time known local compile-time known compile-time known
compile-time known compile-time known compile-time known
jafingerhut commented 2 weeks ago

The extra cases of compile-time known and local compile-time known values that you list look correct to me, and seem reasonable to explicitly document in the spec.