(module: Module)
| 329 | format!("Optimizing module: {}", module.name) |
| 330 | ); |
| 331 | for (name, func) in old_funcs { |
| 332 | breadcrumbs::log!( |
| 333 | breadcrumbs::LogLevel::Info, |
| 334 | "optimisation", |
| 335 | format!("Optimizing function: {}", name) |
| 336 | ); |
| 337 | // Pass data_types needed for analysis/transformation |
| 338 | let new_func = optimise_function(func, &module.data_types); |
| 339 | new_funcs.insert(name, new_func); |
| 340 | } |
| 341 | |
| 342 | // Rust emits tiny generic helpers such as `needs_drop::<T>` as ordinary |
| 343 | // functions even when their result is a compile-time constant. Fold calls |
| 344 | // to side-effect-free constant-returning functions before the caller's |
| 345 | // final optimisation pass. This lets constant branches and the pointer |
| 346 | // temporaries contained exclusively in their dead arms disappear before |
| 347 | // JVM lowering. |
| 348 | let constant_returns = new_funcs |
| 349 | .iter() |
| 350 | .filter_map(|(key, function)| { |
| 351 | simple_constant_return(function).map(|constant| (key.clone(), constant)) |
| 352 | }) |
| 353 | .collect::<HashMap<_, _>>(); |
| 354 | for function in new_funcs.values_mut() { |
| 355 | if fold_constant_static_calls(function, &constant_returns) { |
| 356 | optimise_function_in_place(function, &module.data_types); |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | breadcrumbs::log!( |
| 361 | breadcrumbs::LogLevel::Info, |
| 362 | "optimisation", |
no test coverage detected