| 961 | |
| 962 | #[test] |
| 963 | fn test_analyze_simple() { |
| 964 | // Create a simple expression: App(Var(0), Var(0)) |
| 965 | // Var(0) should have usage_count = 2 |
| 966 | let var0 = Expr::var(0); |
| 967 | let app = Expr::app(var0.clone(), var0); |
| 968 | |
| 969 | let (info_map, ptr_to_hash, _topo_order) = analyze_block(&[app], false); |
| 970 | |
| 971 | // Should have 2 unique subterms: Var(0) and App(Var(0), Var(0)) |
| 972 | assert_eq!(info_map.len(), 2); |
| 973 | |
| 974 | // Find Var(0) info - it should have usage_count = 2 |
| 975 | let var_hash = ptr_to_hash.values().find(|h| { |
| 976 | info_map |
| 977 | .get(*h) |
| 978 | .is_some_and(|info| matches!(info.expr.as_ref(), Expr::Var(0))) |
| 979 | }); |
| 980 | assert!(var_hash.is_some()); |
| 981 | let var_info = info_map.get(var_hash.unwrap()).unwrap(); |
| 982 | assert_eq!(var_info.usage_count, 2); |
| 983 | } |
| 984 | |
| 985 | #[test] |
| 986 | fn test_decide_sharing_simple() { |