Refactor: Improve optimizer and DCE
This commit introduces several improvements to the AST optimizer and dead code elimination (DCE) logic: - **Address Mapping:** The `Get` and `Set` operations now correctly map local slots and global indices using the substitution map, ensuring that remapped variables are handled properly. - **Parameter Slot Mapping:** Parameters are now explicitly mapped to their correct slots within the `Lambda` node, preventing potential slot reassignments in the function body. - **Pure Function Analysis:** The `is_pure` function has been refined to accurately identify pure expressions, including calls to pure functions and stateless closures. - **Dead Code Elimination:** DCE logic in `BoundKind::Block` has been enhanced to remove unused local definitions and pure, non-essential expressions more effectively. Global DCE is also improved. - **Constant Folding:** `try_fold_pure` is now more robust in folding pure function calls with constant arguments, reducing redundant computations. - **Beta Reduction:** `try_beta_reduce` has been updated to avoid reducing if the body contains `DefLocal`, ensuring correctness. - **Global Purity Tracking:** A `global_purity` map is introduced to track the purity of global values, enabling better optimization of global accesses. - **Inlinable Value Check:** The `is_inlinable_value` check now correctly identifies stateless closures for inlining. - **Optimization Level:** The default `optimization_level` is set to 2 to enable more aggressive optimizations.
This commit is contained in:
@@ -91,7 +91,7 @@ impl Environment {
|
||||
function_registry: Rc::new(RefCell::new(HashMap::new())),
|
||||
monomorph_cache: Rc::new(RefCell::new(HashMap::new())),
|
||||
debug_mode: false,
|
||||
optimization_level: 0,
|
||||
optimization_level: 2,
|
||||
};
|
||||
env.register_stdlib();
|
||||
env
|
||||
|
||||
Reference in New Issue
Block a user