Refactor: Move inlining logic to Inliner struct
Introduces the `Inliner` struct to encapsulate logic related to value and function inlining. This improves code organization and readability within the optimizer engine. Key changes include: - Moving `is_inlinable_value` to the `Inliner` struct. - Extracting beta-reduction preparation logic into `Inliner::prepare_beta_reduction`. - Moving parameter slot collection to `Inliner::collect_parameter_slots`. - Introducing `flatten_tuple` to a new `utils` module, used by both `Folder` and `Inliner`.
This commit is contained in:
@@ -4,6 +4,8 @@ use crate::ast::types::{Purity, StaticType, Value};
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
|
||||
use super::utils::flatten_tuple;
|
||||
|
||||
pub struct Folder<'a> {
|
||||
pub globals: &'a Option<Rc<RefCell<Vec<Value>>>>,
|
||||
}
|
||||
@@ -54,7 +56,7 @@ impl<'a> Folder<'a> {
|
||||
}
|
||||
|
||||
let mut arg_nodes = Vec::new();
|
||||
self.flatten_tuple(args.clone(), &mut arg_nodes);
|
||||
flatten_tuple(args.clone(), &mut arg_nodes);
|
||||
let mut arg_values = Vec::with_capacity(arg_nodes.len());
|
||||
for node in arg_nodes {
|
||||
if let BoundKind::Constant(val) = node.kind {
|
||||
@@ -77,21 +79,5 @@ impl<'a> Folder<'a> {
|
||||
};
|
||||
Some(self.make_constant_node(result, callee))
|
||||
}
|
||||
|
||||
fn flatten_tuple(&self, node: AnalyzedNode, into: &mut Vec<AnalyzedNode>) {
|
||||
match node.kind {
|
||||
BoundKind::Tuple { elements } => {
|
||||
for el in elements {
|
||||
self.flatten_tuple(el, into);
|
||||
}
|
||||
}
|
||||
BoundKind::Record { fields } => {
|
||||
for (_, v) in fields {
|
||||
self.flatten_tuple(v, into);
|
||||
}
|
||||
}
|
||||
BoundKind::Nop => {}
|
||||
_ => into.push(node),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user