Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
language:types2 [2026/08/05 15:23] – [Non-strict template parameters] rajitlanguage:types2 [2026/08/09 13:10] (current) – [Non-strict template parameters] rajit
Line 153: Line 153:
 the type. Hence, when checking for type compatibility, the values of the type. Hence, when checking for type compatibility, the values of
 parameters are also taken into account. Hence, the full type for parameters are also taken into account. Hence, the full type for
-instance ''a2'' above is in fact ''adder<5>'', not just+instance ''a2'' above is in fact ''adder<16>'', not just
 ''adder''. Types such as ''fulladder'' that do not have ''adder''. Types such as ''fulladder'' that do not have
 parameters are more completely specified as ''fulladder<>'', parameters are more completely specified as ''fulladder<>'',
Line 463: Line 463:
 ... ...
 </code> </code>
-This will also result in the same circuit as the earlier example, because the value ''17'' is a parameter and so after expansion, the CHP to be synthesized will once again has the constant value ''17'' as a fixed input to the adder.+This will also result in the same circuit as the earlier example, because the value ''17'' is a parameter and soafter expansion, the CHP to be synthesized will have the constant value ''17'' as a fixed input to the adder.
  
 What if we wanted to create an array of these adders? While  What if we wanted to create an array of these adders? While 
Line 481: Line 481:
                    New type: addbuf<8,18>                    New type: addbuf<8,18>
 </code> </code>
-This is because elements of an array must have the same type. As this is a useful use-case, ACT has special syntax that can be used to support it+This is because elements of an array must have the same type. As this is a useful use-case, ACT has support for a special type of template parameter introduced for this scenario.
  
 Template parameters for processes can be of two types: Template parameters for processes can be of two types:
-   * //strict// parameters, are the ones we have been considering so far.+   * //strict// parameters, which are the ones we have been considering so far. Elements of an array must have the same strict template parameters.
    * //non-strict// parameters, which can be varied within an array.    * //non-strict// parameters, which can be varied within an array.
-Any ports for the type can only use strict parameters.  In other words, the type signature can only depend on strict parameters. This is what permits diferrent process types to be treated as a single array. 
  
-Non-strict parameters are separate from strict parameters by a vertical bar. The example above would be written as follows:+ 
 +Non-strict parameters are separated from strict parameters by a vertical bar. The example above would be written as follows:
 <code act> <code act>
 template<pint W | pint VAL> template<pint W | pint VAL>
Line 505: Line 505:
 </code> </code>
 ACT will allow this syntax. This comes with a few caveats: ACT will allow this syntax. This comes with a few caveats:
-   The array will be treated as a sparse array with multiple chunkseach of which can have different non-strict parameters.+    Any ports for the type can only use strict parameters.  In other words, the type signature can only depend on strict parameters. This is what permits different process types to be mixed within a single array, since the external interface to the array elements remains unchanged. So<code act> 
 +template<pint W | pint VAL> 
 +defproc oddbuf(chan?(int<W>) L; chan!(int<W+VAL>) R) 
 +
 +...  
 +}  
 +</code>will lead to the following error<code> 
 +-[ERROR]-> Expressions in port parameter list can only use strict template parameters 
 +</code> 
 +   * Even if the array is dense, it will be treated as a sparse array with multiple chunks where each chunk can have different non-strict parameters.
    * Sub-array expressions cannot be used where different elements have different types.    * Sub-array expressions cannot be used where different elements have different types.
 +
 +Since the general ACT syntax can be used, the following would also be valid:
 +<code act>
 +...
 +(i:8: addbuf<8,17+i> mybuf[i..i];)
 +...
 +</code>
 +