Size() vs $size for constraining Unpacked Arrays

Hi All,

While trying to constraint an unpacked array random property of different type ( fixed / dynamic / queue ) I observe that 2 out of 3 tools don’t allow method size() for fixed type array (edalink)

[Q1] Is size() method legal for fixed unpacked arrays ?

[Q2] Inorder to constraint size of queue / dynamic array, is system function $size legal ?

As per LRM 7.5.2 ::

The size dynamic array method is equivalent to the $size(addr,1) array query system function

For dynamic arrays / queue, is it legal to constraint the size using $size instead of size method ?

Thanks in Advance

.size() method is not legal for fixed unpacked arrays. Fixed arrays have compile-time constant size, but this appears to be a tool-specific extension and not strictly defined by the LRM.

And even though LRM states that dynamic array .size() is equivalent to $size(array,1), in practice $size() is not reliably supported inside constraints as far as I have tried on many tools. I mean constraint solvers treat .size() as a property of the random array and can solve symbolically for the array length. $size() is considered a runtime query function which expects the array to already exist, so many tools do not allow it inside constraints. using $size() only the array elements can be randomized, not the array size.

For dynamic arrays and queues, it is recommended to use .size() for constraining the array length. $size() can still be used for dynamic types outside constraints (for example display/debug), including for fixed arrays.

Hi @Thobiyas , I am not clear on the first 2 lines of your comment.

As per my understanding .size() would be considered illegal for fixed unpacked arrays only if the LRM explicitly mentions it.

In my brief search I couldn’t find any such line ( I may have possibly missed if any such quote does exist in LRM )

Absence of such a quote would probably mean that each tool has it’s own implementation ( which could be the reason behind what we currently observe in above edalink )

Similarly although LRM mentions using size to constraint the size of dynamic array / queue ( Section 18.4 of LRM-2023 ), it doesn’t explicitly mention $size as illegal to constraint size of dynamic array / queue

Yeah. Refer IEEE Std 1800-2017 on section 20.7 “It is an error to use these functions directly on a dynamically sized type identifier”.

LRM-2013 Section 7.5.1 has an example

integer addr[];

addr = new[100];

Section 7.5.2 further mentions

The size dynamic array method is equivalent to $size( addr,1) array query function (see 20.7)

Where addr is a dynamic type identifier

Hence I believe $size is legal for dynamic arrays

Section 20.7 mentions

When used on a dynamic array or queue dimension, these functions return information about the current state of the array.

So this does confirm that $size is valid for queues and dynamic arrays.

It further mentions

It is an error to use these functions directly on a dynamically sized type identifier

The keyword here is directly ( However I am not clear on what it means here )

Furthermore LRM mentions that $size is legal for associative array dimensions with index type as integer