11//! SSA (Static Single Assignment) analysis utilities.
22
3- use crate :: lang:: { Line , Expression , Boolean , Var } ;
43use super :: visitors:: { Visitor , VisitorResult } ;
4+ use crate :: lang:: { Boolean , Expression , Line , Var } ;
55use std:: collections:: { HashMap , HashSet } ;
66
77/// Tracks variable assignments to detect SSA violations
@@ -131,7 +131,12 @@ impl ReturnContextCollector {
131131 collector. contexts
132132 }
133133
134- fn collect_recursive ( & mut self , lines : & [ Line ] , return_vars : & [ Var ] , current_conditions : Vec < Boolean > ) {
134+ fn collect_recursive (
135+ & mut self ,
136+ lines : & [ Line ] ,
137+ return_vars : & [ Var ] ,
138+ current_conditions : Vec < Boolean > ,
139+ ) {
135140 for line in lines {
136141 match line {
137142 Line :: Assignment { var, value } if return_vars. contains ( var) => {
@@ -141,7 +146,11 @@ impl ReturnContextCollector {
141146 } ;
142147 self . contexts . push ( context) ;
143148 }
144- Line :: IfCondition { condition, then_branch, else_branch } => {
149+ Line :: IfCondition {
150+ condition,
151+ then_branch,
152+ else_branch,
153+ } => {
145154 // Collect from then branch with added condition
146155 let mut then_conditions = current_conditions. clone ( ) ;
147156 then_conditions. push ( condition. clone ( ) ) ;
@@ -234,7 +243,7 @@ pub fn create_ssa_repair_strategy(contexts: &[ReturnContext]) -> Vec<Line> {
234243#[ cfg( test) ]
235244mod tests {
236245 use super :: * ;
237- use crate :: lang:: { SimpleExpr , ConstExpression } ;
246+ use crate :: lang:: { ConstExpression , SimpleExpr } ;
238247
239248 #[ test]
240249 fn test_ssa_analyzer_no_violations ( ) {
@@ -273,12 +282,10 @@ mod tests {
273282
274283 #[ test]
275284 fn test_return_context_collection ( ) {
276- let lines = vec ! [
277- Line :: Assignment {
278- var: "result" . to_string( ) ,
279- value: Expression :: Value ( SimpleExpr :: Constant ( ConstExpression :: scalar( 42 ) ) ) ,
280- } ,
281- ] ;
285+ let lines = vec ! [ Line :: Assignment {
286+ var: "result" . to_string( ) ,
287+ value: Expression :: Value ( SimpleExpr :: Constant ( ConstExpression :: scalar( 42 ) ) ) ,
288+ } ] ;
282289
283290 let return_vars = vec ! [ "result" . to_string( ) ] ;
284291 let contexts = ReturnContextCollector :: collect_from ( & lines, & return_vars) ;
@@ -296,12 +303,10 @@ mod tests {
296303 left: Expression :: Value ( SimpleExpr :: Constant ( ConstExpression :: scalar( 1 ) ) ) ,
297304 right: Expression :: Value ( SimpleExpr :: Constant ( ConstExpression :: scalar( 1 ) ) ) ,
298305 } ,
299- then_branch: vec![
300- Line :: Assignment {
301- var: "result" . to_string( ) ,
302- value: Expression :: Value ( SimpleExpr :: Constant ( ConstExpression :: scalar( 100 ) ) ) ,
303- }
304- ] ,
306+ then_branch: vec![ Line :: Assignment {
307+ var: "result" . to_string( ) ,
308+ value: Expression :: Value ( SimpleExpr :: Constant ( ConstExpression :: scalar( 100 ) ) ) ,
309+ } ] ,
305310 else_branch: vec![ ] ,
306311 } ,
307312 Line :: Assignment {
@@ -313,4 +318,4 @@ mod tests {
313318 let return_vars = vec ! [ "result" . to_string( ) ] ;
314319 assert ! ( detect_return_ssa_violations( & lines, & return_vars) ) ;
315320 }
316- }
321+ }
0 commit comments