-
-
Notifications
You must be signed in to change notification settings - Fork 38
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
New Rule: Forbid unpacked array declarations #280
Conversation
New Rule: Forbid unpacked array declarations
Nice one @ronitnallagatla.
|
Thanks for the feedback :) The motivation behind the rule is to prevent the use of unpacked array signals. So I think for the most part, the rule is relevant for module ports and parameters. I'm not sure about arrays of modules and variables in functions, since the issues I was facing were related to how signals were synthesized. I think for some non-synthesizable types like classes and events, only unpacked arrays are supported -- which might be worth implementing as another rule. Based on IEEE 1800-2017, 7.4.3 Operations on Arrays, packed arrays can be used with more operators than unpacked arrays. Unpacked arrays don't support all arithmetic and bitwise operators and cannot be assigned as a whole. I was facing an issue where my synthesis tool would optimize out some indices of the unpacked memory that it thinks are not being used, which caused mismatches between simulation and synthesis (maybe something weird happens when it tries to flatten multidimensional hierarchies during synth). Another issues I came across: verilator/verilator#2907 (comment) |
Do you think it would be better to have this rule only apply to signal/parameter declarations? Or would it be more appropriate to have separate rules for each of these? |
Fix docs and add more testcases
First, sorry for the delay! A packed array is a collection of things that can be used as 1 thing - a signed or unsigned integer. That's great for use-cases like packets where you construct 1 thing from many components, then operate on the packet as 1 thing, e.g. calculating a checksum or shifting its bits to a transmitter.
I think the best approach is: Just restrictive enough that it helps mitigate your issue, but no more restrictive than that. My instinct would be to have a flag for each thing that you want to restrict, similar to this which is set on entering the node and cleared on leaving the node. Basically, a flag for each of:
Instead of having 10 separate rules (and 10 explanations), you could add 10 Boolean configuration options, so the TOML would look something like: syntaxrules.unpacked_array = true
option.unpacked_array.localparam = false
option.unpacked_array.parameter = true
option.unpacked_array.input = false
option.unpacked_array.output = true Then, check for |
No problem! Thanks for getting back :)
I think using the configuration option to enable/disable which declaration the rule applies to makes for an elegant solution. If the syntax rule is enabled, but the option is not configured, could the rule by default only target data declarations? Or should the documentation specify that the option must be configured as well. Basically, how do we handle the case when the syntax rule is enabled, but none of the options are set. Thanks again for your time and feedback! |
Unpacked array -- modifications
Unpacked array -- updates
I've updated the config to hold the target declaration options, as well as the implementation to check if the corresponding flag and option is set. The rule on default only targets data declarations, and can be enabled/disabled along with all the other declarations through the config file. I've also updated the testcases to only contain a data declaration testcase since it is enabled by default and will work with |
I think this PR can be merged. |
Thanks @dalance. I will open a new PR to add back the contributors after this PR has been merged |
This PR implements a lint rule check that forbids unpacked array declarations.
Relevant Issues: