@@ -12,14 +12,13 @@ struct ComponentUsage {
1212 invocations : HashMap < String , ast:: Loc < fil_utils:: Id > > ,
1313 let_params : HashMap < String , ast:: Loc < fil_utils:: Id > > ,
1414 sig_params : HashMap < String , ast:: Loc < fil_utils:: Id > > ,
15-
15+
1616 // Usage tracking
1717 invoked_instances : HashSet < String > ,
1818 accessed_invocations : HashSet < String > ,
1919 referenced_params : HashSet < String > ,
2020}
2121
22-
2322/// Check for unused elements in AST (instances, invocations, parameters)
2423pub struct UnusedElementsCheck {
2524 diag : Diagnostics ,
@@ -46,7 +45,10 @@ impl crate::ast_visitor::Construct for UnusedElementsCheck {
4645
4746impl UnusedElementsCheck {
4847 fn current_usage ( & mut self ) -> & mut ComponentUsage {
49- let comp_name = self . current_component . clone ( ) . expect ( "No current component" ) ;
48+ let comp_name = self
49+ . current_component
50+ . clone ( )
51+ . expect ( "No current component" ) ;
5052 self . component_usage . entry ( comp_name) . or_default ( )
5153 }
5254
@@ -63,11 +65,15 @@ impl UnusedElementsCheck {
6365 match expr {
6466 ast:: Expr :: Abstract ( name) => {
6567 let usage = self . current_usage ( ) ;
66- usage. referenced_params . insert ( name. inner ( ) . as_ref ( ) . to_string ( ) ) ;
68+ usage
69+ . referenced_params
70+ . insert ( name. inner ( ) . as_ref ( ) . to_string ( ) ) ;
6771 }
6872 ast:: Expr :: ParamAccess { inst : _, param } => {
6973 let usage = self . current_usage ( ) ;
70- usage. referenced_params . insert ( param. inner ( ) . as_ref ( ) . to_string ( ) ) ;
74+ usage
75+ . referenced_params
76+ . insert ( param. inner ( ) . as_ref ( ) . to_string ( ) ) ;
7177 }
7278 ast:: Expr :: Op { left, right, .. } => {
7379 self . visit_expr_for_params ( left) ;
@@ -88,12 +94,18 @@ impl UnusedElementsCheck {
8894 }
8995 }
9096
91- fn visit_order_constraint_for_params ( & mut self , constraint : & ast:: OrderConstraint < Box < ast:: Expr > > ) {
97+ fn visit_order_constraint_for_params (
98+ & mut self ,
99+ constraint : & ast:: OrderConstraint < Box < ast:: Expr > > ,
100+ ) {
92101 self . visit_expr_for_params ( & constraint. left ) ;
93102 self . visit_expr_for_params ( & constraint. right ) ;
94103 }
95104
96- fn visit_order_constraint_unboxed_for_params ( & mut self , constraint : & ast:: OrderConstraint < ast:: Expr > ) {
105+ fn visit_order_constraint_unboxed_for_params (
106+ & mut self ,
107+ constraint : & ast:: OrderConstraint < ast:: Expr > ,
108+ ) {
97109 self . visit_expr_for_params ( & constraint. left ) ;
98110 self . visit_expr_for_params ( & constraint. right ) ;
99111 }
@@ -106,9 +118,17 @@ impl UnusedElementsCheck {
106118 }
107119 }
108120
109- fn add_unused_warning ( & mut self , element_type : & str , description : & str , loc : GPosIdx ) {
121+ fn add_unused_warning (
122+ & mut self ,
123+ element_type : & str ,
124+ description : & str ,
125+ loc : GPosIdx ,
126+ ) {
110127 let mut warning = Error :: unused_element ( element_type, description)
111- . add_note ( self . diag . add_info ( format ! ( "{} defined here" , element_type) , loc) ) ;
128+ . add_note (
129+ self . diag
130+ . add_info ( format ! ( "{} defined here" , element_type) , loc) ,
131+ ) ;
112132
113133 // Promote to error if flag is set
114134 if self . warnings_as_errors {
@@ -131,28 +151,44 @@ impl UnusedElementsCheck {
131151 // Check unused instances
132152 for ( inst_name, def_loc) in & usage. instances {
133153 if !usage. invoked_instances . contains ( inst_name) {
134- warnings. push ( ( def_loc. pos ( ) , "instance" , "instance is created but never invoked" ) ) ;
154+ warnings. push ( (
155+ def_loc. pos ( ) ,
156+ "instance" ,
157+ "instance is created but never invoked" ,
158+ ) ) ;
135159 }
136160 }
137161
138162 // Check unused invocations (no ports accessed)
139163 for ( inv_name, def_loc) in & usage. invocations {
140164 if !usage. accessed_invocations . contains ( inv_name) {
141- warnings. push ( ( def_loc. pos ( ) , "invocation" , "output ports on invocation never used" ) ) ;
165+ warnings. push ( (
166+ def_loc. pos ( ) ,
167+ "invocation" ,
168+ "output ports on invocation never used" ,
169+ ) ) ;
142170 }
143171 }
144172
145173 // Check unused let parameters
146174 for ( param_name, def_loc) in & usage. let_params {
147175 if !usage. referenced_params . contains ( param_name) {
148- warnings. push ( ( def_loc. pos ( ) , "parameter" , "parameter is defined but never used" ) ) ;
176+ warnings. push ( (
177+ def_loc. pos ( ) ,
178+ "parameter" ,
179+ "parameter is defined but never used" ,
180+ ) ) ;
149181 }
150182 }
151183
152184 // Check unused signature parameters
153185 for ( param_name, def_loc) in & usage. sig_params {
154186 if !usage. referenced_params . contains ( param_name) {
155- warnings. push ( ( def_loc. pos ( ) , "parameter" , "parameter is defined but never used" ) ) ;
187+ warnings. push ( (
188+ def_loc. pos ( ) ,
189+ "parameter" ,
190+ "parameter is defined but never used" ,
191+ ) ) ;
156192 }
157193 }
158194
@@ -190,17 +226,16 @@ impl Visitor for UnusedElementsCheck {
190226 fn signature ( & mut self , sig : & mut ast:: Signature ) -> Action {
191227 let comp_name = sig. name . inner ( ) . as_ref ( ) . to_string ( ) ;
192228 self . current_component = Some ( comp_name. clone ( ) ) ;
193-
229+
194230 // Record signature parameters
195231 let usage = self . current_usage ( ) ;
196232 for param in & sig. params {
197- usage. sig_params . insert (
198- param. name ( ) . as_ref ( ) . to_string ( ) ,
199- param. param . clone ( ) ,
200- ) ;
233+ usage
234+ . sig_params
235+ . insert ( param. name ( ) . as_ref ( ) . to_string ( ) , param. param . clone ( ) ) ;
201236 }
202237
203- // Record let-bound parameters from the 'with' section
238+ // Record let-bound parameters from the 'with' section
204239 // First pass: record parameters
205240 for sig_bind in & sig. sig_bindings {
206241 match sig_bind. inner ( ) {
@@ -227,7 +262,9 @@ impl Visitor for UnusedElementsCheck {
227262 }
228263 ast:: SigBind :: Exists { cons, .. } => {
229264 for constraint in cons {
230- self . visit_order_constraint_unboxed_for_params ( constraint. inner ( ) ) ;
265+ self . visit_order_constraint_unboxed_for_params (
266+ constraint. inner ( ) ,
267+ ) ;
231268 }
232269 }
233270 }
@@ -239,10 +276,9 @@ impl Visitor for UnusedElementsCheck {
239276
240277 fn instance ( & mut self , inst : & mut ast:: Instance ) -> Action {
241278 let usage = self . current_usage ( ) ;
242- usage. instances . insert (
243- inst. name . inner ( ) . as_ref ( ) . to_string ( ) ,
244- inst. name . clone ( ) ,
245- ) ;
279+ usage
280+ . instances
281+ . insert ( inst. name . inner ( ) . as_ref ( ) . to_string ( ) , inst. name . clone ( ) ) ;
246282
247283 // Visit parameter expressions for parameter usage
248284 for param_expr in & inst. params {
@@ -254,17 +290,16 @@ impl Visitor for UnusedElementsCheck {
254290
255291 fn invoke ( & mut self , inv : & mut ast:: Invoke ) -> Action {
256292 let usage = self . current_usage ( ) ;
257-
293+
258294 // Record invocation definition
259- usage. invocations . insert (
260- inv. name . inner ( ) . as_ref ( ) . to_string ( ) ,
261- inv. name . clone ( ) ,
262- ) ;
263-
295+ usage
296+ . invocations
297+ . insert ( inv. name . inner ( ) . as_ref ( ) . to_string ( ) , inv. name . clone ( ) ) ;
298+
264299 // Mark the instance as being invoked
265- usage. invoked_instances . insert (
266- inv . instance . inner ( ) . as_ref ( ) . to_string ( )
267- ) ;
300+ usage
301+ . invoked_instances
302+ . insert ( inv . instance . inner ( ) . as_ref ( ) . to_string ( ) ) ;
268303
269304 // Visit port expressions for parameter usage
270305 for port in & inv. ports {
0 commit comments