rust_hdl
rust_hdl copied to clipboard
[Feature] Enhanced Unused Detection
Feature Request: Enhanced Unused Detection
Enhance the existing unused detection in order to find symbols that are
- assigned but never read (dead code)
- read but never assigned or initialized in declaration (X)
Besides, it would be useful to distinguish between different types of "unused" scenarios and set a severity level for each scenario in the toml, since the consequences of these scenarios differ:
- Never read port inputs or generics - Interface compatibility?
- Never referenced or never read locals - Dead code, impacts readability but optimized out in synthesis
- Never assigned port outputs or read but never assigned locals - Most likely bug
Current Behavior
Currently, VHDL-LS detects unused declarations only when they are never referenced at all.
Also, unused (never read) port inputs and generics might be acceptable for interface compatibility. The current workaround is to embrace them with -- vhdl_ls off ... -- vhdl_ls on.
library ieee;
use ieee.std_logic_1164.all;
entity test is
generic(
g_UNUSED : boolean := true -- ❌ Flagged (but maybe acceptable)
);
port(
i_unused : in std_logic; -- ❌ Flagged (but maybe acceptable)
o_unused : out std_logic; -- ❌ NOT flagged (but is never assigned)
o_used : out std_logic -- ✅ Correctly used
);
end entity test;
architecture example of test is
signal never_used : std_logic; -- ✅ Correctly flagged as unused
signal only_read : std_logic; -- ❌ NOT flagged (but is read-only)
signal only_written : std_logic; -- ❌ NOT flagged (but is write-only)
signal properly_used : std_logic; -- ✅ Correctly used
begin
only_written <= '1';
properly_used <= '0';
process (properly_used, only_read) is
begin
o_used <= properly_used and only_read;
end process;
end architecture example;
I completely agree! At least if we have a way to disable unused signal like
port(
i_unused : in std_logic; -- vhdl_ls unused
o_unused : out std_logic; -- vhdl_ls unused
o_used : out std_logic
);
It would be great!